edlang/backtrace/index.html
2024-02-13 06:38:44 +00:00

90 lines
12 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta name="generator" content="rustdoc"><meta name="description" content="A library for acquiring a backtrace at runtime"><title>backtrace - Rust</title><link rel="preload" as="font" type="font/woff2" crossorigin href="../static.files/SourceSerif4-Regular-46f98efaafac5295.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../static.files/FiraSans-Regular-018c141bf0843ffd.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../static.files/FiraSans-Medium-8f9a781e4970d388.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../static.files/SourceCodePro-Regular-562dcc5011b6de7d.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../static.files/SourceCodePro-Semibold-d899c5a5c4aeb14a.ttf.woff2"><link rel="stylesheet" href="../static.files/normalize-76eba96aa4d2e634.css"><link rel="stylesheet" href="../static.files/rustdoc-ac92e1bbe349e143.css"><meta name="rustdoc-vars" data-root-path="../" data-static-root-path="../static.files/" data-current-crate="backtrace" data-themes="" data-resource-suffix="" data-rustdoc-version="1.76.0 (07dca489a 2024-02-04)" data-channel="1.76.0" data-search-js="search-2b6ce74ff89ae146.js" data-settings-js="settings-4313503d2e1961c2.js" ><script src="../static.files/storage-f2adc0d6ca4d09fb.js"></script><script defer src="../crates.js"></script><script defer src="../static.files/main-305769736d49e732.js"></script><noscript><link rel="stylesheet" href="../static.files/noscript-feafe1bb7466e4bd.css"></noscript><link rel="alternate icon" type="image/png" href="../static.files/favicon-16x16-8b506e7a72182f1c.png"><link rel="alternate icon" type="image/png" href="../static.files/favicon-32x32-422f7d1d52889060.png"><link rel="icon" type="image/svg+xml" href="../static.files/favicon-2c020d218678b618.svg"></head><body class="rustdoc mod crate"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="mobile-topbar"><button class="sidebar-menu-toggle">&#9776;</button></nav><nav class="sidebar"><div class="sidebar-crate"><h2><a href="../backtrace/index.html">backtrace</a><span class="version">0.3.69</span></h2></div><div class="sidebar-elems"><ul class="block">
<li><a id="all-types" href="all.html">All Items</a></li></ul><section><ul class="block"><li><a href="#structs">Structs</a></li><li><a href="#enums">Enums</a></li><li><a href="#functions">Functions</a></li></ul></section></div></nav><div class="sidebar-resizer"></div>
<main><div class="width-limiter"><nav class="sub"><form class="search-form"><span></span><div id="sidebar-button" tabindex="-1"><a href="../backtrace/all.html" title="show sidebar"></a></div><input class="search-input" name="search" aria-label="Run search in the documentation" autocomplete="off" spellcheck="false" placeholder="Click or press S to search, ? for more options…" type="search"><div id="help-button" tabindex="-1"><a href="../help.html" title="help">?</a></div><div id="settings-menu" tabindex="-1"><a href="../settings.html" title="settings"><img width="22" height="22" alt="Change settings" src="../static.files/wheel-7b819b6101059cd0.svg"></a></div></form></nav><section id="main-content" class="content"><div class="main-heading"><h1>Crate <a class="mod" href="#">backtrace</a><button id="copy-path" title="Copy item path to clipboard"><img src="../static.files/clipboard-7571035ce49a181d.svg" width="19" height="18" alt="Copy item path"></button></h1><span class="out-of-band"><a class="src" href="../src/backtrace/lib.rs.html#1-192">source</a> · <button id="toggle-all-docs" title="collapse all docs">[<span>&#x2212;</span>]</button></span></div><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>A library for acquiring a backtrace at runtime</p>
<p>This library is meant to supplement the <code>RUST_BACKTRACE=1</code> support of the
standard library by allowing an acquisition of a backtrace at runtime
programmatically. The backtraces generated by this library do not need to be
parsed, for example, and expose the functionality of multiple backend
implementations.</p>
<h2 id="usage"><a href="#usage">Usage</a></h2>
<p>First, add this to your Cargo.toml</p>
<div class="example-wrap"><pre class="language-toml"><code>[dependencies]
backtrace = &quot;0.3&quot;
</code></pre></div>
<p>Next:</p>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">fn </span>main() {
backtrace::trace(|frame| {
<span class="kw">let </span>ip = frame.ip();
<span class="kw">let </span>symbol_address = frame.symbol_address();
<span class="comment">// Resolve this instruction pointer to a symbol name
</span>backtrace::resolve_frame(frame, |symbol| {
<span class="kw">if let </span><span class="prelude-val">Some</span>(name) = symbol.name() {
<span class="comment">// ...
</span>}
<span class="kw">if let </span><span class="prelude-val">Some</span>(filename) = symbol.filename() {
<span class="comment">// ...
</span>}
});
<span class="bool-val">true </span><span class="comment">// keep going to the next frame
</span>});
}</code></pre></div>
<h2 id="backtrace-accuracy"><a href="#backtrace-accuracy">Backtrace accuracy</a></h2>
<p>This crate implements best-effort attempts to get the native backtrace. This
is not always guaranteed to work, and some platforms dont return any
backtrace at all. If your application requires accurate backtraces then its
recommended to closely evaluate this crate to see whether its suitable
for your use case on your target platforms.</p>
<p>Even on supported platforms, theres a number of reasons that backtraces may
be less-than-accurate, including but not limited to:</p>
<ul>
<li>
<p>Unwind information may not be available. This crate primarily implements
backtraces by unwinding the stack, but not all functions may have
unwinding information (e.g. DWARF unwinding information).</p>
</li>
<li>
<p>Rust code may be compiled without unwinding information for some
functions. This can also happen for Rust code compiled with
<code>-Cpanic=abort</code>. You can remedy this, however, with
<code>-Cforce-unwind-tables</code> as a compiler option.</p>
</li>
<li>
<p>Unwind information may be inaccurate or corrupt. In the worst case
inaccurate unwind information can lead this library to segfault. In the
best case inaccurate information will result in a truncated stack trace.</p>
</li>
<li>
<p>Backtraces may not report filenames/line numbers correctly due to missing
or corrupt debug information. This wont lead to segfaults unlike corrupt
unwinding information, but missing or malformed debug information will
mean that filenames and line numbers will not be available. This may be
because debug information wasnt generated by the compiler, or its just
missing on the filesystem.</p>
</li>
<li>
<p>Not all platforms are supported. For example theres no way to get a
backtrace on WebAssembly at the moment.</p>
</li>
<li>
<p>Crate features may be disabled. Currently this crate supports using Gimli
libbacktrace on non-Windows platforms for reading debuginfo for
backtraces. If both crate features are disabled, however, then these
platforms will generate a backtrace but be unable to generate symbols for
it.</p>
</li>
</ul>
<p>In most standard workflows for most standard platforms you generally dont
need to worry about these caveats. Well try to fix ones where we can over
time, but otherwise its important to be aware of the limitations of
unwinding-based backtraces!</p>
</div></details><h2 id="structs" class="section-header"><a href="#structs">Structs</a></h2><ul class="item-table"><li><div class="item-name"><a class="struct" href="struct.Backtrace.html" title="struct backtrace::Backtrace">Backtrace</a></div><div class="desc docblock-short">Representation of an owned and self-contained backtrace.</div></li><li><div class="item-name"><a class="struct" href="struct.BacktraceFmt.html" title="struct backtrace::BacktraceFmt">BacktraceFmt</a></div><div class="desc docblock-short">A formatter for backtraces.</div></li><li><div class="item-name"><a class="struct" href="struct.BacktraceFrame.html" title="struct backtrace::BacktraceFrame">BacktraceFrame</a></div><div class="desc docblock-short">Captured version of a frame in a backtrace.</div></li><li><div class="item-name"><a class="struct" href="struct.BacktraceFrameFmt.html" title="struct backtrace::BacktraceFrameFmt">BacktraceFrameFmt</a></div><div class="desc docblock-short">A formatter for just one frame of a backtrace.</div></li><li><div class="item-name"><a class="struct" href="struct.BacktraceSymbol.html" title="struct backtrace::BacktraceSymbol">BacktraceSymbol</a></div><div class="desc docblock-short">Captured version of a symbol in a backtrace.</div></li><li><div class="item-name"><a class="struct" href="struct.Frame.html" title="struct backtrace::Frame">Frame</a></div><div class="desc docblock-short">A trait representing one frame of a backtrace, yielded to the <code>trace</code>
function of this crate.</div></li><li><div class="item-name"><a class="struct" href="struct.Symbol.html" title="struct backtrace::Symbol">Symbol</a></div><div class="desc docblock-short">A trait representing the resolution of a symbol in a file.</div></li><li><div class="item-name"><a class="struct" href="struct.SymbolName.html" title="struct backtrace::SymbolName">SymbolName</a></div><div class="desc docblock-short">A wrapper around a symbol name to provide ergonomic accessors to the
demangled name, the raw bytes, the raw string, etc.</div></li></ul><h2 id="enums" class="section-header"><a href="#enums">Enums</a></h2><ul class="item-table"><li><div class="item-name"><a class="enum" href="enum.BytesOrWideString.html" title="enum backtrace::BytesOrWideString">BytesOrWideString</a></div><div class="desc docblock-short">A platform independent representation of a string. When working with <code>std</code>
enabled it is recommended to the convenience methods for providing
conversions to <code>std</code> types.</div></li><li><div class="item-name"><a class="enum" href="enum.PrintFmt.html" title="enum backtrace::PrintFmt">PrintFmt</a></div><div class="desc docblock-short">The styles of printing that we can print</div></li></ul><h2 id="functions" class="section-header"><a href="#functions">Functions</a></h2><ul class="item-table"><li><div class="item-name"><a class="fn" href="fn.clear_symbol_cache.html" title="fn backtrace::clear_symbol_cache">clear_symbol_cache</a></div><div class="desc docblock-short">Attempt to reclaim that cached memory used to symbolicate addresses.</div></li><li><div class="item-name"><a class="fn" href="fn.resolve.html" title="fn backtrace::resolve">resolve</a></div><div class="desc docblock-short">Resolve an address to a symbol, passing the symbol to the specified
closure.</div></li><li><div class="item-name"><a class="fn" href="fn.resolve_frame.html" title="fn backtrace::resolve_frame">resolve_frame</a></div><div class="desc docblock-short">Resolve a previously capture frame to a symbol, passing the symbol to the
specified closure.</div></li><li><div class="item-name"><a class="fn" href="fn.resolve_frame_unsynchronized.html" title="fn backtrace::resolve_frame_unsynchronized">resolve_frame_unsynchronized</a><sup title="unsafe function"></sup></div><div class="desc docblock-short">Same as <code>resolve_frame</code>, only unsafe as its unsynchronized.</div></li><li><div class="item-name"><a class="fn" href="fn.resolve_unsynchronized.html" title="fn backtrace::resolve_unsynchronized">resolve_unsynchronized</a><sup title="unsafe function"></sup></div><div class="desc docblock-short">Same as <code>resolve</code>, only unsafe as its unsynchronized.</div></li><li><div class="item-name"><a class="fn" href="fn.trace.html" title="fn backtrace::trace">trace</a></div><div class="desc docblock-short">Inspects the current call-stack, passing all active frames into the closure
provided to calculate a stack trace.</div></li><li><div class="item-name"><a class="fn" href="fn.trace_unsynchronized.html" title="fn backtrace::trace_unsynchronized">trace_unsynchronized</a><sup title="unsafe function"></sup></div><div class="desc docblock-short">Same as <code>trace</code>, only unsafe as its unsynchronized.</div></li></ul></section></div></main></body></html>