-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Description
Problem
I recently added some additional benchmarks to my library including one that didn't converge. I built debug binaries with cargo build --benches, which outputs:
cargo build --benches
Compiling num-traits v0.2.6
Compiling version_check v0.1.5
Compiling num-integer v0.1.39
Compiling num-bigint v0.2.0
Compiling num-iter v0.1.37
Compiling libc v0.2.43
Compiling cfg-if v0.1.6
Compiling serde v1.0.80
Compiling num-rational v0.2.1
Compiling num-complex v0.2.1
Compiling matrixmultiply v0.1.15
Compiling rawpointer v0.1.0
Compiling rand_core v0.3.0
Compiling ndarray v0.12.0
Compiling either v1.5.0
Compiling bencher v0.1.5
Compiling memchr v2.1.0
Compiling itertools v0.7.8
Compiling rand_core v0.2.2
Compiling rand v0.5.5
Compiling csv-core v0.1.4
Compiling csv v1.0.2
Compiling num v0.2.0
Compiling rkm v0.3.0 (/home/nick/Projects/rkm)
Finished dev [unoptimized + debuginfo] target(s) in 45.92s
However, when I run gdb target/debug/bench-12ca78b61d26ae10
and try to list
or bt
I find that the debug symbols for my benchmark code (the code I've written for benchmarks) seem to be missing or corrupted. A backtrace shows function names but no files or line numbers for my code, but it does information for some of the bencher library code. Using list
in a stack frame for my own code will give an error about not being able to find a libcore file instead.
(gdb) run
Starting program: rkm/target/debug/bench-12ca78b61d26ae10
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/usr/lib/libthread_db.so.1".
running 4 tests
test bench_birch3 ... ^C
Program received signal SIGINT, Interrupt.
0x000055555556df70 in core::ops::function::impls::<impl core::ops::function::FnOnce<A> for &'a mut F>::call_once ()
(gdb) bt
#0 0x000055555556df70 in core::ops::function::impls::<impl core::ops::function::FnOnce<A> for &'a mut F>::call_once ()
#1 0x000055555556b725 in <alloc::vec::Vec<T> as alloc::vec::SpecExtend<T, I>>::from_iter ()
#2 0x000055555556d183 in rkm::kmeans_lloyd ()
#3 0x0000555555568b68 in bencher::Bencher::iter ()
#4 0x000055555556a043 in bench::bench_birch3 ()
#5 0x0000555555577b40 in bencher::run_test::{{closure}} (
harness=0x7fffffffc390)
at /home/nick/.cargo/registry/src/github.com-1ecc6299db9ec823/bencher-0.1.5/lib.rs:571
#6 0x0000555555578f05 in bencher::Bencher::auto_bench::{{closure}} (
x=0x7fffffffc390)
at /home/nick/.cargo/registry/src/github.com-1ecc6299db9ec823/bencher-0.1.5/lib.rs:661
#7 0x0000555555577d5c in bencher::Bencher::bench_n (self=0x7fffffffc390, n=1,
f=...)
at /home/nick/.cargo/registry/src/github.com-1ecc6299db9ec823/bencher-0.1.5/lib.rs:628
#8 0x000055555557897b in bencher::Bencher::auto_bench (self=0x7fffffffc390,
f=...)
at /home/nick/.cargo/registry/src/github.com-1ecc6299db9ec823/bencher-0.1.5/lib.rs:661
---Type <return> to continue, or q <return> to quit---q
Quit
(gdb) frame 2
#2 0x000055555556d183 in rkm::kmeans_lloyd ()
(gdb) list
1 libcore/str/mod.rs: No such file or directory.
(gdb)
Steps
The code I'm trying to debug is in the NewBenchmarks
branch of my rkm repo, but my impression is that any benchmark code can be used to reproduce this.
- Compile a benchmark with
cargo build --benches
orcargo build --bench
- Debug the resulting binary under gdb/rust-gdb with
rust-gdb target/debug/bench-################
Possible Solution(s)
One way I've found (after a couple of days of being stumped) is to set RUSTFLAGS
to -C debuginfo=2
, e.g.
RUSTFLAGS="-C debuginfo=2" cargo build --benches
This produces binaries with the correct debug information.
Notes
Output of cargo version
:
cargo 1.30.0 (36d96825d 2018-10-24)
rustc version
:
rustc 1.30.0 (da5f414c2 2018-10-24)
Platform is Antergos Linux 4.17 x86_64
This seems to be related to #4240, but I thought I'd create a new bug since my issue is with a different cargo command.