libxtc
0.4.0
Async concurrency for C: Tokio + Seastar + BEAM, in one library
Loading...
Searching...
No Matches
os_backtrace.h
1
/*-
2
* Copyright (c) 2026, The XTC Project
3
* Use of this source code is governed by the ISC License.
4
*
5
* src/inc/os_backtrace.h
6
* Cross-platform native stack backtrace seam. Captures the C call
7
* stack of the CALLING OS thread and emits human-readable frames.
8
* The implementation is selected at configure time, in priority order:
9
*
10
* - execinfo (glibc/macOS/BSD): symbolized frames, async-signal-safe.
11
* - libunwind (musl and other execinfo-less libc's): frame addresses
12
* via the unwinder, symbolized best-effort with dladdr when present
13
* (else addresses only). Frame walking + address emission are
14
* async-signal-safe; the dladdr name lookup is best-effort.
15
* - DbgHelp (Windows): symbolized frames -- COMPILED BUT NOT
16
* RUNTIME-VERIFIED on the porting host (no Windows machine in the
17
* CI matrix); reviewed against the DbgHelp API, like src/io/io_aix.c.
18
* - stub (no backend available): an empty backtrace, never a
19
* build error.
20
*
21
* __os_backtrace_emit uses only async-signal-safe primitives on the
22
* execinfo (backtrace_symbols_fd) and libunwind (write(2)) paths, so it
23
* is safe to call from a fatal-signal handler there. The Windows path
24
* serializes the non-signal-safe DbgHelp Sym* family under a lock and is
25
* intended for the panic/abort path. See src/ptc/dump.c and
26
* docs/guide/debugging.md.
27
*/
28
29
#ifndef XTC_OS_BACKTRACE_H
30
#define XTC_OS_BACKTRACE_H
31
32
/*
33
* PUBLIC: int __os_backtrace __P((void **, int));
34
* PUBLIC: void __os_backtrace_emit __P((int, void *const *, int));
35
* PUBLIC: int __os_backtrace_supported __P((void));
36
*/
37
38
/* Capture up to `max` return addresses of the calling thread into
39
* `frames`. Returns the number captured (0 if unsupported). */
40
int
__os_backtrace(
void
**frames,
int
max);
41
42
/* Symbolize `n` frames (as returned by __os_backtrace) and write them,
43
* one per line, to `fd`. Best-effort and async-signal-safe; writes
44
* nothing when unsupported. */
45
void
__os_backtrace_emit(
int
fd,
void
*
const
*frames,
int
n);
46
47
/* 1 if a real backtrace backend is compiled in, 0 if the stub. */
48
int
__os_backtrace_supported(
void
);
49
50
#endif
/* XTC_OS_BACKTRACE_H */
src
inc
os_backtrace.h
Generated by
1.9.8