61

As per subject.

I have some constants hash defined like so:

#define CONST 40

I've set a breakpoint in my program. How do I print the value of that constant? (I know I can just look at the source code, but I want to be sure of it)

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Charles Ma
  • 47,141
  • 22
  • 87
  • 101
  • 1
    In general, this is why you shouldn't use `#define` for defining numeric constants. For integer constants, use `enum` instead. – jamesdlin May 29 '10 at 18:10
  • Oh, I was using it for error codes, and since they're from different files, I didn't want to have to dig through every one of them to find what they are – Charles Ma May 30 '10 at 05:01
  • 1
    You may also need to build with `-g3`. `-g3` includes items like symbolic constants. – jww May 12 '16 at 06:09

1 Answers1

56
help macro

You must compile with the -g3 flag for it to work and start your program before the macros are loaded.

In your case:

info macro CONST

or

macro expand CONST

More info: http://sourceware.org/gdb/current/onlinedocs/gdb/Macros.html