[OT] Which IDE / Editor do you use?

Sönke Ludwig sludwig at outerproduct.org
Sun Sep 15 03:14:13 PDT 2013


Am 14.09.2013 22:20, schrieb Paolo Invernizzi:
> On Saturday, 14 September 2013 at 17:34:27 UTC, 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();
>> }
>
>
> O_o
>
> Adam, this is *really* an unexpected gift!
> I suggest to add this example in the core.runtime DDoc at least!
>
> - Paolo

Even better would be to promote the underlying function for 
"defaultTraceHandler" to be public and add an argument (size_t nskip = 
0) to make it generally useful without those ugly artificial stack 
frames. I mean don't get me wrong, I've used that same hack myself a few 
weeks ago, but it doesn't really make for a premium API ;)


More information about the Digitalmars-d mailing list