Print only part of a stack trace

Dennis dkorpel at gmail.com
Wed Jul 1 18:54:55 UTC 2020


On Wednesday, 1 July 2020 at 18:44:10 UTC, Stanislav Blinov wrote:
> void assertNoOpenGLErrors(string file = __FILE__, int line = 
> __LINE__, string func = __PRETTY_FUNCTION__)
> {
>     if (glGetError() != GL_NO_ERROR) {
>         print(file, ":", line, ":", func, ": blah");
>         exit();
>     }
> }
>
> :)

I love __FILE__ and __LINE__, but in this case they won't cut it.
In my actual code there's usually one or two more functions 
inbetween, and amending hundreds of signatures with __FILE__ and 
__LINE__ for a little debugging convenience is not worth it.

I'm now trying to call the defaultTraceHandler manually like this:
```
void bar() {
     import std.stdio;
     import core.runtime: defaultTraceHandler;
     auto res = defaultTraceHandler(null);
     writeln(res);
}

void foo() {bar();}
void main() {foo();}
```

It sort of works, but it seems it does not start at the right 
stack frame, the top item is this:

??:? void rt.dmain2._d_run_main2(char[][], ulong, extern (C) int 
function(char[][])*).runAll().__lambda1() [0x55c19a09c1fa]


More information about the Digitalmars-d-learn mailing list