Skip to main content

mod_alloc/symbolicate/
mod.rs

1//! Symbolication for the per-call-site report (v0.9.2).
2//!
3//! Behind the `symbolicate` cargo feature. Turns the raw return
4//! addresses captured by v0.9.1's backtrace path into
5//! `(function, file, line)` tuples at *report-generation time*.
6//! Never invoked from the alloc hot path.
7//!
8//! ## Dependencies
9//!
10//! See `.dev/DIRECTIVES.md` section 2.2 for the approved external-
11//! dep exception. Default builds, the `counters` feature, and
12//! the `backtraces` feature remain zero-runtime-dep. The
13//! `symbolicate` feature pulls in:
14//!
15//! - `addr2line` + `object` + `rustc-demangle` (all targets)
16//! - `pdb` (Windows only)
17//!
18//! All are pure-Rust, MSRV 1.75-compatible.
19//!
20//! ## Platform parity
21//!
22//! Linux / macOS produce richer output than Windows (DWARF
23//! inlining info is more complete than PDB's `S_INLINESITE`).
24//! This is accepted; the asymmetry is documented and not gated.
25
26use std::path::PathBuf;
27
28pub(crate) mod self_binary;
29
30#[cfg(unix)]
31pub(crate) mod unix;
32
33#[cfg(windows)]
34pub(crate) mod windows;
35
36pub(crate) mod report;
37
38/// One symbolicated frame within a call site.
39///
40/// `function`, `file`, and `line` are each `None` when the
41/// underlying debug info did not resolve to a name / location
42/// (stripped binaries, FFI frames into system libraries, etc.).
43/// The raw `address` is always preserved.
44#[derive(Debug, Clone)]
45pub struct SymbolicatedFrame {
46    /// Original raw return address from the capture path.
47    pub address: u64,
48    /// Demangled Rust function name, if resolvable.
49    pub function: Option<String>,
50    /// Source file path, if resolvable.
51    pub file: Option<PathBuf>,
52    /// Source line number, if resolvable.
53    pub line: Option<u32>,
54    /// True if this frame represents an inlined call site that
55    /// expanded from the same return address as a previous frame
56    /// in the parent `SymbolicatedCallSite.frames` vector.
57    pub inlined: bool,
58}
59
60/// One symbolicated call site (counterpart of
61/// [`CallSiteStats`](crate::CallSiteStats)).
62///
63/// Contains the aggregated counters from the raw report plus a
64/// vector of resolved frames in top-of-stack-first order.
65#[derive(Debug, Clone)]
66pub struct SymbolicatedCallSite {
67    /// Allocations attributed to this site.
68    pub count: u64,
69    /// Total bytes allocated at this site.
70    pub total_bytes: u64,
71    /// Resolved frames, top of stack first. May contain frames
72    /// with `inlined = true` representing inlined call sites
73    /// expanded from a single physical return address.
74    pub frames: Vec<SymbolicatedFrame>,
75}
76
77pub use report::symbolicated_report;