How can I see printf output when evaluating an expression using the `expr` command in lldb?

依然范特西╮ 提交于 2019-12-14 01:26:08

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!