當宏符號甚至不呈現我有這個C文件(sample.c文件):GDB使用-g3或-ggdb3或-gdwarf -4-
#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。相關:http://stackoverflow.com/questions/2934006/how-do-i-print-a-defined-constant-in-gdb –