Thread overview
Debugging with LLDB on Windows
Aug 03, 2020
WebFreak001
Aug 03, 2020
kinke
Aug 03, 2020
WebFreak001
Aug 04, 2020
kinke
Feb 17, 2021
Siemargl
Feb 23, 2021
Siemargl
Feb 23, 2021
kinke
August 03, 2020
I'm trying to use LLDB on Windows to debug a program compiled with LDC, however it seems LLDB doesn't load any debug symbols or it doesn't know how to parse the ones emitted by LDC.

Is there some way to make LDC emit debug symbols parsable by LLDB? I believe it needs DWARF debugging information to work properly, but I assume that's what LDC already emits.

On the other hand I'm also not sure if it's just the LLDB build I'm using, I've obtained it from the VSCode extension https://github.com/vadimcn/vscode-lldb and it says the version is

lldb version 10.0.1 (local revision a55a07af20ef3228dfc31bd5c0c0161c356fb1af)
  clang revision a55a07af20ef3228dfc31bd5c0c0161c356fb1af
  llvm revision a55a07af20ef3228dfc31bd5c0c0161c356fb1af
  rust-enabled

August 03, 2020
On Monday, 3 August 2020 at 11:56:30 UTC, WebFreak001 wrote:
> I believe it needs DWARF debugging information to work properly, but I assume that's what LDC already emits.

It doesn't, see https://forum.dlang.org/post/ttblgcwiwmdhyukzpocb@forum.dlang.org. - Wrt. VSCode on Windows, we've re-activated `-gc` to improve debugging with the Microsoft C/C++ plugin, see https://github.com/ldc-developers/ldc/pull/2869.
August 03, 2020
On Monday, 3 August 2020 at 17:43:21 UTC, kinke wrote:
> On Monday, 3 August 2020 at 11:56:30 UTC, WebFreak001 wrote:
>> I believe it needs DWARF debugging information to work properly, but I assume that's what LDC already emits.
>
> It doesn't, see https://forum.dlang.org/post/ttblgcwiwmdhyukzpocb@forum.dlang.org. - Wrt. VSCode on Windows, we've re-activated `-gc` to improve debugging with the Microsoft C/C++ plugin, see https://github.com/ldc-developers/ldc/pull/2869.

is it possible to then simply target the MinGW triple? Are there any disadvantages coming from it?

I would like to try making a small D script for LLDB so it can parse all the types and hopefully make a good debug experience on all platforms consistently, because LLDB implements DWARF debug symbols on all platforms.
August 04, 2020
On Monday, 3 August 2020 at 20:37:49 UTC, WebFreak001 wrote:
> is it possible to then simply target the MinGW triple?

Nope, not (fully) supported by druntime and Phobos, and the compiler would probably require a few adaptations too.

As you're the 2nd guy asking for DWARF debuginfos and MSVC targets in a month, and LLVM supports it: https://github.com/ldc-developers/ldc/pull/3533
February 17, 2021
On Tuesday, 4 August 2020 at 18:44:02 UTC, kinke wrote:
> On Monday, 3 August 2020 at 20:37:49 UTC, WebFreak001 wrote:
>> is it possible to then simply target the MinGW triple?
>
> Nope, not (fully) supported by druntime and Phobos, and the compiler would probably require a few adaptations too.
>
> As you're the 2nd guy asking for DWARF debuginfos and MSVC targets in a month, and LLVM supports it: https://github.com/ldc-developers/ldc/pull/3533

Some problems with llvm debugging.

Test log from lldb 10.0.0 - not recognized main function name (but other is found), not steps next line (expect goto finally expression) after throw exception.

Compile>ldc2 -gdwarf -gc -m64 except.d
lld-link: warning: section name .debug_abbrev is longer than 8 characters and will use a non-standard string table
lld-link: warning: section name .debug_info is longer than 8 characters and will use a non-standard string table
lld-link: warning: section name .debug_line is longer than 8 characters and will use a non-standard string table
lld-link: warning: section name .debug_loc is longer than 8 characters and will use a non-standard string table
lld-link: warning: section name .debug_pubnames is longer than 8 characters and will use a non-standard string table
lld-link: warning: section name .debug_pubtypes is longer than 8 characters and will use a non-standard string table
lld-link: warning: section name .debug_ranges is longer than 8 characters and will use a non-standard string table
lld-link: warning: section name .debug_str is longer than 8 characters and will use a non-standard string table

Used MSVC Build tools 2019 (as -v option tells), but lld-link.

-----
>E:\_bin\LLVM\bin\lldb.exe except.exe
> 
>                                                 (lldb) target
>create "except.exe"
Current executable set to 'E:\VSProjects\testjunk\DbetterC\except.exe' (x86_64).
(lldb) b main
Breakpoint 1: no locations (pending).
WARNING:  Unable to resolve breakpoint to any actual locations.
(lldb) b _Dmain
Breakpoint 2: no locations (pending).
WARNING:  Unable to resolve breakpoint to any actual locations.
(lldb) b except.d:3
Breakpoint 3: where = except.exe`_Dmain + 16 at except.d:9:13, address = 0x0000000140001010
(lldb) r
Process 90056 launched: 'E:\VSProjects\testjunk\DbetterC\except.exe' (x86_64)
Process 90056 stopped
* thread #1, stop reason = breakpoint 3.1
    frame #0: 0x00007ff6369d1010 except.exe`_Dmain at except.d:9:13
   6        {
   7            try
   8            {
-> 9                throw new Exception("first");
   10           }
   11           finally
   12           {
(lldb) n
Process 90056 exited with status = 0 (0x00000000)
(lldb)
---

February 23, 2021
On Wednesday, 17 February 2021 at 20:26:54 UTC, Siemargl wrote:
> Some problems with llvm debugging.
>
> Test log from lldb 10.0.0 - not recognized main function name (but other is found), not steps next line (expect goto finally expression) after throw exception.

Something wrong with generation debug info.

Case 1. CV debug info

>ldc2 -g -gc except.d
>list - showed nothing
>b _Dmain - works, breakpoink stopped, but shows only assembly code
>list - showed nothing after stop
>b except.d:13  - not working (no source code)
>b _d_throw_exception - also works as asm
>image dump symtab except.exe - works, many D symbols seen (>1000)

Same executable, MS WinDbg X64 works, may set breakpoints in opened source code, step by step debugging works.
Also Windbg commands worked fine bp Dmain, bp d_throw_exception working (without leading underscore!)


Case 2. Dwarf debug info

>ldc2 -gdwarf -g -gc except.d
>b _Dmain - not working
>b except.d:13  - works, after stoping at breakpoint shows source, 'next' command steps ok
>list - showed source ater breakpoint stops
>b _d_throw_exception - not working
>image dump symtab except.exe - not works, num_symbols = 0









February 23, 2021
On Tuesday, 23 February 2021 at 12:03:05 UTC, Siemargl wrote:
> Same executable, MS WinDbg X64 works, may set breakpoints in opened source code, step by step debugging works.
> Also Windbg commands worked fine bp Dmain, bp d_throw_exception working (without leading underscore!)

The generated CodeView has been checked/tailored for the VS debugger (with both -g and -gc). The corresponding tests use the `cdb` console debugger. I've noted some discrepancies between VS and cdb too.

I haven't tested DWARF on Windows at all, and neither fired up lldb a single time on Windows. I have no idea about its Windows support. You could try `--debugger-tune=lldb` (a pure LLVM option, doesn't affect LDC at all) and see if that improves anything.