问题
Let us say that I have a function in a C program test.c
like this:
#include <stdio.h>
char* foo = "test";
void print_foo(void)
{
printf("%s", foo);
}
main() { }
I compile and run test.c
like this:
gcc -g -o test test.c
chmod 755 test && lldb -s <(echo "b main\nr") test
However, if I then run expr print_foo()
no string output occurs:
(lldb) expr print_foo()
(lldb)
回答1:
STDOUT is line buffered. You haven't emitted a newline yet. Try calling (lldb) expr (void) fflush(0)
and you should see the output. Or have foo be "test\n".
来源:https://stackoverflow.com/questions/33969943/how-can-i-see-printf-output-when-evaluating-an-expression-using-the-expr-comma