GNU Compiler Debug 'Level'

While looking at the various option switches for my compiler (GNU C ++ 3.2.3 is maintained by my organization for a given hardware configuration), I came across this:

-glevel
   :
Level 3 includes extra information, such as all the macro definitions
present in the program. Some debuggers support macro expansion when
you use -g3.

      

I compiled a test program with several macros (like a loop, if-then-else in argument), then tried the commercial debugger TotalView and GDB on the compiled -g3 code. I didn’t see any difference (macros were not extended to their original code, I couldn’t "step" into macros, etc.).

Has anyone had any experience with additional "debugging" functionality using -g3 in GNU compilers?

0


source to share


2 answers


Your question assumes you don't understand what macros are. Of course, you cannot go into a macro.

"-g3 is quite useful for macro-heavy programs. Consider:

int main()
{
  int i;
  for (i = 0; i < 20; ++i) {
#define A(x) case x: printf(#x "\n"); break
    switch(i) {
      A(1); A(2); A(3); A(4); /* line 7 */
#undef A
#define A(x) case 10+x: printf("10+" #x "\n"); break
      A(1); A(2); /* line 10 */
    }
  }
  return 0;
}

      



Without -g3, when you stopped at line 7 or 10, you might have to search quite a bit for the definition of A (), and there might be many such definitions, so you would need to figure out which one is the "current" one.

With -g3, GDB can do the heavy lifting for you:

(gdb) b 7
Breakpoint 1 at 0x4004cc: file m.c, line 7.
(gdb) b 10
Breakpoint 2 at 0x4004fc: file m.c, line 10.
(gdb) r

Breakpoint 1, main () at m.c:7
7         A(1); A(2); A(3); A(4);
(gdb) info macro A
Defined at /tmp/m.c:5
#define A(x) case x: printf(#x "\n"); break
(gdb) c
1
2
3
4

Breakpoint 2, main () at m.c:10
10        A(1); A(2);
(gdb) info macro A
Defined at /tmp/m.c:9
#define A(x) case 10+x: printf("10+" #x "\n"); break
(gdb) q

      

+3


source


I've got it checked -g3

off and on since 1992
and never got anything useful from me .



+2


source







All Articles