What's wrong with gdb and stdout?

Check out this simple gdb session.

I can call printf after a break, but I just cannot name anything containing stdout. What am I doing wrong?

(gdb) call printf("Hi :)\n")
Hi :)
$1 = 6
(gdb) call fprintf(stdout, "Bug!\n")

Program received signal SIGSEGV, Segmentation fault.
0x00007ffff7491d1d in vfprintf () from /lib/x86_64-linux-gnu/libc.so.6
The program being debugged was signaled while in a function called from GDB.
GDB remains in the frame where the signal was received.
To change this behavior use "set unwindonsignal on".
Evaluation of the expression containing the function
(fprintf) will be abandoned.
When the function is done executing, GDB will silently stop.
(gdb)

      

My breakpoint is on the third line of this very tiny program:

int main() {
    int x[20] = {};
    x[0] = 3;
}

      

Which was compiled using these flags:

CFLAGS =-g -Wall -O0 -std=c11
LDLIBS=

      

I am using gdb:

GNU gdb (Ubuntu 7.7-0ubuntu3) 7.7
This GDB was configured as "x86_64-linux-gnu"

      

Thank you in advance

+3


source to share


1 answer


The problem here is that you don't have debuginfo installed for libc, and no other debuginfo stdout

was created for.

However, stdout

it still displays as an ELF character. gdb, in a solution that probably made sense in the early 90s, suggests that the type of such a character int

. But this is different from pointer ... which fails.



I think you can work around this by converting it to the correct type using the extension {}

. Or, to put it simply, install glibc debuginfo. Many distributions have an easy way to do this.

+2


source







All Articles