www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 21318] New: Add ability to get raw stack trace from TraceInfo


          Issue ID: 21318
           Summary: Add ability to get raw stack trace from TraceInfo
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P1
         Component: druntime
          Assignee: nobody puremagic.com
          Reporter: kytodragon e.mail.de

It would be nice if it was possible to directly retrieve the stack trace of a
TraceInfo instance as either void*[] or size_t[].

TraceInfo currently only exports a "resolved" version of each frame as a string
via its opApply, which can be very lacking and is not  nogc.

Example stack trace on Ubuntu:
Exception: Range violation!
??:? [0x55ed1c6558a5]
??:? [0x55ed1c6611e6]
??:? [0x55ed1c644aed]
??:? [0x55ed1c63d128]
??:? [0x55ed1c63d817]
??:? [0x55ed1c6447bb]
??:? [0x55ed1c6446b2]
??:? [0x55ed1c64450d]

Since both core.runtime.DefautTraceInfo and the members of
core.sys.windows.stacktrace.StackTrace are private, the only way to get a good
stack trace is something like this (for Posix):

struct DefaultTraceInfo {
    void** vfptr;
    int numframes;
    void*[128] callstack = void;
DefaultTraceInfo* info = cast(DefaultTraceInfo*)cast(void*)er.info;
size_t[] trace = cast(size_t[])info.callstack[0..info.numframes];

A standardized way would be appreciated.

Oct 16 2020