Win32: How to get the stack trace when compiling with a windows subsystem?

Andrej Mitrovic andrej.mitrovich at gmail.com
Sun Aug 18 07:35:30 PDT 2013


On 8/18/13, Adam D. Ruppe <destructionator at gmail.com> wrote:
> extern(Windows) void AllocConsole(); // not sure if that's the
> perfect signature but it works
>
> void main() {
>     debug AllocConsole();
>     throw new Exception("test");
> }
>
>
> The problem is the console will close before you can actually
> read it! But it is there and the exception text did appear in it
> so that's something.

Thanks. However I've found a solution but also a new problem. The
'info' field of a Throwable can be converted to a string, so I can
output this into a log file.

But, the info field is always null in a module constructor:

-----
import std.stdio;

import core.sys.windows.windows;
extern(Windows) HWND GetConsoleWindow();

shared static this()
{
    stderr.open(r".\stderr.log", "w");

    try
    {
        assert(0);
    }
    catch (Throwable thr)
    {
        stderr.writefln("thr.info: %s", thr.info);
    }
}

void main() { }
-----

$ dmd -g -L/SUBSYSTEM:WINDOWS:5.01 -run test.d && type stderr.log
$ thr.info: null

If I copy-paste the code from the module ctor into main then thr.info
has the proper stack trace information.

Should I be calling some runtime initialization functions in the
module ctor so the stack traces work there?


More information about the Digitalmars-d-learn mailing list