I have this C file (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; }
which I compile with:
$ gcc -O0 -Wall -g3 sample.c -o sample
then debug using
$ 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
It worked. I need this to work because I use libraries that have #define names for hardware peripherals and memory addresses.
This seems like a direct contradiction to the behavior shown on the gdb source site .
What am I doing wrong?
source share