gpt4 book ai didi

debugging - 在 lldb 中使用 `expr` 命令计算表达式时如何查看 printf 输出?

转载 作者:行者123 更新时间:2023-12-02 11:29:40 25 4
gpt4 key购买 nike

假设我在 C 程序 test.c 中有一个函数,如下所示:

#include <stdio.h>
char* foo = "test";
void print_foo(void)
{
printf("%s", foo);
}
main() { }

我像这样编译并运行test.c:

gcc -g -o test test.c
chmod 755 test && lldb -s <(echo "b main\nr") test

但是,如果我随后运行 expr print_foo() 则不会出现字符串输出:

(lldb) expr print_foo()
(lldb)

最佳答案

STDOUT 是行缓冲的。您还没有发出换行符。尝试调用 (lldb) expr (void) fflush(0)

您应该会看到输出。或者让 foo 为“test\n”。

关于debugging - 在 lldb 中使用 `expr` 命令计算表达式时如何查看 printf 输出?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33969943/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com