【发布时间】:2012-05-08 09:42:46
【问题描述】:
我有这个 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 site 上显示的行为直接矛盾。
我做错了什么?
【问题讨论】:
-
你的 GCC 版本是多少?在 Ubuntu 14.04 上的 GCC 4.8 GDB 7.7.1 上为我工作。相关:stackoverflow.com/questions/2934006/…