Thread overview
Using Windbg to debug D applications and unittests
Feb 25, 2023
solidstate1991
Feb 25, 2023
evilrat
Feb 25, 2023
solidstate1991
Feb 25, 2023
evilrat
Feb 25, 2023
solidstate1991
Feb 25, 2023
evilrat
Feb 25, 2023
solidstate1991
Feb 27, 2023
Basile B.
Mar 04, 2023
Chris Piker
Mar 05, 2023
Basile B.
February 25, 2023

I had a lot of trouble trying to get Visual Studio to catch handled exceptions, which would have been mandatory for debugging unittests, but I either forgot how to do it, or something have changed in either the newer versions of VS or the D compilers I use (LDC, DMD).

So I downloaded the new WinDbg Preview, which is like the older WinDbg but with some new features and a new GUI. This would also allow me (in theory) to get rid of VS in the future or only keep it for other projects. So far I struggle to set up breakpoints that actually work and doesn't just step over them. It also doesn't like templates, especially if there's multiple instances of them. (Also I couldn't find any way to break on exceptions so far.)

February 25, 2023

On Saturday, 25 February 2023 at 15:55:33 UTC, solidstate1991 wrote:

>

I had a lot of trouble trying to get Visual Studio to catch handled exceptions

VisualD for Visual Studio provides some extra help with displaying your data in debugger and on Windows is the best you can get for D.

You can use Visual Studio Code + code-d to debug, but it is not as good as full Visual Studio counterpart.

Anyway you can use LDC with -gc flag to improve this situation a bit as it will mimic C++ debug info that is more compatible with said debuggers than D one.

February 25, 2023

On Saturday, 25 February 2023 at 16:22:49 UTC, evilrat wrote:

>

VisualD for Visual Studio provides some extra help with displaying your data in debugger and on Windows is the best you can get for D.

You can use Visual Studio Code + code-d to debug, but it is not as good as full Visual Studio counterpart.

Anyway you can use LDC with -gc flag to improve this situation a bit as it will mimic C++ debug info that is more compatible with said debuggers than D one.

I used to use Visual Studio, but I forgot how to set it up properly to break on handled throws. Now it doesn't do anything if throws are handled in any fashion, and I can't find an option to change it (it was removed maybe?).

February 25, 2023

On Saturday, 25 February 2023 at 16:58:44 UTC, solidstate1991 wrote:

>

I used to use Visual Studio, but I forgot how to set it up properly to break on handled throws. Now it doesn't do anything if throws are handled in any fashion, and I can't find an option to change it (it was removed maybe?).

Turn on exception settings panel in top menu bar:
Debug->Windows->Exceptions Settings (Crtl+Alt+E)

My settings for D is full "D exceptions", under Win32 check "D Exception", or just click "Restore to default settings" in there on top of that panel.

February 25, 2023

On Saturday, 25 February 2023 at 18:08:57 UTC, evilrat wrote:

>

Turn on exception settings panel in top menu bar:
Debug->Windows->Exceptions Settings (Crtl+Alt+E)

My settings for D is full "D exceptions", under Win32 check "D Exception", or just click "Restore to default settings" in there on top of that panel.

Well, VS turned to be even less cooperative than before. Now it only loads and runs a specific old version of an EXE file.

I'm asking around for other debuggers, I'm definitely moving to another.

February 25, 2023

On Saturday, 25 February 2023 at 19:31:10 UTC, solidstate1991 wrote:

>

Well, VS turned to be even less cooperative than before. Now it only loads and runs a specific old version of an EXE file.

I'm asking around for other debuggers, I'm definitely moving to another.

Nothing happens without a reason, check your project settings and make sure that for debugging you have correct paths, command, and arguments.

Even with no debug info and no project you can just drop an executable to an empty VS window and start debugging it, at the very least it can show disassembly.
If there is .pdb files with debug info next to your executable you can just drag and drop your D source files and then add breakpoints in that source files and it will work.

February 25, 2023

On Saturday, 25 February 2023 at 19:55:27 UTC, evilrat wrote:

>

Nothing happens without a reason, check your project settings and make sure that for debugging you have correct paths, command, and arguments.

Even with no debug info and no project you can just drop an executable to an empty VS window and start debugging it, at the very least it can show disassembly.
If there is .pdb files with debug info next to your executable you can just drag and drop your D source files and then add breakpoints in that source files and it will work.

Well, it was that.

I'll try to get GDB running, since I got so fed up with MS's own debuggers.

February 27, 2023

On Saturday, 25 February 2023 at 15:55:33 UTC, solidstate1991 wrote:

>

I had a lot of trouble trying to get Visual Studio to catch handled exceptions, which would have been mandatory for debugging unittests, but I either forgot how to do it, or something have changed in either the newer versions of VS or the D compilers I use (LDC, DMD).
[...]

You must break on _d_throwc (windows), _d_throwdwarf (linux), _d_throw_exception (ldc).

They are defined in

At least this is what is done for the Dexed GDB widget, so that gdb breaks automatically when an Error or an Exception is new'd (https://gitlab.com/basile.b/dexed/-/blob/master/src/u_gdb.pas#L2072).

March 04, 2023

On Monday, 27 February 2023 at 12:09:50 UTC, Basile B. wrote:

>

At least this is what is done for the Dexed GDB widget, so that gdb breaks automatically when an Error or an Exception is new'd (https://gitlab.com/basile.b/dexed/-/blob/master/src/u_gdb.pas#L2072).

Glad you mentioned Dexed. I Had been meaning to try it out but forgot about it. I just downloaded the deb and will give it a go. Thanks!

March 05, 2023

On Saturday, 4 March 2023 at 19:19:26 UTC, Chris Piker wrote:

>

On Monday, 27 February 2023 at 12:09:50 UTC, Basile B. wrote:

>

At least this is what is done for the Dexed GDB widget, so that gdb breaks automatically when an Error or an Exception is new'd (https://gitlab.com/basile.b/dexed/-/blob/master/src/u_gdb.pas#L2072).

Glad you mentioned Dexed. I Had been meaning to try it out but forgot about it. I just downloaded the deb and will give it a go. Thanks!

The GDB widget wont work on windows I think. The point of my first answer was just to show you how to automatically break when something is thrown.