Skip to content
CaptureStackTrace

CaptureStackTrace

Description

Capture up to max_frames frames of the caller’s stack via the saved-FP chain. skip_frames discards the topmost frames (caller’s own wrappers). CaptureStackTrace’s own frame is always skipped.

Parameters

Name Direction Description
out out Frame array to populate.
max_frames in Capacity of out.
skip_frames in Number of caller-side wrappers to discard.

Success

Returns number of frames written (<= max_frames).

Failure

Returns 0 if frame pointers are unavailable (build with -fomit-frame-pointer) or the stack is structurally invalid. out is left untouched on failure.

Usage example (Cross-references)

Usage examples (Cross-references)
    // captured trace.
    static __attribute__((noinline)) size bt_capture_with_helper(StackFrame *frames, size max) {
        return CaptureStackTrace(frames, max, 0);
    }
    }
    
    size CaptureStackTrace(StackFrame *out, size max_frames, size skip_frames) {
        if (!out || max_frames == 0)
            return 0;
    };
    
    size CaptureStackTrace(StackFrame *out, size max_frames, size skip_frames) {
        if (!out || max_frames == 0) {
            return 0;
            if (depth > DEBUG_ALLOCATOR_MAX_TRACE)
                depth = DEBUG_ALLOCATOR_MAX_TRACE;
            rec.alloc_trace_n = (u32)CaptureStackTrace(rec.alloc_trace, depth, 2);
        }
            if (depth > DEBUG_ALLOCATOR_MAX_TRACE)
                depth = DEBUG_ALLOCATOR_MAX_TRACE;
            rec->free_trace_n = (u32)CaptureStackTrace(rec->free_trace, depth, 3);
        }
        rec->freed = true;
Last updated on