Search code examples
cgccmacrosgdb

Print function macro definition in gdb


Here is the source file fragment:

#define TEST 34
#define PRINT_CONCAT(a, b) \
    printf("%d\n", a##b)

Compiling with GCC and linking this source file into a binary with flags -ggdb3 -O3 and running the app with gdb shows up the following behavior:

(gdb) p TEST                                                                                                                                                                                                       
$3 = 34                                                                                                                                                                                                            
(gdb) p PRINT_CONCAT                                                                                                                                                                                               
No symbol "PRINT_CONCAT" in current context. 

Is there a way to make gdb expand function macros in any way?


Solution

  • It turned to be as easy as macro expand

    (gdb) macro expand PRINT_CONCAT(2, 4)                                                                                                                                                                              
    expands to: printf("%d\n", 24) 
    

    -ggdb3 is not even required, -g3 is enough. -g2 does not seem to include the desired information.