What should I do if I want to use identifier NULL
in gdb
's call statement?
Is it because I didn't include stdio.h in gdb?
I have tried : call #include <stdio.h>
but this doesn't seem to work.
NULL
is a C define, defined somewhere as:
#define NULL ((void *) 0)
NULL
is replaced by the C pre-processor to be ((void *) 0)
. So it's never passed to the compiler, so you can not use it in gdb
.
So do as Jester suggested, and just use (void *) 0
.
Current GCC and GDB can see defines, but you must compile with -ggdb3
, -g
is not enough.
Input program:
#include <stdio.h>
#define ABC 123
int main() {
return 0;
}
GDB:
# start is required.
start
print ABC
print NULL
Output:
$1 = 123
$2 = (void *) 0x0
Tested with GCC 4.8 and GDB 7.7.1 on Ubuntu 14.04.
Above is good, also 0x0 should work for comparing pointers,
0x0 is the memory address that NULL points to. Here is an example I used while running gdb (on MS-DOS terminal) to print out memory addresses and see which were pointing to NULL for debugging a segmentation fault: