Match unit names with cg_llvm

This commit is contained in:
bjorn3 2024-03-27 12:57:24 +00:00
parent e48d7d242f
commit 98eaaeda11
2 changed files with 9 additions and 3 deletions

View File

@ -43,7 +43,7 @@ pub(crate) struct FunctionDebugContext {
} }
impl DebugContext { impl DebugContext {
pub(crate) fn new(tcx: TyCtxt<'_>, isa: &dyn TargetIsa) -> Self { pub(crate) fn new(tcx: TyCtxt<'_>, isa: &dyn TargetIsa, cgu_name: &str) -> Self {
let encoding = Encoding { let encoding = Encoding {
format: Format::Dwarf32, format: Format::Dwarf32,
// FIXME this should be configurable // FIXME this should be configurable
@ -108,7 +108,7 @@ pub(crate) fn new(tcx: TyCtxt<'_>, isa: &dyn TargetIsa) -> Self {
dwarf.unit.line_program = line_program; dwarf.unit.line_program = line_program;
{ {
let name = dwarf.strings.add(name); let name = dwarf.strings.add(format!("{name}/@/{cgu_name}"));
let comp_dir = dwarf.strings.add(comp_dir); let comp_dir = dwarf.strings.add(comp_dir);
let root = dwarf.unit.root(); let root = dwarf.unit.root();
@ -116,6 +116,12 @@ pub(crate) fn new(tcx: TyCtxt<'_>, isa: &dyn TargetIsa) -> Self {
root.set(gimli::DW_AT_producer, AttributeValue::StringRef(dwarf.strings.add(producer))); root.set(gimli::DW_AT_producer, AttributeValue::StringRef(dwarf.strings.add(producer)));
root.set(gimli::DW_AT_language, AttributeValue::Language(gimli::DW_LANG_Rust)); root.set(gimli::DW_AT_language, AttributeValue::Language(gimli::DW_LANG_Rust));
root.set(gimli::DW_AT_name, AttributeValue::StringRef(name)); root.set(gimli::DW_AT_name, AttributeValue::StringRef(name));
// This will be replaced when emitting the debuginfo. It is only
// defined here to ensure that the order of the attributes matches
// rustc.
root.set(gimli::DW_AT_stmt_list, AttributeValue::Udata(0));
root.set(gimli::DW_AT_comp_dir, AttributeValue::StringRef(comp_dir)); root.set(gimli::DW_AT_comp_dir, AttributeValue::StringRef(comp_dir));
root.set(gimli::DW_AT_low_pc, AttributeValue::Address(Address::Constant(0))); root.set(gimli::DW_AT_low_pc, AttributeValue::Address(Address::Constant(0)));
} }

View File

@ -148,7 +148,7 @@ fn new(
let unwind_context = let unwind_context =
UnwindContext::new(isa, matches!(backend_config.codegen_mode, CodegenMode::Aot)); UnwindContext::new(isa, matches!(backend_config.codegen_mode, CodegenMode::Aot));
let debug_context = if debug_info && !tcx.sess.target.options.is_like_windows { let debug_context = if debug_info && !tcx.sess.target.options.is_like_windows {
Some(DebugContext::new(tcx, isa)) Some(DebugContext::new(tcx, isa, cgu_name.as_str()))
} else { } else {
None None
}; };