Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any standard methodology for debugging a stack overflow in Rust?

Getting a backtrace would be nice.

$ cargo test
    Running target/debug/partition_ops-b31bcf7b82e2e8d5

running 1 test

thread 'create_small' has overflowed its stack
Process didn't exit successfully: `/home/dhardy/other/pippin/target/debug/partition_ops-b31bcf7b82e2e8d5` (signal: 11)

To learn more, run the command again with --verbose.
like image 681
dhardy Avatar asked Mar 16 '16 16:03

dhardy


2 Answers

The simple answer is to use GDB:

$ gdb --args target/debug/partition_ops-b31bcf7b82e2e8d5
...
(gdb) run
Starting program: /home/dhardy/other/pippin/target/debug/partition_ops-b31bcf7b82e2e8d5 
Missing separate debuginfos, use: dnf debuginfo-install glibc-2.22-7.fc23.x86_64
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib64/libthread_db.so.1".

running 1 test
[New Thread 0x7ffff67ff700 (LWP 30769)]
[New Thread 0x7ffff5fff700 (LWP 30770)]

Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0x7ffff5fff700 (LWP 30770)]
0x00005555555f8a96 in pippin::detail::elt::PartId::from_num (n=1099511627775) at src/detail/elt.rs:36
36              assert!(n > 0 && n <= Self::max().into_num(), "PartId::from_num(n): n is invalid");
Missing separate debuginfos, use: dnf debuginfo-install libgcc-5.3.1-2.fc23.x86_64
(gdb) bt
#0  0x00005555555f8a96 in pippin::detail::elt::PartId::from_num (n=1099511627775) at src/detail/elt.rs:36
#1  0x00005555555f8b57 in pippin::detail::elt::PartId::max () at src/detail/elt.rs:56
#2  0x00005555555f8ab3 in pippin::detail::elt::PartId::from_num (n=1099511627775) at src/detail/elt.rs:36
#3  0x00005555555f8b57 in pippin::detail::elt::PartId::max () at src/detail/elt.rs:56
...
like image 129
dhardy Avatar answered Oct 22 '22 22:10

dhardy


Using LLDB:

$ rust-lldb -- target/debug/partition_ops-b31bcf7b82e2e8d5  # append test args here
...
(lldb) run
...
(lldb) bt
like image 28
robinst Avatar answered Oct 22 '22 22:10

robinst