在我的 Windows 10 计算机上设置 clang 时,我无法让调试器正常工作。编译似乎工作正常,至少对于我尝试过的简单的“hello,world”程序来说是这样。但是,当我尝试在此测试程序(或我尝试过的任何其他程序)上运行 lldb 或 gdb 调试器时,它无法识别函数名称。
这是我的C程序代码:
#include <stdio.h>
int main(void) {
puts("Hello, world!");
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我知道这里没什么特别的。我正在使用以下命令进行编译:
> clang -g -O0 hello.c -o hello.exe
Run Code Online (Sandbox Code Playgroud)
然后我尝试运行调试器:
> lldb hello
(lldb) target create "hello"
Current executable set to 'hello' (x86_64).
(lldb) b main
Breakpoint 1: no locations (pending).
WARNING: Unable to resolve breakpoint to any actual locations.
(lldb) r
Process 12156 launched: 'C:\Users\********\Projects\clang-test\hello.exe' (x86_64)
Process 12156 exited with status = 0 (0x00000000)
(lldb)
Run Code Online (Sandbox Code Playgroud)
显然,符号“main”未被识别,并且程序没有在“main”函数开始时停止,而是运行到完成(在不同的控制台窗口中,因此这里没有程序输出)。
如何让调试符号发挥作用?在另一个 stackoverflow 答案中,我发现添加编译器选项“-g …