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

Set the dwarf linkage_name to the mangled name #46899

Merged
merged 1 commit into from
Dec 25, 2017

Conversation

m4b
Copy link
Contributor

@m4b m4b commented Dec 21, 2017

ref #46453

@michaelwoerister or anyone else who knows, i'm not sure if this is the correct instance to pass here (or how to get the correct one precisely): https://github.com//m4b/rust/blob/5a94a48678ec0a20ea6a63a783e63546bf9459b1/src/librustc_trans/debuginfo/namespace.rs#L36

So don't merge this yet, I'd like to learn about correct instance first; however, I think this already fixes a bunch of weirdness i'm seeing debugging from time to time, not to mention backtraces in gdb via bt are now readable meaningful 🎉

E.g.:

new:

(gdb) bt
#0  <inline::Foo as core::convert::From<()>>::from () at /home/m4b/tmp/bad_debug/inline.rs:11
#1  0x000055555555a35d in inline::deadbeef () at /home/m4b/tmp/bad_debug/inline.rs:16
#2  0x000055555555a380 in inline::main () at /home/m4b/tmp/bad_debug/inline.rs:20

old:

(gdb) bt
#0  inline::{{impl}}::from () at /home/m4b/tmp/bad_debug/inline.rs:11
#1  0x000055555555b0ed in inline::deadbeef () at /home/m4b/tmp/bad_debug/inline.rs:16
#2  0x000055555555b120 in inline::main () at /home/m4b/tmp/bad_debug/inline.rs:20

@rust-highfive
Copy link
Collaborator

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @estebank (or someone else) soon.

If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes.

Please see the contribution instructions for more information.

@m4b m4b force-pushed the linkage_name_equals_symbol_name branch from 5a94a48 to 990a5cc Compare December 21, 2017 05:28
@estebank
Copy link
Contributor

r? @michaelwoerister

@michaelwoerister
Copy link
Member

Thanks, @m4b! Yes, that is the correct instance (it's the same that is also used for translating to LLVM IR).

@bors r+

@bors
Copy link
Contributor

bors commented Dec 23, 2017

📌 Commit 990a5cc has been approved by michaelwoerister

@m4b
Copy link
Contributor Author

m4b commented Dec 24, 2017

@michaelwoerister np, and thanks for clarifying its correct!

So, one last component I thought should be remedied here is the following addition:

diff --git a/src/librustc_trans/debuginfo/namespace.rs b/src/librustc_trans/debuginfo/namespace.rs
index 47e2b8c461..8324077e29 100644
--- a/src/librustc_trans/debuginfo/namespace.rs
+++ b/src/librustc_trans/debuginfo/namespace.rs
@@ -58,7 +58,8 @@ pub fn item_namespace(ccx: &CrateContext, def_id: DefId) -> DIScope {
 
     let namespace_name = match def_key.disambiguated_data.data {
         DefPathData::CrateRoot => ccx.tcx().crate_name(def_id.krate).as_str(),
-        data => data.as_interned_str()
+        DefPathData::Module(module) => module,
+        _ => return parent_scope,
     };
 
     let namespace_name = CString::new(namespace_name.as_bytes()).unwrap();

What this does is drop the {{impl}} in crate::mod::{{impl}}::fn in the dwarf namespaces.

So, in our example above, this would yield inline as the namespace, instead of inline::{{impl}}.

I believe we should do this. One immediate benefit is it won't show up in autocomplete (which you can't use anyway, since the current parser won't accept {{ and it isn't any symbol or namespace anywhere anyway).

However, this had the side effect of sending me down a rabbit hole w.r.t. namespaces, debugging info, gdb, and rusts "universal method call syntax". I wrote up a large thing here, but I don't think it's the time or place at the moment to paste here, probably another issue is better.

But it basically it has to do with apparently a known issue with the symbol names for trait impls and generics, e.g., one of these is the symbol table name for a impl Debug for Foo<u32>, and the other for Foo<u64>:

<foo::Foo<T> as core::fmt::Debug>::fmt::h0a79f028de68abf6
<foo::Foo<T> as core::fmt::Debug>::fmt::ha10b9f27c105328e  

E.g., they only differ in hash, but really we'd like to see the type parameter reified/instantiated with the appropriate u32/u64 (or whatever it was impl'd for)

The solution here will be probably complicated, and may involve drastically changing rusts symbol name output, but I think in the future its really important to get right.

Also would like to thank @eddyb on irc for long and fruitful discussion about some of the complexities involved here, was very interesting :)

@bors
Copy link
Contributor

bors commented Dec 24, 2017

⌛ Testing commit 990a5cc with merge a834b86...

bors added a commit that referenced this pull request Dec 24, 2017
…woerister

Set the dwarf linkage_name to the mangled name

ref #46453

@michaelwoerister or anyone else who knows, i'm not sure if this is the correct instance to pass here (or how to get the correct one precisely): https://github.com//m4b/rust/blob/5a94a48678ec0a20ea6a63a783e63546bf9459b1/src/librustc_trans/debuginfo/namespace.rs#L36

So don't merge this yet, I'd like to learn about correct instance first; however, I think this already fixes a bunch of weirdness i'm seeing debugging from time to time, not to mention backtraces in gdb via `bt` are now ~readable~ meaningful 🎉

E.g.:

new:
```
(gdb) bt
#0  <inline::Foo as core::convert::From<()>>::from () at /home/m4b/tmp/bad_debug/inline.rs:11
#1  0x000055555555a35d in inline::deadbeef () at /home/m4b/tmp/bad_debug/inline.rs:16
#2  0x000055555555a380 in inline::main () at /home/m4b/tmp/bad_debug/inline.rs:20
```

old:
```
(gdb) bt
#0  inline::{{impl}}::from () at /home/m4b/tmp/bad_debug/inline.rs:11
#1  0x000055555555b0ed in inline::deadbeef () at /home/m4b/tmp/bad_debug/inline.rs:16
#2  0x000055555555b120 in inline::main () at /home/m4b/tmp/bad_debug/inline.rs:20
```
@bors
Copy link
Contributor

bors commented Dec 25, 2017

☀️ Test successful - status-appveyor, status-travis
Approved by: michaelwoerister
Pushing a834b86 to master...

@bors bors merged commit 990a5cc into rust-lang:master Dec 25, 2017
@m4b m4b deleted the linkage_name_equals_symbol_name branch December 25, 2017 06:53
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 this pull request may close these issues.

5 participants