Part I
Tracing is a very useful enhancement of Insure++ for C++
programmers. Because C++ is such a complicated language, programmers
may never know which functions are being called or in which order.
Some functions are called during initialization before the main program
begins execution. Tracing provides the programmer with the ability
to see how functions, constructors, destructors, and more are called as
the program runs.
Insure++ prints a message at the entry to every function which
includes the function name, filename, and line number of the command that
called it.
A typical line of output from tracing looks like:
function_name filename, line_number
By default, the output is indented to show the proper depth of the
trace.
By default, tracing is turned off. The easiest way to turn tracing on
is to use the
trace on option in your
.psrc file. This turns on tracing for the entire
program.
To get a full trace, you must use the -g complier
switch on your insure compile line. To get file
names and line numbers in the trace output, you must
use the
stack_internal on
option when compiling your program.
You may not want to do this always, though, because your program will
slow down while every function call prints information.
This problem can be minimized by selectively turning on tracing during
the execution of your program only in those sections of the code where
you need it most. This can be done using the special Insure++
command
void _Insure_trace_enable(int flag)
flag = 0 turns tracing off
flag = 1 turns tracing on
There is one more special Insure++ function that works with
tracing. This function may be used to add your own messages to the
trace.
void _Insure_trace_annotate
(int indent,char *format, ...)
indent = 0 means string is placed in
column zero
indent = 1 means string will be indented
at proper level
format should be a normal
printf -style format string
The default output for tracing data, like all other Insure++
output, is stderr . You can direct the output to a
file using the
trace_file filename
option in your .psrc file.
When you use this option, Insure++ prints a message reminding
you where the tracing data is being written. If you would like to eliminate
these reminders, you can use the
trace_banner off option
in your .psrc file. See
trace_banner
for more information.
Consider the following code, which will illustrate how tracing works.
1: /*
2: * File: trace.C
3: */
4: int twice(int j) {
5: return j*2;
6: }
7: class Object {
8: public:
9: int i;
10: Object() {
11: i = 0;
12: }
13: Object(int j) {
14: i = j;
15: }
16: operator int() { return twice(i); }
17: };
18: int main() {
19: Object o;
20: int i;
21:
22: i = o;
23: return i;
24: }
If you compile and link trace.C with the
-g option and the
stack_internal on
option, and then run
the executable with the trace on
option in your .psrc file, you will see the following
output in stderr .
main
Object::Object trace.C, 19
Object::operator int trace.C, 22
twice trace.C, 16
For more information, call (888) 305-0041 or send email to:
insure@parasoft.com
Interacting with Debuggers
Signals
Insure++ User's Guide TOC
|