Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 2 additions & 7 deletions src/debuginfo/line_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::path::{Component, Path};

use cranelift_codegen::MachSrcLoc;
use cranelift_codegen::binemit::CodeOffset;
use gimli::write::{AttributeValue, FileId, FileInfo, LineProgram, LineString, LineStringTable};
use gimli::write::{FileId, FileInfo, LineProgram, LineString, LineStringTable};
use rustc_span::{FileName, Pos, SourceFile, SourceFileAndLine, SourceFileHashAlgorithm, hygiene};

use crate::debuginfo::FunctionDebugContext;
Expand Down Expand Up @@ -117,8 +117,7 @@ impl DebugContext {
}
filename => {
// For anonymous sources, create an empty directory instead of using the default
let empty_dir = LineString::new(b"", line_program.encoding(), line_strings);
let dir_id = line_program.add_directory(empty_dir);
let dir_id = line_program.default_directory();

let dummy_file_name = LineString::new(
filename.prefer_remapped_unconditionally().to_string().into_bytes(),
Expand Down Expand Up @@ -176,10 +175,6 @@ impl FunctionDebugContext {

assert_ne!(func_end, 0);

let entry = debug_context.dwarf.unit.get_mut(self.entry_id);
entry.set(gimli::DW_AT_low_pc, AttributeValue::Address(address_for_func(func_id)));
entry.set(gimli::DW_AT_high_pc, AttributeValue::Udata(u64::from(func_end)));

func_end
}
}
59 changes: 39 additions & 20 deletions src/debuginfo/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,14 @@ pub(crate) struct DebugContext {
created_files: FxHashMap<(StableSourceFileId, SourceFileHash), FileId>,
stack_pointer_register: Register,
namespace_map: DefIdMap<UnitEntryId>,
array_size_type: UnitEntryId,
array_size_type: Option<UnitEntryId>,

filename_display_preference: FileNameDisplayPreference,
embed_source: bool,
}

pub(crate) struct FunctionDebugContext {
entry_id: UnitEntryId,
entry_id: Option<UnitEntryId>,
function_source_loc: (FileId, u64, u64),
source_loc_set: IndexSet<(FileId, u64, u64)>,
}
Expand Down Expand Up @@ -154,18 +154,23 @@ impl DebugContext {
root.set(gimli::DW_AT_low_pc, AttributeValue::Address(Address::Constant(0)));
}

let array_size_type = dwarf.unit.add(dwarf.unit.root(), gimli::DW_TAG_base_type);
let array_size_type_entry = dwarf.unit.get_mut(array_size_type);
array_size_type_entry.set(
gimli::DW_AT_name,
AttributeValue::StringRef(dwarf.strings.add("__ARRAY_SIZE_TYPE__")),
);
array_size_type_entry
.set(gimli::DW_AT_encoding, AttributeValue::Encoding(gimli::DW_ATE_unsigned));
array_size_type_entry.set(
gimli::DW_AT_byte_size,
AttributeValue::Udata(isa.frontend_config().pointer_bytes().into()),
);
let array_size_type = if tcx.sess.opts.debuginfo == DebugInfo::LineTablesOnly {
None
} else {
let array_size_type = dwarf.unit.add(dwarf.unit.root(), gimli::DW_TAG_base_type);
let array_size_type_entry = dwarf.unit.get_mut(array_size_type);
array_size_type_entry.set(
gimli::DW_AT_name,
AttributeValue::StringRef(dwarf.strings.add("__ARRAY_SIZE_TYPE__")),
);
array_size_type_entry
.set(gimli::DW_AT_encoding, AttributeValue::Encoding(gimli::DW_ATE_unsigned));
array_size_type_entry.set(
gimli::DW_AT_byte_size,
AttributeValue::Udata(isa.frontend_config().pointer_bytes().into()),
);
Some(array_size_type)
};

Some(DebugContext {
endian,
Expand Down Expand Up @@ -217,6 +222,14 @@ impl DebugContext {
) -> FunctionDebugContext {
let (file_id, line, column) = self.get_span_loc(tcx, function_span, function_span);

if tcx.sess.opts.debuginfo == DebugInfo::LineTablesOnly {
return FunctionDebugContext {
entry_id: None,
function_source_loc: (file_id, line, column),
source_loc_set: IndexSet::new(),
};
}

let scope = self.item_namespace(tcx, tcx.parent(instance.def_id()));

let mut name = String::new();
Expand Down Expand Up @@ -274,7 +287,7 @@ impl DebugContext {
}

FunctionDebugContext {
entry_id,
entry_id: Some(entry_id),
function_source_loc: (file_id, line, column),
source_loc_set: IndexSet::new(),
}
Expand All @@ -288,6 +301,10 @@ impl DebugContext {
def_id: DefId,
data_id: DataId,
) {
if tcx.sess.opts.debuginfo == DebugInfo::LineTablesOnly {
return;
}

let DefKind::Static { nested, .. } = tcx.def_kind(def_id) else { bug!() };
if nested {
return;
Expand Down Expand Up @@ -353,10 +370,12 @@ impl FunctionDebugContext {
.0
.push(Range::StartLength { begin: address_for_func(func_id), length: u64::from(end) });

let func_entry = debug_context.dwarf.unit.get_mut(self.entry_id);
// Gdb requires both DW_AT_low_pc and DW_AT_high_pc. Otherwise the DW_TAG_subprogram is skipped.
func_entry.set(gimli::DW_AT_low_pc, AttributeValue::Address(address_for_func(func_id)));
// Using Udata for DW_AT_high_pc requires at least DWARF4
func_entry.set(gimli::DW_AT_high_pc, AttributeValue::Udata(u64::from(end)));
if let Some(entry_id) = self.entry_id {
let entry = debug_context.dwarf.unit.get_mut(entry_id);
// Gdb requires both DW_AT_low_pc and DW_AT_high_pc. Otherwise the DW_TAG_subprogram is skipped.
entry.set(gimli::DW_AT_low_pc, AttributeValue::Address(address_for_func(func_id)));
// Using Udata for DW_AT_high_pc requires at least DWARF4
entry.set(gimli::DW_AT_high_pc, AttributeValue::Udata(u64::from(end)));
}
}
}
3 changes: 2 additions & 1 deletion src/debuginfo/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,8 @@ impl DebugContext {

let subrange_id = self.dwarf.unit.add(array_type_id, gimli::DW_TAG_subrange_type);
let subrange_entry = self.dwarf.unit.get_mut(subrange_id);
subrange_entry.set(gimli::DW_AT_type, AttributeValue::UnitRef(self.array_size_type));
subrange_entry
.set(gimli::DW_AT_type, AttributeValue::UnitRef(self.array_size_type.unwrap()));
subrange_entry.set(gimli::DW_AT_lower_bound, AttributeValue::Udata(0));
subrange_entry.set(gimli::DW_AT_count, AttributeValue::Udata(len));

Expand Down