How can I see printf output inside gdb?

This is what I tried but does not seem to work:

(gdb) call printf("%d",6) $8 = 1 
+6
c linux gdb
source share
2 answers

You do not see the result because stdout (FILE *) has an output buffer. It does not display any data until the buffer is full or "\ n" is encountered.

so call printf like this:

 (gdb) call (int)printf("%d\n", 6) 6 $6 = 2 

BTW, "$ 6 = 2", which is the result of printf.

+7
source share

It looks like it worked fine - printf returned 1, indicating that it successfully printed one character for standard output.

Note that standard output is not necessarily displayed on the same terminal that gdb runs on - it will be displayed wherever the debugged program has its standard output (just as if the program itself was called printf() - the call command in gdb calls a function in the context of the program).

+1
source share

All Articles