August 18, 2013 Win32: How to get the stack trace when compiling with a windows subsystem? | ||||
|---|---|---|---|---|
| ||||
When you compile with -L/SUBSYSTEM:WINDOWS you're essentially building an app without a console, so if you want to print out messages you'd have to log them to a file. For example:
-----
import core.sys.windows.windows;
import std.stdio;
extern(Windows) HWND GetConsoleWindow();
void main()
{
if (!GetConsoleWindow())
{
stdout.open(r".\stdout.log", "w");
stderr.open(r".\stderr.log", "w");
}
try
{
realMain();
}
catch (Throwable thr)
{
stderr.writeln(thr.msg);
throw thr;
}
}
void realMain()
{
assert(0);
}
-----
Compilable and runnable with:
dmd -g -L/SUBSYSTEM:WINDOWS:5.01 -run test.d
This will write the exception message to a log file, however I'd also like to retrieve the stack trace to log that as well. For example here's the output in a regular console app (without the windows subsystem):
core.exception.AssertError@test(29): Assertion failure
----------------
0x0041D93B in onAssertError
0x004020DD in void test.realMain() at C:\dev\code\d_code\test.d(30)
0x0040208B in _Dmain at C:\dev\code\d_code\test.d(18)
0x00417BE8 in extern (C) int rt.dmain2._d_run_main(int, char**, extern (C
) int function(char[][])*).void runMain()
0x00417C78 in extern (C) int rt.dmain2._d_run_main(int, char**, extern (C
) int function(char[][])*).void runAll()
0x00417555 in _d_run_main
0x00408690 in main
0x0042DD29 in mainCRTStartup
0x774F33CA in BaseThreadInitThunk
0x77D09ED2 in RtlInitializeExceptionChain
0x77D09EA5 in RtlInitializeExceptionChain
I'd like to log this out when building with a windows subsystem. Is there any way to do that?
| ||||
August 18, 2013 Re: Win32: How to get the stack trace when compiling with a windows subsystem? | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Andrej Mitrovic | On Sun, 18 Aug 2013 16:07:20 +0200 Andrej Mitrovic <andrej.mitrovich@gmail.com> wrote: > > catch (Throwable thr) > { > stderr.writeln(thr.msg); stderr.writeln(thr.msg); // No trace stderr.writeln(thr); // Includes trace However, I'm guessing it probably doesn't solve the other 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: | |||
Copyright © 1999-2021 by the D Language Foundation
Permalink
Reply