I get different results with GCC 4.4.7 and GDB 7.2 than what you report. Having used your source and your compilation command, my GDB session looks like this:
> gdb sample
[ ... startup banner ... ]
(gdb) break main
Breakpoint 1 at 0x4004d3: file sample.c, line 7.
(gdb) run
Starting program: /home/jbolling/tmp/sample
Breakpoint 1, main (argc=1, argv=0x7fffffffcba8) at sample.c:7
7 printf("M: %d\n", M);
Missing separate debuginfos, use: debuginfo-install glibc-2.12-1.166.el6_7.7.x86_64
(gdb) info macro M
Defined at /home/jbolling/tmp/sample.c:3
#define M 42
(gdb) continue
Continuing.
M: 42
Program exited normally.
(gdb)
I suspect that the key difference here, and the reason that you aren't seeing a definition of M
, is in GDB's sense of the source location associated with a breakpoint at function main
. The GDB output you reported provides a clue about this:
gdb> info macro M
The symbol `M' has no definition as a C/C++ preprocessor macro
at <user-defined>:-1
Note in particular the location GDB reports: "<user-defined>" file, line number -1. In my GDB run, the breakpoint was associated with the first source line in the body of main()
. I am inclined to believe that if you break there then GDB will report correctly on the macro's definition at that location.