52
votes

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)

1
In general, this is why you shouldn't use #define for defining numeric constants. For integer constants, use enum instead. - jamesdlin
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
You may also need to build with -g3. -g3 includes items like symbolic constants. - jww

1 Answers

50
votes
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