How can I see the output of printf inside gdb?
This is what I tried,but seems not working:
(gdb开发者_运维知识库) call printf("%d",6)
$8 = 1
You can't see the result is because stdout(FILE*) has a output buffer. It won't output any to the screen 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, The "$6 = 2" which is result value of printf.
It looks like it worked fine - printf
returned 1, indicating that it successfully printed a single character to standard output.
Note that standard output isn't necessarily displayed in the same terminal that gdb is running in - it'll be displayed wherever the program you're debugging has its standard output (it's just as if the program itself had called printf()
- the call
command in gdb calls the function in the program's context).
精彩评论