Skip to content

codegen-units ruins debug symbols #39160

Closed
@jdm

Description

@jdm
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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-debuginfoArea: Debugging information in compiled programs (DWARF, PDB, etc.)A-incr-compArea: Incremental compilationO-macosOperating system: macOST-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions