我有这个 C 文件(sample.c):
#include <stdio.h>
#define M 42
#define ADD(x) (M + x)
int main ()
{
printf("%d\n", M);
printf("%d\n", ADD(2));
return 0;
}
我编译的是:
$ gcc -O0 -Wall -g3 sample.c -o sample
然后调试
$ gdb ./sample
GNU gdb (Gentoo 7.3.1 p2) 7.3.1
Copyright (C) 2011 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-pc-linux-gnu".
For bug reporting instructions, please see:
<http://bugs.gentoo.org/>...
Reading symbols from /tmp/sample...done.
(gdb) macro list
(gdb) macro expand ADD(2)
expands to: ADD(2)
(gdb) print M
No symbol "M" in current context.
(gdb) q
这曾经奏效。我需要它来工作,因为我正在使用为硬件外围设备和内存地址提供#define 名称的库。
这似乎与Sourceware gdb 站点上显示的行为直接矛盾。
我究竟做错了什么?