Skip to content

suspect bug in emitting debug information #11600

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

Closed
alsam opened this issue Jan 16, 2014 · 11 comments · Fixed by #11846
Closed

suspect bug in emitting debug information #11600

alsam opened this issue Jan 16, 2014 · 11 comments · Fixed by #11846

Comments

@alsam
Copy link

alsam commented Jan 16, 2014

small snippet called arg0.rs:

fn main ()
{
    let args : ~[~str] = ::std::os::args();
    ::std::io::println(args[0]);
}
$ rustc -Z debug-info arg0.rs
$ gdb arg0 
GNU gdb (GDB) 7.6.1
Copyright (C) 2013 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-unknown-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from /home/asamoilov/work/projects/rust-sandbox/my-rust/arg0...done.
(gdb) l
1   arg0.rc: No such file or directory.
(gdb) quit

i.e. expects arg0.rc instead of arg0.rs

Thanks

@alexcrichton
Copy link
Member

cc @michaelwoerister

@jdm
Copy link
Contributor

jdm commented Jan 16, 2014

I expect this to come from CrateDebugContext::new, which is called by http://mxr.mozilla.org/rust/source/src/librustc/middle/trans/context.rs#168 .

@jdm
Copy link
Contributor

jdm commented Jan 16, 2014

http://mxr.mozilla.org/rust/source/src/librustc/middle/trans/base.rs#3376

3368 // Append ".rc" to crate name as LLVM module identifier.
3369 //
3370 // LLVM code generator emits a ".file filename" directive
3371 // for ELF backends. Value of the "filename" is set as the
3372 // LLVM module identifier. Due to a LLVM MC bug[1], LLVM
3373 // crashes if the module identifer is same as other symbols
3374 // such as a function name in the module.
3375 // 1. http://llvm.org/bugs/show_bug.cgi?id=11479
3376 let llmod_id = link_meta.crateid.name.clone() + ".rc";

@michaelwoerister
Copy link
Member

I just took a look at this. Replacing ".rc" with ".rs" in the code section quoted by @jdm fixes the problem for me.

@alsam
Copy link
Author

alsam commented Jan 18, 2014

Making a symbolic link say ln -s arg0.rs arg0.rc also fixes the problem, though this is weird.
Conducted a search for all ".rc" in source files:

find . -name '*.rs' | xargs egrep '\.rc\>'
./src/librustc/middle/trans/base.rs:    // Append ".rc" to crate name as LLVM module identifier.
./src/librustc/middle/trans/base.rs:    let llmod_id = link_meta.crateid.name.clone() + ".rc";
./src/compiletest/compiletest.rs:    // Pretty-printer does not work with .rc files yet
./src/compiletest/compiletest.rs:          _ => ~[~".rc", ~".rs"]
./src/test/run-pass/item-attributes.rs:// for completeness since .rs files linked from .rc files support this
./src/test/run-pass/issue_3136_b.rs:// aux-build:issue_3136_a.rc

@michaelwoerister
Copy link
Member

I think I tracked this down to a wrong DW_AT_name in the crate's DW_TAG_compile_unit entry. At the moment this is always the name of the crate's root source file. Instead it should be the path to the crate's root file relative to the DW_AT_comp_dir. I'll implement this now but it turns out to be a bit more complicated than expected because the path of the file in question is not stored anywhere. Just a minor complication though.

@alsam
Copy link
Author

alsam commented Jan 28, 2014

Great, thanks for fixing!
I'm confirming it really works

 gdb prog1 
GNU gdb (GDB) 7.6.1
...
Reading symbols from /home/asamoilov/work/projects/rust-sandbox/my-rust/prog1...done.
(gdb) l
1   // **********************************************
2   //prog1.rs <http://prog1.rs>
3   use std::rand::{task_rng, Rng};
4   fn main() {
5       let names = ["Alice", "Bob", "Carol"];
6       for name in names.iter() {
7           let v = task_rng().shuffle(~[1,2,3]);
8           for num in v.iter() {
9               println!("{:s} says: {:d}", *name, *num);
10          }

On a side note, can't print local variables:

(gdb) b 4
Breakpoint 1 at 0x406340: file prog1.rs, line 4.
(gdb) r
Starting program: /home/asamoilov/work/projects/rust-sandbox/my-rust/prog1 
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
[New Thread 0x7ffff7f66700 (LWP 8790)]
...
[Switching to Thread 0x7ffff7f66700 (LWP 8790)]

Breakpoint 1, prog1::main () at prog1.rs:4
4   fn main() {
(gdb) n
5       let names = ["Alice", "Bob", "Carol"];
(gdb) n
6       for name in names.iter() {
(gdb) p names
No symbol "names" in current context.
(gdb) info scope 4
Scope for 4 contains no locals or arguments.
(gdb) info scope main
Scope for main contains no locals or arguments.

@alsam
Copy link
Author

alsam commented Jan 28, 2014

Found this bug:
no debug-info on locals in stack frames when stepping though rust-msgpack
#9641

@alsam
Copy link
Author

alsam commented Jan 28, 2014

It works with -Z extra-debug-info

rustc -Z extra-debug-info prog1.rs 
asamoilov@atlant:~/work/projects/rust-sandbox/my-rust$ gdb prog1 
GNU gdb (GDB) 7.6.1
Copyright (C) 2013 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-unknown-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from /home/asamoilov/work/projects/rust-sandbox/my-rust/prog1...done.
(gdb) l
1   // **********************************************
2   //prog1.rs <http://prog1.rs>
3   use std::rand::{task_rng, Rng};
4   fn main() {
5       let names = ["Alice", "Bob", "Carol"];
6       for name in names.iter() {
7           let v = task_rng().shuffle(~[1,2,3]);
8           for num in v.iter() {
9               println!("{:s} says: {:d}", *name, *num);
10          }
(gdb) b 4
Breakpoint 1 at 0x406340: file prog1.rs, line 4.
(gdb) n
The program is not being run.
(gdb) r
Starting program: /home/asamoilov/work/projects/rust-sandbox/my-rust/prog1 
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
[New Thread 0x7ffff7f66700 (LWP 8881)]
[New Thread 0x7ffff6edf700 (LWP 8882)]
[New Thread 0x7fffeffff700 (LWP 8883)]
[New Thread 0x7ffff6dde700 (LWP 8884)]
[New Thread 0x7ffff6cdd700 (LWP 8885)]
[New Thread 0x7ffff6bdc700 (LWP 8886)]
[New Thread 0x7ffff6adb700 (LWP 8887)]
[New Thread 0x7ffff69da700 (LWP 8888)]
[Switching to Thread 0x7ffff7f66700 (LWP 8881)]

Breakpoint 1, prog1::main () at prog1.rs:4
4   fn main() {
(gdb) n
5       let names = ["Alice", "Bob", "Carol"];
(gdb) n
6       for name in names.iter() {
(gdb) p names
$1 = {{data_ptr = 0x52f5b0 <str1489> "Alice", length = 5}, {data_ptr = 0x52f5b6 <str1490> "Bob", length = 3}, {
    data_ptr = 0x52f5ba <str1491> "Carol", length = 5}}
(gdb) 

Sorry for the noise.

@michaelwoerister
Copy link
Member

@alsam I just wanted to ask you that :) With -Zdebug-info rustc will only produce line tables, but no information about types and variables. And don't worry about noise, better duplicate report than no report.

@alsam
Copy link
Author

alsam commented Jan 28, 2014

Great, thanks for clarification. It's much more useful with this extra debug info.

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.

4 participants