ascii-chat 0.11.33
Video chat in your terminal
Loading...
Searching...
No Matches
backtrace.c File Reference

Backtrace stubs for WASM (not available in browser environment) More...

Go to the source code of this file.

Typedefs

typedef bool(* backtrace_frame_filter_t) (const char *frame)
 

Functions

void backtrace_capture (backtrace_t *bt)
 Capture current stack into bt.
 
void backtrace_capture_and_symbolize (backtrace_t *bt)
 Capture and symbolize in one call.
 
void backtrace_free (backtrace_t *bt)
 
void backtrace_t_free (backtrace_t *bt)
 Free backtrace symbols.
 
void backtrace_symbolize (backtrace_t *bt)
 Symbolize bt->ptrs into bt->symbols.
 
void backtrace_print (const char *label, const backtrace_t *bt, int skip_frames, int max_frames, backtrace_frame_filter_t filter)
 Print backtrace with dual output: colored stderr + plain log file.
 
void backtrace_print_simple (int skip_frames)
 Print backtrace of the current call stack.
 

Detailed Description

Backtrace stubs for WASM (not available in browser environment)

Definition in file platform/wasm/stubs/backtrace.c.

Typedef Documentation

◆ backtrace_frame_filter_t

typedef bool(* backtrace_frame_filter_t) (const char *frame)

Definition at line 42 of file platform/wasm/stubs/backtrace.c.

Function Documentation

◆ backtrace_capture()

void backtrace_capture ( backtrace_t *  bt)

Capture current stack into bt.

Calls platform_backtrace() to capture raw return addresses. Does not symbolize (symbols remain NULL).

Parameters
btBacktrace structure to fill (must not be NULL)

Definition at line 9 of file platform/wasm/stubs/backtrace.c.

9 {
10 if (bt) {
11 bt->count = 0;
12 bt->symbols = NULL;
13 }
14}
int count
Number of frames captured.
char ** symbols
Symbolized strings (NULL until backtrace_symbolize called)

References backtrace_t::count, and backtrace_t::symbols.

◆ backtrace_capture_and_symbolize()

void backtrace_capture_and_symbolize ( backtrace_t *  bt)

Capture and symbolize in one call.

Convenience function combining backtrace_capture() and backtrace_symbolize().

Parameters
btBacktrace structure to fill and symbolize (must not be NULL)

Definition at line 16 of file platform/wasm/stubs/backtrace.c.

16 {
17 if (bt) {
18 bt->count = 0;
19 bt->symbols = NULL;
20 }
21}

References backtrace_t::count, and backtrace_t::symbols.

◆ backtrace_free()

void backtrace_free ( backtrace_t *  bt)

Definition at line 23 of file platform/wasm/stubs/backtrace.c.

23 {
24 if (bt) {
25 bt->count = 0;
26 bt->symbols = NULL;
27 }
28}

References backtrace_t::count, and backtrace_t::symbols.

◆ backtrace_print()

void backtrace_print ( const char *  label,
const backtrace_t *  bt,
int  skip_frames,
int  max_frames,
backtrace_frame_filter_t  filter 
)

Print backtrace with dual output: colored stderr + plain log file.

Intelligently formats and routes backtraces to multiple destinations:

  • stderr: Colored output with semantic highlighting (for interactive debugging)
  • log file (if logging): Plain ASCII without ANSI codes (for file parsing)

This dual-output design ensures readable terminal output during development while keeping log files clean and searchable in production.

Output Format

Terminal output example:

=== Backtrace: Error ===
[0] 0x7f1234567890 in main() [src/main.c:42]
[1] 0x7f1234567800 in process_request() [src/network.c:128]
[2] 0x7f1234567700 in send_data() [src/io.c:67]
int main(int argc, char *argv[])
Definition main.c:472

Log file (same content, no colors):

=== Backtrace: Error ===
[0] 0x7f1234567890 in main() [src/main.c:42]
...
Parameters
labelHeader label (e.g., "Backtrace", "Leak trace", "Assertion failure")
btBacktrace to print (must not be NULL, must be symbolized via backtrace_capture_and_symbolize)
skip_framesNumber of frames to skip from start (0 = include all, 1 = skip first frame, etc.)
max_framesMaximum frames to print (0 = unlimited, 5 = first 5 frames only)
filterOptional callback to selectively skip frames (e.g., filter internal frames) Return true to skip frame, false to include. NULL = no filtering.
Note
Backtrace must be symbolized. Unsymbolized (raw hex) traces are less useful.
Frame filtering is useful to focus on application code, excluding:
  • lib/platform internal calls
  • lib/log infrastructure
  • Exception handling wrappers
See also
backtrace_format() for buffer-based output (safe for log system)

Definition at line 44 of file platform/wasm/stubs/backtrace.c.

45 {
46 (void)label;
47 (void)bt;
48 (void)skip_frames;
49 (void)max_frames;
50 (void)filter;
51 // No-op for WASM
52}

◆ backtrace_symbolize()

void backtrace_symbolize ( backtrace_t *  bt)

Symbolize bt->ptrs into bt->symbols.

Calls platform_backtrace_symbols() to convert raw addresses to symbol strings. This is a no-op if symbols are already set (already symbolized).

Parameters
btBacktrace structure to symbolize (must not be NULL)

Definition at line 37 of file platform/wasm/stubs/backtrace.c.

37 {
38 (void)bt;
39 // No-op for WASM
40}

◆ backtrace_t_free()

void backtrace_t_free ( backtrace_t *  bt)

Free backtrace symbols.

Calls platform_backtrace_symbols_destroy() to free the symbols array. Nulls the symbols pointer after freeing.

Parameters
btBacktrace structure (must not be NULL)

Definition at line 30 of file platform/wasm/stubs/backtrace.c.

30 {
31 if (bt) {
32 bt->count = 0;
33 bt->symbols = NULL;
34 }
35}

References backtrace_t::count, and backtrace_t::symbols.