4

I have a macro that fetch's the J-th bit of an integer:

#define TWO_TO_THE(POWER) (1 << POWER)

#define JTH_BIT(BITS, J)  ((TWO_TO_THE((J-1)) & BITS) != 0)

However, I can't use it from gdb by issuing the command print JTH_BIT(i,j), can macros in C even be used while debugging?

1
  • 1
    This should be reopened, as this is quetion is about clang and the assumed duplicate is about gcc. Commented Feb 10, 2014 at 7:12

2 Answers 2

7

Macros are handled by the pre-processor. The compiler doesn't even know about them.

However, if lucky, GCC's option -g3 would do the job and generate code allowing gdb to expand a macro.

From the gdb documentation (emphasis by me):

-glevel

[...] Level 3 includes extra information, such as all the macro definitions present in the program. Some debuggers support macro expansion when you use -g3.

Sign up to request clarification or add additional context in comments.

6 Comments

But this question is about the debugger, not the compiler. The debugger has access to both the binary and the source (typically), so anything is possible.
I changed my makefile to compile with -g3, but when I try to print the result of the macro, I get "GDB has no preprocessor macro information for that code", do I need to load the header files in gdb?
@TobiLehman: What does info macro JTH_BIT tell you? And: Did you do a make clean?
@alk I did a make clean and then a make, and the -g3 arg used when compiling. Then when in the debugger at a line where the macro is in scope, info macro JTH_BIT returns GDB has no preprocessor macro information for that code.
@TobiLehman: Which gcc are you using though, on which platform? You should perhaps test this with a simple (2 liner) example, if the version of gcc you use does support macro expansion if having used -g3.
|
3

It should work, if you compile your program with the right options. In gcc, you need to say "-g3" when you compile

See here and here.

1 Comment

I doubt that's helpful when the op is apparently using clang.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.