blob: 712204997c775053e0daff4e11cf530fc242b548 [file] [log] [blame]
<html lang="en">
<head>
<title>Rust - Debugging with GDB</title>
<meta http-equiv="Content-Type" content="text/html">
<meta name="description" content="Debugging with GDB">
<meta name="generator" content="makeinfo 4.13">
<link title="Top" rel="start" href="index.html#Top">
<link rel="up" href="Supported-Languages.html#Supported-Languages" title="Supported Languages">
<link rel="prev" href="Pascal.html#Pascal" title="Pascal">
<link rel="next" href="Modula_002d2.html#Modula_002d2" title="Modula-2">
<link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage">
<!--
Copyright (C) 1988-2019 Free Software Foundation, Inc.
Permission is granted to copy, distribute and/or modify this document
under the terms of the GNU Free Documentation License, Version 1.3 or
any later version published by the Free Software Foundation; with the
Invariant Sections being ``Free Software'' and ``Free Software Needs
Free Documentation'', with the Front-Cover Texts being ``A GNU Manual,''
and with the Back-Cover Texts as in (a) below.
(a) The FSF's Back-Cover Text is: ``You are free to copy and modify
this GNU Manual. Buying copies from GNU Press supports the FSF in
developing GNU and promoting software freedom.''
-->
<meta http-equiv="Content-Style-Type" content="text/css">
<style type="text/css"><!--
pre.display { font-family:inherit }
pre.format { font-family:inherit }
pre.smalldisplay { font-family:inherit; font-size:smaller }
pre.smallformat { font-family:inherit; font-size:smaller }
pre.smallexample { font-size:smaller }
pre.smalllisp { font-size:smaller }
span.sc { font-variant:small-caps }
span.roman { font-family:serif; font-weight:normal; }
span.sansserif { font-family:sans-serif; font-weight:normal; }
--></style>
</head>
<body>
<div class="node">
<a name="Rust"></a>
<p>
Next:&nbsp;<a rel="next" accesskey="n" href="Modula_002d2.html#Modula_002d2">Modula-2</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="Pascal.html#Pascal">Pascal</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="Supported-Languages.html#Supported-Languages">Supported Languages</a>
<hr>
</div>
<h4 class="subsection">15.4.8 Rust</h4>
<p><span class="sc">gdb</span> supports the <a href="https://www.rust-lang.org/">Rust Programming Language</a>. Type- and value-printing, and expression
parsing, are reasonably complete. However, there are a few
peculiarities and holes to be aware of.
<ul>
<li>Linespecs (see <a href="Specify-Location.html#Specify-Location">Specify Location</a>) are never relative to the current
crate. Instead, they act as if there were a global namespace of
crates, somewhat similar to the way <code>extern crate</code> behaves.
<p>That is, if <span class="sc">gdb</span> is stopped at a breakpoint in a function in
crate &lsquo;<samp><span class="samp">A</span></samp>&rsquo;, module &lsquo;<samp><span class="samp">B</span></samp>&rsquo;, then <code>break B::f</code> will attempt
to set a breakpoint in a function named &lsquo;<samp><span class="samp">f</span></samp>&rsquo; in a crate named
&lsquo;<samp><span class="samp">B</span></samp>&rsquo;.
<p>As a consequence of this approach, linespecs also cannot refer to
items using &lsquo;<samp><span class="samp">self::</span></samp>&rsquo; or &lsquo;<samp><span class="samp">super::</span></samp>&rsquo;.
<li>Because <span class="sc">gdb</span> implements Rust name-lookup semantics in
expressions, it will sometimes prepend the current crate to a name.
For example, if <span class="sc">gdb</span> is stopped at a breakpoint in the crate
&lsquo;<samp><span class="samp">K</span></samp>&rsquo;, then <code>print ::x::y</code> will try to find the symbol
&lsquo;<samp><span class="samp">K::x::y</span></samp>&rsquo;.
<p>However, since it is useful to be able to refer to other crates when
debugging, <span class="sc">gdb</span> provides the <code>extern</code> extension to
circumvent this. To use the extension, just put <code>extern</code> before
a path expression to refer to the otherwise unavailable &ldquo;global&rdquo;
scope.
<p>In the above example, if you wanted to refer to the symbol &lsquo;<samp><span class="samp">y</span></samp>&rsquo; in
the crate &lsquo;<samp><span class="samp">x</span></samp>&rsquo;, you would use <code>print extern x::y</code>.
<li>The Rust expression evaluator does not support &ldquo;statement-like&rdquo;
expressions such as <code>if</code> or <code>match</code>, or lambda expressions.
<li>Tuple expressions are not implemented.
<li>The Rust expression evaluator does not currently implement the
<code>Drop</code> trait. Objects that may be created by the evaluator will
never be destroyed.
<li><span class="sc">gdb</span> does not implement type inference for generics. In order
to call generic functions or otherwise refer to generic items, you
will have to specify the type parameters manually.
<li><span class="sc">gdb</span> currently uses the C<tt>++</tt> demangler for Rust. In most
cases this does not cause any problems. However, in an expression
context, completing a generic function name will give syntactically
invalid results. This happens because Rust requires the &lsquo;<samp><span class="samp">::</span></samp>&rsquo;
operator between the function name and its generic arguments. For
example, <span class="sc">gdb</span> might provide a completion like
<code>crate::f&lt;u32&gt;</code>, where the parser would require
<code>crate::f::&lt;u32&gt;</code>.
<li>As of this writing, the Rust compiler (version 1.8) has a few holes in
the debugging information it generates. These holes prevent certain
features from being implemented by <span class="sc">gdb</span>:
<ul>
<li>Method calls cannot be made via traits.
<li>Operator overloading is not implemented.
<li>When debugging in a monomorphized function, you cannot use the generic
type names.
<li>The type <code>Self</code> is not available.
<li><code>use</code> statements are not available, so some names may not be
available in the crate.
</ul>
</ul>
</body></html>