index.html 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <meta name="generator" content="rustdoc">
  7. <meta name="description" content="API documentation for the Rust `backtrace` crate.">
  8. <meta name="keywords" content="rust, rustlang, rust-lang, backtrace">
  9. <title>backtrace - Rust</title>
  10. <link rel="stylesheet" type="text/css" href="../normalize.css">
  11. <link rel="stylesheet" type="text/css" href="../rustdoc.css" id="mainThemeStyle">
  12. <link rel="stylesheet" type="text/css" href="../dark.css">
  13. <link rel="stylesheet" type="text/css" href="../main.css" id="themeStyle">
  14. <script src="../storage.js"></script>
  15. </head>
  16. <body class="rustdoc mod">
  17. <!--[if lte IE 8]>
  18. <div class="warning">
  19. This old browser is unsupported and will most likely display funky
  20. things.
  21. </div>
  22. <![endif]-->
  23. <nav class="sidebar">
  24. <div class="sidebar-menu">&#9776;</div>
  25. <p class='location'>Crate backtrace</p><div class="sidebar-elems"><div class="block items"><ul><li><a href="#structs">Structs</a></li><li><a href="#functions">Functions</a></li></ul></div><p class='location'></p><script>window.sidebarCurrent = {name: 'backtrace', ty: 'mod', relpath: '../'};</script></div>
  26. </nav>
  27. <div class="theme-picker">
  28. <button id="theme-picker" aria-label="Pick another theme!">
  29. <img src="../brush.svg" width="18" alt="Pick another theme!">
  30. </button>
  31. <div id="theme-choices"></div>
  32. </div>
  33. <script src="../theme.js"></script>
  34. <nav class="sub">
  35. <form class="search-form js-only">
  36. <div class="search-container">
  37. <input class="search-input" name="search"
  38. autocomplete="off"
  39. placeholder="Click or press ‘S’ to search, ‘?’ for more options…"
  40. type="search">
  41. </div>
  42. </form>
  43. </nav>
  44. <section id='main' class="content">
  45. <h1 class='fqn'><span class='in-band'>Crate <a class="mod" href=''>backtrace</a></span><span class='out-of-band'><span id='render-detail'>
  46. <a id="toggle-all-docs" href="javascript:void(0)" title="collapse all docs">
  47. [<span class='inner'>&#x2212;</span>]
  48. </a>
  49. </span><a class='srclink' href='../src/backtrace/lib.rs.html#1-177' title='goto source code'>[src]</a></span></h1>
  50. <div class='docblock'><p>A library for acquiring a backtrace at runtime</p>
  51. <p>This library is meant to supplement the <code>RUST_BACKTRACE=1</code> support of the
  52. standard library by allowing an acquisition of a backtrace at runtime
  53. programmatically. The backtraces generated by this library do not need to be
  54. parsed, for example, and expose the functionality of multiple backend
  55. implementations.</p>
  56. <h1 id="implementation" class="section-header"><a href="#implementation">Implementation</a></h1>
  57. <p>This library makes use of a number of strategies for actually acquiring a
  58. backtrace. For example unix uses libgcc's libunwind bindings by default to
  59. acquire a backtrace, but coresymbolication or dladdr is used on OSX to
  60. acquire symbol names while linux uses gcc's libbacktrace.</p>
  61. <p>When using the default feature set of this library the &quot;most reasonable&quot; set
  62. of defaults is chosen for the current platform, but the features activated
  63. can also be controlled at a finer granularity.</p>
  64. <h1 id="platform-support" class="section-header"><a href="#platform-support">Platform Support</a></h1>
  65. <p>Currently this library is verified to work on Linux, OSX, and Windows, but
  66. it may work on other platforms as well. Note that the quality of the
  67. backtrace may vary across platforms.</p>
  68. <h1 id="api-principles" class="section-header"><a href="#api-principles">API Principles</a></h1>
  69. <p>This library attempts to be as flexible as possible to accommodate different
  70. backend implementations of acquiring a backtrace. Consequently the currently
  71. exported functions are closure-based as opposed to the likely expected
  72. iterator-based versions. This is done due to limitations of the underlying
  73. APIs used from the system.</p>
  74. <h1 id="usage" class="section-header"><a href="#usage">Usage</a></h1>
  75. <p>First, add this to your Cargo.toml</p>
  76. <pre><code class="language-toml">[dependencies]
  77. backtrace = &quot;0.2&quot;
  78. </code></pre>
  79. <p>Next:</p>
  80. <pre class="rust rust-example-rendered">
  81. <span class="kw">extern</span> <span class="kw">crate</span> <span class="ident">backtrace</span>;
  82. <span class="kw">fn</span> <span class="ident">main</span>() {
  83. <span class="ident">backtrace</span>::<span class="ident">trace</span>(<span class="op">|</span><span class="ident">frame</span><span class="op">|</span> {
  84. <span class="kw">let</span> <span class="ident">ip</span> <span class="op">=</span> <span class="ident">frame</span>.<span class="ident">ip</span>();
  85. <span class="kw">let</span> <span class="ident">symbol_address</span> <span class="op">=</span> <span class="ident">frame</span>.<span class="ident">symbol_address</span>();
  86. <span class="comment">// Resolve this instruction pointer to a symbol name</span>
  87. <span class="ident">backtrace</span>::<span class="ident">resolve</span>(<span class="ident">ip</span>, <span class="op">|</span><span class="ident">symbol</span><span class="op">|</span> {
  88. <span class="kw">if</span> <span class="kw">let</span> <span class="prelude-val">Some</span>(<span class="ident">name</span>) <span class="op">=</span> <span class="ident">symbol</span>.<span class="ident">name</span>() {
  89. <span class="comment">// ...</span>
  90. }
  91. <span class="kw">if</span> <span class="kw">let</span> <span class="prelude-val">Some</span>(<span class="ident">filename</span>) <span class="op">=</span> <span class="ident">symbol</span>.<span class="ident">filename</span>() {
  92. <span class="comment">// ...</span>
  93. }
  94. });
  95. <span class="bool-val">true</span> <span class="comment">// keep going to the next frame</span>
  96. });
  97. }</pre>
  98. </div><h2 id='structs' class='section-header'><a href="#structs">Structs</a></h2>
  99. <table>
  100. <tr class=' module-item'>
  101. <td><a class="struct" href="struct.Backtrace.html"
  102. title='struct backtrace::Backtrace'>Backtrace</a></td>
  103. <td class='docblock-short'>
  104. <p>Representation of an owned and self-contained backtrace.</p>
  105. </td>
  106. </tr>
  107. <tr class=' module-item'>
  108. <td><a class="struct" href="struct.BacktraceFrame.html"
  109. title='struct backtrace::BacktraceFrame'>BacktraceFrame</a></td>
  110. <td class='docblock-short'>
  111. <p>Captured version of a frame in a backtrace.</p>
  112. </td>
  113. </tr>
  114. <tr class=' module-item'>
  115. <td><a class="struct" href="struct.BacktraceSymbol.html"
  116. title='struct backtrace::BacktraceSymbol'>BacktraceSymbol</a></td>
  117. <td class='docblock-short'>
  118. <p>Captured version of a symbol in a backtrace.</p>
  119. </td>
  120. </tr>
  121. <tr class=' module-item'>
  122. <td><a class="struct" href="struct.Frame.html"
  123. title='struct backtrace::Frame'>Frame</a></td>
  124. <td class='docblock-short'>
  125. <p>A trait representing one frame of a backtrace, yielded to the <code>trace</code>
  126. function of this crate.</p>
  127. </td>
  128. </tr>
  129. <tr class=' module-item'>
  130. <td><a class="struct" href="struct.Symbol.html"
  131. title='struct backtrace::Symbol'>Symbol</a></td>
  132. <td class='docblock-short'>
  133. <p>A trait representing the resolution of a symbol in a file.</p>
  134. </td>
  135. </tr>
  136. <tr class=' module-item'>
  137. <td><a class="struct" href="struct.SymbolName.html"
  138. title='struct backtrace::SymbolName'>SymbolName</a></td>
  139. <td class='docblock-short'>
  140. <p>A wrapper around a symbol name to provide ergonomic accessors to the
  141. demangled name, the raw bytes, the raw string, etc.</p>
  142. </td>
  143. </tr></table><h2 id='functions' class='section-header'><a href="#functions">Functions</a></h2>
  144. <table>
  145. <tr class=' module-item'>
  146. <td><a class="fn" href="fn.resolve.html"
  147. title='fn backtrace::resolve'>resolve</a></td>
  148. <td class='docblock-short'>
  149. <p>Resolve an address to a symbol, passing the symbol to the specified
  150. closure.</p>
  151. </td>
  152. </tr>
  153. <tr class=' module-item'>
  154. <td><a class="fn" href="fn.trace.html"
  155. title='fn backtrace::trace'>trace</a></td>
  156. <td class='docblock-short'>
  157. <p>Inspects the current call-stack, passing all active frames into the closure
  158. provided to calculate a stack trace.</p>
  159. </td>
  160. </tr></table></section>
  161. <section id='search' class="content hidden"></section>
  162. <section class="footer"></section>
  163. <aside id="help" class="hidden">
  164. <div>
  165. <h1 class="hidden">Help</h1>
  166. <div class="shortcuts">
  167. <h2>Keyboard Shortcuts</h2>
  168. <dl>
  169. <dt><kbd>?</kbd></dt>
  170. <dd>Show this help dialog</dd>
  171. <dt><kbd>S</kbd></dt>
  172. <dd>Focus the search field</dd>
  173. <dt><kbd>↑</kbd></dt>
  174. <dd>Move up in search results</dd>
  175. <dt><kbd>↓</kbd></dt>
  176. <dd>Move down in search results</dd>
  177. <dt><kbd>↹</kbd></dt>
  178. <dd>Switch tab</dd>
  179. <dt><kbd>&#9166;</kbd></dt>
  180. <dd>Go to active search result</dd>
  181. <dt><kbd>+</kbd></dt>
  182. <dd>Expand all sections</dd>
  183. <dt><kbd>-</kbd></dt>
  184. <dd>Collapse all sections</dd>
  185. </dl>
  186. </div>
  187. <div class="infos">
  188. <h2>Search Tricks</h2>
  189. <p>
  190. Prefix searches with a type followed by a colon (e.g.
  191. <code>fn:</code>) to restrict the search to a given type.
  192. </p>
  193. <p>
  194. Accepted types are: <code>fn</code>, <code>mod</code>,
  195. <code>struct</code>, <code>enum</code>,
  196. <code>trait</code>, <code>type</code>, <code>macro</code>,
  197. and <code>const</code>.
  198. </p>
  199. <p>
  200. Search functions by type signature (e.g.
  201. <code>vec -> usize</code> or <code>* -> vec</code>)
  202. </p>
  203. </div>
  204. </div>
  205. </aside>
  206. <script>
  207. window.rootPath = "../";
  208. window.currentCrate = "backtrace";
  209. </script>
  210. <script src="../main.js"></script>
  211. <script defer src="../search-index.js"></script>
  212. </body>
  213. </html>