Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Debugging Rust with gdb

I'm aware of the debugging Rust questions here on StackOverflow and I also used gdb before with Go. However, I'm running into a problem where it seems gdb is unable to locate the debug symbols.

Consider this complex program in main.rs?

pub fn main () {
    println!("run");
}

I compile it with debug symbols

rustc -g main.rs

Then I run gdb

gdb main

This gives the first clue that something with the loading of debug symbols is not quite right.

enter image description here

Now when I'm in gdb and type

list

it leaves me with some C code which isn't what I expect.

enter image description here

What am I doing wrong? My gdb version is 7.7 and I'm on OS X 10.9.2 (13C64). My rustc version is rustc 0.11.0-pre (3035d8dfb13077e195eb056568183911c90c1b4b 2014-07-02 21:26:40 +0000)

It may also be helpful to see the output of `gdb --configuration``

$ gdb --configuration
This GDB was configured as follows:
   configure --host=x86_64-apple-darwin13.1.0 --target=x86_64-apple-darwin13.1.0
             --with-auto-load-dir=:${prefix}/share/auto-load
             --with-auto-load-safe-path=:${prefix}/share/auto-load
             --with-expat
             --with-gdb-datadir=/usr/local/share/gdb (relocatable)
             --with-jit-reader-dir=/usr/local/lib/gdb (relocatable)
             --without-libunwind-ia64
             --without-lzma
             --with-python=/System/Library/Frameworks/Python.framework/Versions/2.7
             --with-separate-debug-dir=/usr/local/lib/debug (relocatable)
             --with-zlib
             --without-babeltrace
like image 871
Christoph Avatar asked Jul 09 '14 23:07

Christoph


People also ask

Can you use GDB with Rust?

GDB has support for several languages, such as C/C++, but also modern languages such as Go and Rust.

Does Rust have a debugger?

Debugging for Rust is available in CLion, IntelliJ IDEA Ultimate, PyCharm Professional, and GoLand.

Can GDB debug assembly?

gdb will work in an ordinary terminal window, and this is fine for debugging assembly code. For use with higher-level source code, it is more convenient to use gdb from within the emacs editor (a good one to learn!) or using a graphical front-end like xxgdb or /pkgs/gnu/bin/ddd. The basic commands remain the same.


1 Answers

Same question, later Rust version (1.0.0-beta), totally different answer:

In GDB, when debugging a Rust executable, break main sets a breakpoint in some setup code that is part of the Rust standard library. This isn't what you want.

Instead type: break $YOUR_CRATE::main, substituting the name of your program for $YOUR_CRATE.

like image 111
Jason Orendorff Avatar answered Oct 21 '22 10:10

Jason Orendorff