Jump to content United States-English
HP.com Home Products and Services Support and Drivers Solutions How to Buy
» Contact HP
More options
HP.com home
HP Itanium-based Systems: HP aC++/HP C Programmer's Guide > Chapter 2 Command-Line Options

Runtime Checking Options

» 

Technical documentation

Complete book in PDF
» Feedback
Content starts here

 » Table of Contents

 » Glossary

 » Index

The +check options allow you to check your application for errors at runtime.

+check

+check=all|none|bounds|malloc|stack|uninit

The +check=xxx options provide runtime checks to detect many common coding errors in the user program. These options introduce additional instructions for runtime checks that can significantly slow down the user program. A failed check will result in the program aborting at runtime. In most cases, an error message and a stack trace will be emitted to stderr before program termination. The environment variable RTC_NO_ABORT can be set to 1 to allow the program to continue after a failed runtime check. This allows the user to get the diagnostics for all the failed checks in a single execution run.

The +check options need to be specified at both compile time and link time, since they may require additional libraries to be linked into the user program. If different +check options are specified while compiling different source files, all the specified +check options are needed at link time.

Multiple +check options are interpreted left to right. In case of conflicting options, the one on the right will override an earlier +check option.

NOTE: The +check option is only supported on Integrity servers.

+check=all

The +check=all option enables all runtime checks provided by the compiler. It overrides any +check=xxx options that appear earlier on the command line. The +check=all option is currently equivalent to the following options:

+check=bounds +check=malloc +check=stack:variables 
+check=uninit -z +Olit=all

The -z or +Olit=all options, which are part of +check=all, can be overridden by an explicit -Z or +Olit=none option.

+check=none

The +check=none option turns off all runtime checking options. It disables any +check=xxx options that appear earlier on the command line.

+check=bounds

The +check=bounds option enables checks for out-of-bounds references to array variables. The check is performed for each reference to an array element. If a check fails, an error message is emitted and the program is aborted.

The +check=bounds option applies only to local and global array variables. It also applies to references to array fields of structs. It does not apply to arrays allocated dynamically using malloc or alloca. It also does not cover pointer dereferences.

Also see the +check=malloc and the +check=stack options for related runtime checks for heap and stack objects.

+check=malloc

The +check=malloc option enables memory leak and heap corruption checks at runtime. It will cause the user program to abort for writes beyond boundaries of heap objects, free()or realloc() calls for a pointer that is not a valid heap object, and out-of-memory conditions. Memory leak information is captured and written out to a log file when the program exits. The name of the logfile is printed out before program termination.

The +check=malloc option works by intercepting all heap allocation and deallocation calls. This is done by the use of a debug malloc() library, librtc.so. The option works for programs that use the system malloc() or for user provided malloc() routines in a shared library. The librtc.so library is also used by the HP WDB debugger to provide heap memory checking features in the debugger. Please refer to the HP WDB debugger documentation for more information about heap memory checking. The librtc.so library is shipped as part of the wdb product. Please install the HP WDB bundled with the compiler or a more recent version of wdb to get full functionality.

The default behavior of the +check=malloc option can be changed by users providing their own rtcconfig file. The user specified rtcconfig file can be in the current directory or in a directory specified by the GDBRTC_CONFIG environment variable. The default configuration used by the +check=malloc option is:

check_bounds=1; check_free=1; scramble_block=1;
abort_on_bounds=1; abort_on_bad_free=1; abort_on_nomem=1;
check_leaks=1; min_leak_size=0; check_heap=0;
frame_count=4; output_dir=.;

For a description for the above configuration parameters and the full list of other parameters, please refer to the HP WDB debugger documentation.

+check=stack[:frame|:variables|:none]

The +check=stack[:frame|:variables|:none] option enables runtime checks to detect writes outside stack boundaries. Markers are placed before and after the whole stack frame and around some stack variables. On procedure exit, a check is done to see if any marker has been overwritten. If any stack check fails, an error message and stack trace is written to stderr and the program is aborted. The stack checks are not performed for an abnormal exit from the procedure (for example, using longjmp(), exit(), abort(), or exception handling).

+check=stack:frame

This option enables runtime checks for illegal writes from the current stack frame that overflow into the previous stack frame.

+check=stack:variables

This option enables runtime checks for illegal writes to the stack just before or after some variables on the stack. This includes array, struct/class/union, and variables whose address is taken. It also includes the overflow check for the stack frame (+check=stack:frame). In addition to the above checks, this option causes the whole stack to be initialized to a "poison" value, which can help detect the use of uninitialized variables on the stack.

+check=stack:none

This option disables all runtime checks for the stack.

+check=stack

The +check=stack option without any qualifiers is equivalent to +check=stack:variables at optimization levels 0 and 1. It is equivalent to +check=stack:frame for optimization level 2 and above.

+check=uninit

The +check=uninit option checks for a use of a stack variable before it is defined. If such a use is detected, an error message is emitted and the program is aborted. The check is done by adding an internal flag variable to track the definition and use of user variables.

Also see the +Oinitcheck option to enable compile-time warnings for variables that may be used before they are set.

Printable version
Privacy statement Using this site means you accept its terms Feedback to webmaster
© Hewlett-Packard Development Company, L.P.