Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GDB, how to debug macro

Tags:

c

gdb

I am debugging a huge c source code, and it has many macro definition. currently there is a segmentation fault is occurring at a macro. I want to be able to debug macro, step in macro definition just like as a function. I tried that

    ./configure debugflags="-gdwarf-2 -g3"
    make

but this is not working, make is failing. without above option it compile correctly, but could not debug macro.

so, how can I debug macro? thanks in advance

like image 413
arslan Avatar asked Jan 11 '23 13:01

arslan


1 Answers

You could convert the macro into a static inline function, e.g. from

#define max(a, b) (a) > (b) ? (a) : (b)

to

static inline max(int a, int b)
{
    return a > b ? a : b;
}

This lets the compiler create debugging information for the macro (now function).

like image 169
Olaf Dietsche Avatar answered Jan 27 '23 07:01

Olaf Dietsche