[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

7. Tracing tools

A few tools for execution tracing and logging are available in the `gdb' directory and are installed by default. They are simple shell scripts and may be of some use in testing/development. Note that `gdb-4.17' may be required on some machines for this stuff to work properly.

7.1 Statement level tracing  
7.2 Library tracing  


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

7.1 Statement level tracing

The `nana-trace' executes a program and generates a message for each line of code executed (a statement trace). The statement level trace is useful for things such as:

For example the `make ex-trace' command in `gdb' generates:

 
% make ex-trace
gcc -g test.c
sh ./nana-trace a.out
47           setbuf(stdout, NULL); /* disable buffering */
49           printf("** main()\n");
** main()
50           printf("** 1: %d\n", distance(1,-5));
distance (i=1, j=-5) at test.c:43
43           return abs(i - j);
abs (i=6) at test.c:35
35           if(i >= 0) {
36                return i;
40      }
distance (i=1, j=-5) at test.c:44
44      }
** 1: 6
main () at test.c:51
51           printf("** 2: %d\n", distance(twice(1),-5));
twice (i=1) at test.c:29
29           i = i * 2;
31           return i ;
32      }
distance (i=2, j=-5) at test.c:43
43           return abs(i - j);
abs (i=7) at test.c:35
35           if(i >= 0) {
36                return i;
40      }
distance (i=2, j=-5) at test.c:44
44      }
** 2: 7
main () at test.c:52
52           printf("** 3: %d\n", distance(3,-5));
distance (i=3, j=-5) at test.c:43
43           return abs(i - j);
abs (i=8) at test.c:35
35           if(i >= 0) {
36                return i;
40      }
distance (i=3, j=-5) at test.c:44
44      }
** 3: 8
main () at test.c:53
53      }


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

7.2 Library tracing

On most UNIX machines there exists a tool for tracing the system calls executed by a program. If you haven't used one of these tools (e.g. ktrace) then now is a good time to learn. Being able to trace the User/Kernel interface is an excellent way to understand complex applications.

The `nana-libtrace' facility generalises this idea to provide a GDB based function call tracer for all functions in which are defined in a particular library. For example the `make ex-libtrace' command in the `gdb' directory produces a trace of all calls to `libc'.


[ << ] [ >> ]           [Top] [Contents] [Index] [ ? ]

This document was generated by Marius Tomaschewski on February, 12 2004 using texi2html