Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

call setbuf(stdout, NULL): no symbol "NULL" in the current context

Tags:

c

null

gdb

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.

like image 938
CDT Avatar asked Nov 16 '12 14:11

CDT


3 Answers

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.

like image 140
alk Avatar answered Dec 04 '22 03:12

alk


Just use 0 or (void*)0. Nothing fancy.

like image 37
Jester Avatar answered Dec 04 '22 04:12

Jester


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.

See also: How do I print a #defined constant in GDB?