How to get debugging symbols when compiling with clang on Windows

0

I am having trouble getting the debugger to work properly when setting up clang on my Windows 10 machine. Compilation seems to work OK, at least for the simple "hello, world" program I tried. However, when I try to run the lldb or gdb debuggers on this test program (or any other program I tried), it does not recognize function names.

Here's my C program code:

#include <stdio.h>

int main(void) {
    puts("Hello, world!");
    return 0;
}

Nothing too spectacular here, I know. I'm compiling with the following command:

> clang -g -O0 hello.c -o hello.exe

I then try to run the debugger:

> 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)

Apparently the symbol "main" was not recognized, and the program did not halt at the start of the "main" function but ran to completion (in a different console window, hence no program output here).

How do I get debugging symbols to work? In a different stackoverflow answer I found that adding compiler options "-g -O0" should do the trick, but as you can see that does not solve the problem for me. I also found a different stackoverflow answer about how to set up debugging if the code is not in the same directory as the executable, but that is not relevant to my case: the current working directory is the same as the directory with the code and executable in them.

Some version information:

> clang --version
clang version 9.0.0 (tags/RELEASE_900/final)
Target: x86_64-pc-windows-msvc
Thread model: posix
InstalledDir: C:\Program Files\LLVM\bin

> lldb --version
lldb version 9.0.0
c
windows
clang
lldb
asked on Stack Overflow Sep 26, 2019 by Guido van den Heuvel • edited Sep 26, 2019 by Guido van den Heuvel

1 Answer

0

The "-g -O0" options you provided should indeed let the debugger know all the symbols it needs from the executable.

Therefore, I suspect the problem is elsewhere, perhaps with your terminal, or your version/implementation of LLDB.

Are you using the windows cmd.exe commandline ? or something else, like Powershell ? I've never managed to get debuggers working properly in those environments, but it was much easier with Cygwin, which is a bash shell for windows (it creates a "simulated" linux environment within its install folder, so you have all the /usr,/bin,/etc folders a bash shell needs) This way you can actually use gdb the way you would on a UNIX system.

If the above method sounds like more of a hassle than a time-gain, then yeah I would recommend another debugger altogether, like the Visual Studio debugger. In fact, maybe a memory-analysis tool like Dr.Memory can give you what you need

answered on Stack Overflow Sep 26, 2019 by Lexou

User contributions licensed under CC BY-SA 3.0