On Sat, Sep 14, 2013 at 07:34:26PM +0200, Adam D. Ruppe wrote: > On Saturday, 14 September 2013 at 12:25:44 UTC, Paolo Invernizzi > wrote: > >Give me a way to writeln the callstack frames at a certain > > Challenge accepted: > > > import std.stdio; > > string getStackTrace() { > import core.runtime; > > version(Posix) { > // druntime cuts out the first few functions on the trace as > they are internal > // so we'll make some dummy functions here so our actual > info doesn't get cut > Throwable.TraceInfo f5() { return defaultTraceHandler(); } > Throwable.TraceInfo f4() { return f5(); } > Throwable.TraceInfo f3() { return f4(); } > Throwable.TraceInfo f2() { return f3(); } > auto stuff = f2(); > } else { > auto stuff = defaultTraceHandler(); > } > > return stuff.toString(); > } > > > void foo() { > writeln("on foo"); > bar(); > } > > void bar() { > writeln("on bar"); > omg(); > } > > void omg() { > writeln("on omg"); > > writeln(getStackTrace()); > } > > void main() { > omg(); > > writeln("\n****\n"); > foo(); > }
Whoa. My hats off to you, sir!! (And yes, I did actually test this code with a few call trees of my own. It really does work! Amazing.) I'm gonna put this into my personal D library, right now! T -- Recently, our IT department hired a bug-fix engineer. He used to work for Volkswagen.