Skip to content

Commit a834b86

Browse files
committed
Auto merge of rust-lang#46899 - m4b:linkage_name_equals_symbol_name, r=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 #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 rust-lang#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 rust-lang#2 0x000055555555b120 in inline::main () at /home/m4b/tmp/bad_debug/inline.rs:20 ```
2 parents c284f88 + 990a5cc commit a834b86

File tree

3 files changed

+24
-30
lines changed

3 files changed

+24
-30
lines changed

src/librustc_trans/debuginfo/metadata.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1665,8 +1665,8 @@ pub fn create_global_var_metadata(cx: &CrateContext,
16651665
let linkage_name = if no_mangle {
16661666
None
16671667
} else {
1668-
let linkage_name = mangled_name_of_item(cx, node_def_id, "");
1669-
Some(CString::new(linkage_name).unwrap())
1668+
let linkage_name = mangled_name_of_item(cx, node_id);
1669+
Some(CString::new(linkage_name.to_string()).unwrap())
16701670
};
16711671

16721672
let global_align = cx.align_of(variable_type);

src/librustc_trans/debuginfo/mod.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use self::VariableAccess::*;
1515
use self::VariableKind::*;
1616

1717
use self::utils::{DIB, span_start, create_DIArray, is_node_local_to_unit};
18-
use self::namespace::mangled_name_of_item;
18+
use self::namespace::mangled_name_of_instance;
1919
use self::type_names::compute_debuginfo_type_name;
2020
use self::metadata::{type_metadata, file_metadata, TypeMap};
2121
use self::source_loc::InternalDebugLocation::{self, UnknownLocation};
@@ -237,7 +237,6 @@ pub fn create_function_debug_context<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
237237
// Find the enclosing function, in case this is a closure.
238238
let def_key = cx.tcx().def_key(def_id);
239239
let mut name = def_key.disambiguated_data.data.to_string();
240-
let name_len = name.len();
241240

242241
let enclosing_fn_def_id = cx.tcx().closure_base_def_id(def_id);
243242

@@ -251,16 +250,16 @@ pub fn create_function_debug_context<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
251250
file_metadata,
252251
&mut name);
253252

254-
// Build the linkage_name out of the item path and "template" parameters.
255-
let linkage_name = mangled_name_of_item(cx, instance.def_id(), &name[name_len..]);
253+
// Get the linkage_name, which is just the symbol name
254+
let linkage_name = mangled_name_of_instance(cx, instance);
256255

257256
let scope_line = span_start(cx, span).line;
258257

259258
let local_id = cx.tcx().hir.as_local_node_id(instance.def_id());
260259
let is_local_to_unit = local_id.map_or(false, |id| is_node_local_to_unit(cx, id));
261260

262261
let function_name = CString::new(name).unwrap();
263-
let linkage_name = CString::new(linkage_name).unwrap();
262+
let linkage_name = CString::new(linkage_name.to_string()).unwrap();
264263

265264
let mut flags = DIFlags::FlagPrototyped;
266265
match *cx.sess().entry_fn.borrow() {

src/librustc_trans/debuginfo/namespace.rs

+18-23
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212

1313
use super::metadata::{unknown_file_metadata, UNKNOWN_LINE_NUMBER};
1414
use super::utils::{DIB, debug_context};
15+
use monomorphize::Instance;
16+
use rustc::ty;
17+
use syntax::ast;
1518

1619
use llvm;
1720
use llvm::debuginfo::DIScope;
@@ -22,30 +25,22 @@ use common::CrateContext;
2225
use std::ffi::CString;
2326
use std::ptr;
2427

25-
pub fn mangled_name_of_item(ccx: &CrateContext, def_id: DefId, extra: &str) -> String {
26-
fn fill_nested(ccx: &CrateContext, def_id: DefId, extra: &str, output: &mut String) {
27-
let def_key = ccx.tcx().def_key(def_id);
28-
if let Some(parent) = def_key.parent {
29-
fill_nested(ccx, DefId {
30-
krate: def_id.krate,
31-
index: parent
32-
}, "", output);
33-
}
34-
35-
let name = match def_key.disambiguated_data.data {
36-
DefPathData::CrateRoot => ccx.tcx().crate_name(def_id.krate).as_str(),
37-
data => data.as_interned_str()
38-
};
39-
40-
output.push_str(&(name.len() + extra.len()).to_string());
41-
output.push_str(&name);
42-
output.push_str(extra);
43-
}
28+
pub fn mangled_name_of_instance<'a, 'tcx>(
29+
ccx: &CrateContext<'a, 'tcx>,
30+
instance: Instance<'tcx>,
31+
) -> ty::SymbolName {
32+
let tcx = ccx.tcx();
33+
tcx.symbol_name(instance)
34+
}
4435

45-
let mut name = String::from("_ZN");
46-
fill_nested(ccx, def_id, extra, &mut name);
47-
name.push('E');
48-
name
36+
pub fn mangled_name_of_item<'a, 'tcx>(
37+
ccx: &CrateContext<'a, 'tcx>,
38+
node_id: ast::NodeId,
39+
) -> ty::SymbolName {
40+
let tcx = ccx.tcx();
41+
let node_def_id = tcx.hir.local_def_id(node_id);
42+
let instance = Instance::mono(tcx, node_def_id);
43+
tcx.symbol_name(instance)
4944
}
5045

5146
pub fn item_namespace(ccx: &CrateContext, def_id: DefId) -> DIScope {

0 commit comments

Comments
 (0)