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鈥檒l 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

Projects
None yet
5 participants
@m4b
Contributor

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

This comment has been minimized.

Show comment
Hide comment
@rust-highfive

rust-highfive Dec 21, 2017

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.

Collaborator

rust-highfive commented Dec 21, 2017

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.

@estebank

This comment has been minimized.

Show comment
Hide comment
@estebank
Contributor

estebank commented Dec 21, 2017

@michaelwoerister

This comment has been minimized.

Show comment
Hide comment
@michaelwoerister

michaelwoerister Dec 23, 2017

Contributor

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

@bors r+

Contributor

michaelwoerister commented Dec 23, 2017

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

@bors r+

@bors

This comment has been minimized.

Show comment
Hide comment
@bors

bors Dec 23, 2017

Contributor

馃搶 Commit 990a5cc has been approved by michaelwoerister

Contributor

bors commented Dec 23, 2017

馃搶 Commit 990a5cc has been approved by michaelwoerister

@m4b

This comment has been minimized.

Show comment
Hide comment
@m4b

m4b Dec 24, 2017

Contributor

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

Contributor

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

This comment has been minimized.

Show comment
Hide comment
@bors

bors Dec 24, 2017

Contributor

鈱涳笍 Testing commit 990a5cc with merge a834b86...

Contributor

bors commented Dec 24, 2017

鈱涳笍 Testing commit 990a5cc with merge a834b86...

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

Auto merge of #46899 - m4b:linkage_name_equals_symbol_name, r=michael鈥
鈥oerister

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

This comment has been minimized.

Show comment
Hide comment
@bors

bors Dec 25, 2017

Contributor

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

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

2 checks passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details
homu Test successful
Details

@m4b m4b deleted the m4b:linkage_name_equals_symbol_name branch Dec 25, 2017

BurntPizza added a commit to BurntPizza/rust that referenced this pull request Dec 27, 2017

Auto merge of rust-lang#46899 - m4b:linkage_name_equals_symbol_name, 鈥
鈥=michaelwoerister

Set the dwarf linkage_name to the mangled name

ref rust-lang#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
```

old:
```
(gdb) bt
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment