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

WASM implementation for backtrace (no-op in web) More...

Go to the source code of this file.

Functions

void backtrace_t_free (backtrace_t *bt)
 Free backtrace 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_many (const char *label, const backtrace_t *bts, int count)
 Print multiple backtraces.
 
void backtrace_symbolize (backtrace_t *bt)
 Symbolize bt->ptrs into bt->symbols.
 

Detailed Description

WASM implementation for backtrace (no-op in web)

Definition in file platform/wasm/backtrace.c.

Function Documentation

◆ 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 14 of file platform/wasm/backtrace.c.

15 {
16 (void)label;
17 (void)bt;
18 (void)skip_frames;
19 (void)max_frames;
20 (void)filter;
21 // No-op - backtraces not available in WASM
22}

◆ backtrace_print_many()

void backtrace_print_many ( const char *  label,
const backtrace_t *  bts,
int  count 
)

Print multiple backtraces.

Convenience function for iterating and printing multiple backtrace_t entries.

Parameters
labelHeader label for all backtraces
btsArray of backtrace structures
countNumber of backtraces to print

Definition at line 24 of file platform/wasm/backtrace.c.

24 {
25 (void)label;
26 (void)bts;
27 (void)count;
28 // No-op
29}

◆ 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 31 of file platform/wasm/backtrace.c.

31 {
32 (void)bt;
33 // No-op - symbolization not available in WASM
34}

◆ 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 9 of file platform/wasm/backtrace.c.

9 {
10 (void)bt;
11 // No-op - no resources to free in WASM
12}