Skip to content
FormatStackTrace

FormatStackTrace

Description

Format a captured trace. Two shapes:

FormatStackTrace(out_str, frames, count, alloc) – raw FormatStackTrace(out_str, frames_vec, alloc) – vec

Output is appended; never fails – unresolved frames emit as #N 0x<ip>.

Success

Returns to the caller; *out_str has been appended with one line per frame, resolved where the symbol resolver could, and as #N 0x<ip> otherwise.

Failure

Function cannot fail. Allocator OOM while growing *out_str aborts via LOG_FATAL (Str’s standard must-succeed contract).

Usage example (Cross-references)

Usage examples (Cross-references)
            // FormatStackTrace takes `Allocator *` -- legitimate erasure
            // boundary; pass at the call site, no intermediate variable.
            FormatStackTrace(&trace, frames, n, ALLOCATOR_OF(&h));
            (void)FileWrite(&out, StrBegin(&trace), StrLen(&trace));
            StrDeinit(&trace);
        Str rendered = StrInit(meta);
    #if !defined(LOG_NO_BACKTRACE) || !LOG_NO_BACKTRACE
        FormatStackTrace(&rendered, frames, count, meta);
    #else
        // Same rationale as LogWrite's FATAL gate (see Log.c). Symbolicating
            if (val_ptr->alloc_trace_n > 0) {
    #if !defined(LOG_NO_BACKTRACE) || !LOG_NO_BACKTRACE
                FormatStackTrace(out, val_ptr->alloc_trace, val_ptr->alloc_trace_n, ALLOCATOR_OF(&self->meta));
    #else
                for (size i = 0; i < val_ptr->alloc_trace_n; ++i) {
    
        Str rendered = StrInit(alloc_base);
        FormatStackTrace(&rendered, frames, n, alloc_base);
    
        // We expect both helper names to appear in the rendered trace.
    
        Str rendered = StrInit(alloc_base);
        FormatStackTrace(&rendered, &frames, alloc_base);
    
        ok = ok && StrLen(&rendered) > 0;
Last updated on