Catching excecptions in the MSVC debugger when running Win64
Rainer Schuetze
r.sagitario at gmx.de
Tue Apr 27 06:05:26 UTC 2021
On 27/04/2021 07:43, Lewis wrote:
> Okay, I was able to get the VS debugger to catch exceptions in win64 by
> adding a hack to deh_win64_posix.d so that it mimics deh_win32.d.
>
> I added the following code above the definition of _d_throwc():
>
> ```
> import core.sys.windows.windef : DWORD;
> extern(Windows)
> {
> void RaiseException(DWORD, DWORD, DWORD, void*);
> }
> ```
>
> ...and I added the following to _d_throwc() itself, right after it calls
> _d_createTrace():
>
> ```
> template MAKE_EXCEPTION_CODE(int severity, int facility, int exception)
> {
> enum int MAKE_EXCEPTION_CODE = (((severity) << 30) | (1 << 29) | (0 <<
> 28) | ((facility) << 16) | (exception));
> }
> enum int STATUS_DIGITAL_MARS_D_EXCEPTION = MAKE_EXCEPTION_CODE!(3,'D',1);
> enum DWORD EXCEPTION_NONCONTINUABLE = 1;
> RaiseException(STATUS_DIGITAL_MARS_D_EXCEPTION,
> EXCEPTION_NONCONTINUABLE, 1, cast(void*)&h);
> ```
>
> With this, the debugger catches exceptions again.
>
> This feels like a total hack though. Presumably I'm missing an obvious
> better solution?
Unfortunately, the dmd backend does not use the standard exception
mechanism for win64, but some homegrown one adapted from the linux
exception handling. That's why the debugger does not recognize the
exceptions.
Your solution works for catching exceptions, but catch statements will
not work with RaiseException. I guess the best option is to set a
breakpoint in _d_throwc.
LDC uses C++ exceptions, so your debugger should behave as expected when
building with LDC.
More information about the Digitalmars-d-debugger
mailing list