Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Print function macro definition in gdb

Tags:

c

gcc

macros

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?

like image 472
Some Name Avatar asked Oct 14 '25 18:10

Some Name


1 Answers

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.

like image 141
Some Name Avatar answered Oct 17 '25 08:10

Some Name



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!