0

在浏览我的编译器的各种选项开关(我的组织支持我的给定硬件配置的 GNU C++ 3.2.3)时,我遇到了这个问题:

-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.

我用几个宏编译了一个测试程序(比如一个循环,一个参数上的 if-then-else),然后在编译的代码上尝试了商业调试器 TotalView 和 GDB -g3。我没有看到任何区别(宏没有扩展到它们的原始代码,我无法“进入”宏等)。

这里的任何人都有在 GNU 编译器上使用 -g3 获得额外调试“功能”的经验吗?

4

2 回答 2

3

您的问题似乎暗示您不了解宏是什么。当然你不能进入宏。

-g3 对于“宏重”程序非常有用。考虑:

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;
}

如果没有 -g3,当您在第 7 行或第 10 行停止时,您可能需要大量搜索 A() 的定义,并且可能有很多这样的定义,因此您必须找出哪个是“当前”。

使用 -g3,GDB 可以为您完成繁重的工作:

(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
于 2009-01-06T08:57:18.140 回答
2

自 1992 年以来,我不断尝试,但-g3从未让它做任何有用的事情

于 2008-12-31T22:57:31.483 回答