8

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.

alk
  • 68,300
  • 10
  • 92
  • 234
CDT
  • 9,237
  • 16
  • 60
  • 93

4 Answers4

6

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.

alk
  • 68,300
  • 10
  • 92
  • 234
5

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

Jester
  • 54,538
  • 4
  • 72
  • 115
3

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?

Community
  • 1
  • 1
0

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: console gdb printout of NULL pointer comparison

  • 1
    As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Dec 08 '21 at 07:09