Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cargo build --benches missing debug symbols #6301

Closed
genbattle opened this issue Nov 11, 2018 · 1 comment · Fixed by #6309
Closed

cargo build --benches missing debug symbols #6301

genbattle opened this issue Nov 11, 2018 · 1 comment · Fixed by #6309

Comments

@genbattle
Copy link

genbattle commented Nov 11, 2018

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.

  1. Compile a benchmark with cargo build --benches or cargo build --bench
  2. 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.

@ehuss
Copy link
Contributor

ehuss commented Nov 11, 2018

Yea, it's a bit confusing because build --bench builds with the "bench" profile (which does not have debug) but places it in the "debug" directory. There are a few issues related to this: #4240, #5575, #4929.

I think the best course is to have build --bench xxx use the "test" profile, and build --bench xxx --release to use the "bench" profile.

As a temporary workaround, you can edit [profile.bench] in your Cargo.toml to enable debug, and possibly lower opt-level.

I'll try to fix this soon.

bors added a commit that referenced this issue Nov 14, 2018
Use "test" profile for `cargo build` benchmarks.

When using `cargo build` (without `--release`), build benchmarks using the "test" profile. This was causing some confusion where the benchmark is placed in the `target/debug` directory, and also causing some duplicates that may not be expected. It also makes it easier to debug benchmarks (previously you had to edit the `[profile.bench]` profile).

Closes #5575, closes #6301, closes #4240, closes #4929.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants