A minimalistic single-header multi-platform C89 lib for stack tracing
Clone the repo or copy b_stacktrace.h
in your project tree.
Including b_stacktrace.h
provides:
char* b_stacktrace_get_string();
- Returns a human-readable stack-trace string from the point of view of the caller. The string is allocated withmalloc
and needs to be freed withfree
.b_stacktrace_handle b_stacktrace_get();
- Returns a stack-trace handle from the point of view of the caller which can be expanded to a string viab_stacktrace_to_string
. The handle is allocated withmalloc
and needs to be freed withfree
.b_stacktrace_to_string(b_stacktrace_handle stacktrace);
- Converts a stack-trace handle to a human-readable string. The string is allocated withmalloc
and needs to be freed withfree
.
#define B_STACKTRACE_IMPL
before including b_stacktrace.h
in one C or C++ file to create the implementation
TBD
The subdirectory example/
contains several small examples:
trace.c
- creates a trace from a C programtrace.cpp
- creates a trace from a C++ program, demonstrating more complex symbols (classes, templates)crash.c
- example usage of the provided stack trace: as a crash handler
The library is distributed under the MIT Software License. Copyright © 2020-2023 Borislav Stanimirov.