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

codegen-units ruins debug symbols #39160

Closed
jdm opened this issue Jan 18, 2017 · 15 comments
Closed

codegen-units ruins debug symbols #39160

jdm opened this issue Jan 18, 2017 · 15 comments
Labels
A-debuginfo Area: Debugging information in compiled programs (DWARF, PDB, etc.) A-incr-comp Area: Incremental compilation O-macos Operating system: macOS T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@jdm
Copy link
Contributor

jdm commented Jan 18, 2017

mod a {
    pub struct S;
    impl S {
        pub fn foo(&self) {
            println!("hi");
        }
    }
}

mod b {
    use a::S;
    pub struct T;
    impl T {
        pub fn bar(&self) {
            let s = S;
            s.foo();
        }
    }
}

fn main() {
    let t = b::T;
    t.bar();
}

With codegen-units=2, we get breakpoints in one module that work fine, and another that do not:

godot2:tmp jdm$ rustc -C codegen-units=2 foo.rs -g
godot2:tmp jdm$ lldb foo
(lldb) target create "foo"
Current executable set to 'foo' (x86_64).
(lldb) b foo.rs:5
Breakpoint 1: where = foo`foo::a::{{impl}}::foo + 36 at foo.rs:5, address = 0x00000001000009a4
(lldb) b foo.rs:15
Breakpoint 2: no locations (pending).
WARNING:  Unable to resolve breakpoint to any actual locations.
(lldb) r
Process 32398 launched: '/private/tmp/foo' (x86_64)
Process 32398 stopped
* thread #1: tid = 0x7bc9ea, 0x00000001000009a4 foo`foo::a::{{impl}}::foo(self=0x00007fff5fbff918) + 36 at foo.rs:5, queue = 'com.apple.main-thread', stop reason = breakpoint 1.1
    frame #0: 0x00000001000009a4 foo`foo::a::{{impl}}::foo(self=0x00007fff5fbff918) + 36 at foo.rs:5
   2   	    pub struct S;
   3   	    impl S {
   4   	        pub fn foo(&self) {
-> 5   	            println!("hi");
   6   	        }
   7   	    }
   8   	}
(lldb) up
frame #1: 0x00000001000009ed foo`foo::b::T::bar::h8d6dcee6b0c8bb66 + 29
foo`foo::b::T::bar::h8d6dcee6b0c8bb66 + 29:
-> 0x1000009ed:  addq   $0x20, %rsp
   0x1000009f1:  popq   %rbp
   0x1000009f2:  retq
   0x1000009f3:  nopw   %cs:(%rax,%rax)
(lldb) q
Quitting LLDB will kill one or more processes. Do you really want to proceed: [Y/n] y

With codegen-units=1, all breakpoints work as expected:

godot2:tmp jdm$ rustc -C codegen-units=1 foo.rs -g
godot2:tmp jdm$ lldb foo
(lldb) target create "foo"
b Current executable set to 'foo' (x86_64).
(lldb) b foo.rs:15
Breakpoint 1: where = foo`foo::b::{{impl}}::bar + 24 at foo.rs:16, address = 0x00000001000009e8
(lldb) b foo.rs:5
Breakpoint 2: where = foo`foo::a::{{impl}}::foo + 36 at foo.rs:5, address = 0x00000001000009a4
(lldb) r
Process 32422 launched: '/private/tmp/foo' (x86_64)
Process 32422 stopped
* thread #1: tid = 0x7bce5a, 0x00000001000009e8 foo`foo::b::{{impl}}::bar(self=0x00007fff5fbff938) + 24 at foo.rs:16, queue = 'com.apple.main-thread', stop reason = breakpoint 1.1
    frame #0: 0x00000001000009e8 foo`foo::b::{{impl}}::bar(self=0x00007fff5fbff938) + 24 at foo.rs:16
   13  	    impl T {
   14  	        pub fn bar(&self) {
   15  	            let s = S;
-> 16  	            s.foo();
   17  	        }
   18  	    }
   19  	}
(lldb) c
Process 32422 resuming
Process 32422 stopped
* thread #1: tid = 0x7bce5a, 0x00000001000009a4 foo`foo::a::{{impl}}::foo(self=0x00007fff5fbff918) + 36 at foo.rs:5, queue = 'com.apple.main-thread', stop reason = breakpoint 2.1
    frame #0: 0x00000001000009a4 foo`foo::a::{{impl}}::foo(self=0x00007fff5fbff918) + 36 at foo.rs:5
   2   	    pub struct S;
   3   	    impl S {
   4   	        pub fn foo(&self) {
-> 5   	            println!("hi");
   6   	        }
   7   	    }
   8   	}
(lldb) bt
* thread #1: tid = 0x7bce5a, 0x00000001000009a4 foo`foo::a::{{impl}}::foo(self=0x00007fff5fbff918) + 36 at foo.rs:5, queue = 'com.apple.main-thread', stop reason = breakpoint 2.1
  * frame #0: 0x00000001000009a4 foo`foo::a::{{impl}}::foo(self=0x00007fff5fbff918) + 36 at foo.rs:5
    frame #1: 0x00000001000009ed foo`foo::b::{{impl}}::bar(self=0x00007fff5fbff938) + 29 at foo.rs:16
    frame #2: 0x0000000100000a11 foo`foo::main + 17 at foo.rs:23
    frame #3: 0x000000010000a0fb foo`panic_unwind::__rust_maybe_catch_panic + 27 at lib.rs:98
    frame #4: 0x0000000100008967 foo`std::rt::lang_start [inlined] std::panicking::try<(),fn()> + 44 at panicking.rs:436
    frame #5: 0x000000010000893b foo`std::rt::lang_start [inlined] std::panic::catch_unwind<fn(),()> at panic.rs:361
    frame #6: 0x000000010000893b foo`std::rt::lang_start + 347 at rt.rs:57
    frame #7: 0x0000000100000a4a foo`main + 42
    frame #8: 0x00007fff929365fd libdyld.dylib`start + 1
(lldb) up
frame #1: 0x00000001000009ed foo`foo::b::{{impl}}::bar(self=0x00007fff5fbff938) + 29 at foo.rs:16
   13  	    impl T {
   14  	        pub fn bar(&self) {
   15  	            let s = S;
-> 16  	            s.foo();
   17  	        }
   18  	    }
   19  	}
(lldb)
@jdm jdm added the A-debuginfo Area: Debugging information in compiled programs (DWARF, PDB, etc.) label Jan 18, 2017
@alexcrichton
Copy link
Member

cc @michaelwoerister

@michaelwoerister
Copy link
Member

Does this also happen in GDB?

@jdm
Copy link
Contributor Author

jdm commented Jan 18, 2017

@michaelwoerister Yep!

@michaelwoerister
Copy link
Member

:(

@michaelwoerister
Copy link
Member

I cannot reproduce this with GDB on Linux. Can you tell me more about your setup? OS, RUSTC version, GDB and LLDB versions, etc.

@jdm
Copy link
Contributor Author

jdm commented Jan 19, 2017

  • OS X 10.9.5
  • rustc 1.16.0-nightly (1a2ed98 2017-01-13)
  • lldb-320.4.160
  • multiple gdb versions show the same issue:
    • GNU gdb (GDB) 7.11
    • GNU gdb (GDB) 7.7.1
    • GNU gdb 6.3.50-20050815 (Apple version gdb-1822) (Sun Aug 5 03:00:42 UTC 2012)

@michaelwoerister
Copy link
Member

michaelwoerister commented Jan 20, 2017

Alright, I found out what the problem is: The OSX linker doesn't like it when there are DW_TAG_compile_units with the same name in different object files. Specifically, it will assume that all compile units with the same name come from the same object file and thus won't create an OSO stabs symbol for any but the first object file. When dsymutil later tries to aggregate the debuginfo from the object files, there is only one entry in the binary -- it won't know that about all the other object files out there.

A possible solution to this is assigning different DW_TAG_compile_unit names for different object files, even if they come from the same source file. This solved the problem in a local experiment. It is at odds with the DWARF definition of what the DW_AT_name of a compile unit should be, however.

@jdm jdm added the O-macos Operating system: macOS label Jan 20, 2017
@jdm
Copy link
Contributor Author

jdm commented Jan 31, 2017

How would that affect setting breakpoints on lines of named source files?

@jdm
Copy link
Contributor Author

jdm commented Jan 31, 2017

15:54 <tromey> one wacky idea would be to try making up a phony source file name, then pretending that the entire body was actually from the "#included" real file
15:55 <tromey> another would be to play games with relative paths and the compilation directory
15:55 <tromey> getting off in the weeds at that point though

@michaelwoerister
Copy link
Member

How would that affect setting breakpoints on lines of named source files?

In practice not at all, I guess. We would still be emitting the correct file names for source locations.

@nikomatsakis
Copy link
Contributor

Tagging with A-incr-comp since this affects incremental.

@nikomatsakis nikomatsakis added I-nominated T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. and removed I-nominated labels Apr 13, 2017
@jdm
Copy link
Contributor Author

jdm commented May 17, 2017

I waste so much time doing builds of Servo on branches that have codegen-units enabled before realizing that I need to disable it so I can poke around in lldb. Could we please have someone spend some time on fixing this or rust-lang/cargo#3897?

@michaelwoerister
Copy link
Member

I'm inclined to just make a PR with the fix I mentioned above (=generate a unique filename for the codegen unit that does not correspond to an actual file). It's (kind of) incorrect with regards to DWARF but it should hurt neither function nor file/line breakpoints, I think, since debuggers and profilers already have to deal with functions coming from files that are not equal to the file the CGU specifies.

Any serious concerns, @tromey?

Mark-Simulacrum added a commit to Mark-Simulacrum/rust that referenced this issue May 19, 2017
…debuginfo, r=jdm

debuginfo: Generate unique DW_AT_names for compilation units to work around OSX linker bug

This should fix issue rust-lang#39160 and does not seem to cause any problems.

cc @tromey, @Manishearth

r? @jdm
@michaelwoerister
Copy link
Member

@jdm, did you get a chance to see if the fix from #42100 works for you?

@jdm
Copy link
Contributor Author

jdm commented May 29, 2017

It's certainly much more usable out of the box now. Thanks!

@jdm jdm closed this as completed May 29, 2017
bors-servo pushed a commit to servo/servo that referenced this issue May 30, 2017
Update rustc.

This brings in rust-lang/rust#39160 which significantly improves the default debugging experience on macOS.

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/17080)
<!-- Reviewable:end -->
aethanyc pushed a commit to aethanyc/gecko-dev that referenced this issue May 30, 2017
This brings in rust-lang/rust#39160 which significantly improves the default debugging experience on macOS.

Source-Repo: https://github.com/servo/servo
Source-Revision: ad4a5411a9620cee5cd93d5fe1a3dbad02cc0812
moz-v2v-gh pushed a commit to mozilla/gecko-dev that referenced this issue May 30, 2017
This brings in rust-lang/rust#39160 which significantly improves the default debugging experience on macOS.

Source-Repo: https://github.com/servo/servo
Source-Revision: ad4a5411a9620cee5cd93d5fe1a3dbad02cc0812

--HG--
extra : subtree_source : https%3A//hg.mozilla.org/projects/converted-servo-linear
extra : subtree_revision : 0c1abc4ad87968a2ebcd0a2f9d80612f0c58cc78
JerryShih pushed a commit to JerryShih/gecko-dev that referenced this issue Jun 2, 2017
This brings in rust-lang/rust#39160 which significantly improves the default debugging experience on macOS.

Source-Repo: https://github.com/servo/servo
Source-Revision: ad4a5411a9620cee5cd93d5fe1a3dbad02cc0812
Manishearth pushed a commit to Manishearth/gecko-dev that referenced this issue Jun 11, 2017
This brings in rust-lang/rust#39160 which significantly improves the default debugging experience on macOS.

Source-Repo: https://github.com/servo/servo
Source-Revision: ad4a5411a9620cee5cd93d5fe1a3dbad02cc0812
brendandahl pushed a commit to brendandahl/gecko that referenced this issue Jul 10, 2017
This brings in rust-lang/rust#39160 which significantly improves the default debugging experience on macOS.

Source-Repo: https://github.com/servo/servo
Source-Revision: ad4a5411a9620cee5cd93d5fe1a3dbad02cc0812
gecko-dev-updater pushed a commit to marco-c/gecko-dev-wordified-and-comments-removed that referenced this issue Oct 1, 2019
This brings in rust-lang/rust#39160 which significantly improves the default debugging experience on macOS.

Source-Repo: https://github.com/servo/servo
Source-Revision: ad4a5411a9620cee5cd93d5fe1a3dbad02cc0812

UltraBlame original commit: 2b4844f7a38ef8973b937690fc041ca63c496c2f
gecko-dev-updater pushed a commit to marco-c/gecko-dev-comments-removed that referenced this issue Oct 1, 2019
This brings in rust-lang/rust#39160 which significantly improves the default debugging experience on macOS.

Source-Repo: https://github.com/servo/servo
Source-Revision: ad4a5411a9620cee5cd93d5fe1a3dbad02cc0812

UltraBlame original commit: 2b4844f7a38ef8973b937690fc041ca63c496c2f
gecko-dev-updater pushed a commit to marco-c/gecko-dev-wordified that referenced this issue Oct 1, 2019
This brings in rust-lang/rust#39160 which significantly improves the default debugging experience on macOS.

Source-Repo: https://github.com/servo/servo
Source-Revision: ad4a5411a9620cee5cd93d5fe1a3dbad02cc0812

UltraBlame original commit: 2b4844f7a38ef8973b937690fc041ca63c496c2f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-debuginfo Area: Debugging information in compiled programs (DWARF, PDB, etc.) A-incr-comp Area: Incremental compilation O-macos Operating system: macOS T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

4 participants