Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 9d6f65e

Browse files
committed
Implement line debuginfo for AArch64
1 parent 6387df1 commit 9d6f65e

File tree

2 files changed

+52
-25
lines changed

2 files changed

+52
-25
lines changed

src/debuginfo/line_info.rs

Lines changed: 48 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use crate::prelude::*;
66
use rustc_span::{FileName, SourceFile, SourceFileAndLine, Pos, SourceFileHash, SourceFileHashAlgorithm};
77

88
use cranelift_codegen::binemit::CodeOffset;
9+
use cranelift_codegen::machinst::MachSrcLoc;
910

1011
use gimli::write::{
1112
Address, AttributeValue, FileId, LineProgram, LineString, FileInfo, LineStringTable, UnitEntryId,
@@ -128,18 +129,8 @@ impl<'a, 'tcx> FunctionDebugContext<'a, 'tcx> {
128129
source_info_set: &indexmap::IndexSet<SourceInfo>,
129130
) -> CodeOffset {
130131
let tcx = self.debug_context.tcx;
131-
132132
let line_program = &mut self.debug_context.dwarf.unit.line_program;
133-
134-
line_program.begin_sequence(Some(Address::Symbol {
135-
symbol: self.symbol,
136-
addend: 0,
137-
}));
138-
139-
let encinfo = isa.encoding_info();
140133
let func = &context.func;
141-
let mut blocks = func.layout.blocks().collect::<Vec<_>>();
142-
blocks.sort_by_key(|block| func.offsets[*block]); // Ensure inst offsets always increase
143134

144135
let line_strings = &mut self.debug_context.dwarf.line_strings;
145136
let function_span = self.mir.span;
@@ -197,22 +188,58 @@ impl<'a, 'tcx> FunctionDebugContext<'a, 'tcx> {
197188
line_program.generate_row();
198189
};
199190

200-
let mut end = 0;
201-
for block in blocks {
202-
for (offset, inst, size) in func.inst_offsets(block, &encinfo) {
203-
let srcloc = func.srclocs[inst];
204-
line_program.row().address_offset = offset as u64;
205-
if !srcloc.is_default() {
206-
let source_info = *source_info_set.get_index(srcloc.bits() as usize).unwrap();
191+
line_program.begin_sequence(Some(Address::Symbol {
192+
symbol: self.symbol,
193+
addend: 0,
194+
}));
195+
196+
let mut func_end = 0;
197+
198+
if let Some(ref mcr) = &context.mach_compile_result {
199+
for &MachSrcLoc { start, end, loc } in mcr.sections.get_srclocs_sorted() {
200+
// FIXME get_srclocs_sorted omits default srclocs
201+
if func_end < start {
202+
line_program.row().address_offset = func_end as u64;
203+
create_row_for_span(line_program, self.mir.span);
204+
}
205+
line_program.row().address_offset = start as u64;
206+
if !loc.is_default() {
207+
let source_info = *source_info_set.get_index(loc.bits() as usize).unwrap();
207208
create_row_for_span(line_program, source_info.span);
208209
} else {
209210
create_row_for_span(line_program, self.mir.span);
210211
}
211-
end = offset + size;
212+
func_end = end;
213+
}
214+
// FIXME get_srclocs_sorted omits default srclocs
215+
if func_end < mcr.sections.total_size() {
216+
line_program.row().address_offset = func_end as u64;
217+
create_row_for_span(line_program, self.mir.span);
218+
func_end = mcr.sections.total_size();
219+
}
220+
} else {
221+
let encinfo = isa.encoding_info();
222+
let mut blocks = func.layout.blocks().collect::<Vec<_>>();
223+
blocks.sort_by_key(|block| func.offsets[*block]); // Ensure inst offsets always increase
224+
225+
for block in blocks {
226+
for (offset, inst, size) in func.inst_offsets(block, &encinfo) {
227+
let srcloc = func.srclocs[inst];
228+
line_program.row().address_offset = offset as u64;
229+
if !srcloc.is_default() {
230+
let source_info = *source_info_set.get_index(srcloc.bits() as usize).unwrap();
231+
create_row_for_span(line_program, source_info.span);
232+
} else {
233+
create_row_for_span(line_program, self.mir.span);
234+
}
235+
func_end = offset + size;
236+
}
212237
}
213238
}
214239

215-
line_program.end_sequence(end as u64);
240+
assert_ne!(func_end, 0);
241+
242+
line_program.end_sequence(func_end as u64);
216243

217244
let entry = self.debug_context.dwarf.unit.get_mut(self.entry_id);
218245
entry.set(
@@ -222,11 +249,11 @@ impl<'a, 'tcx> FunctionDebugContext<'a, 'tcx> {
222249
addend: 0,
223250
}),
224251
);
225-
entry.set(gimli::DW_AT_high_pc, AttributeValue::Udata(end as u64));
252+
entry.set(gimli::DW_AT_high_pc, AttributeValue::Udata(func_end as u64));
226253

227254
self.debug_context
228255
.emit_location(self.entry_id, self.mir.span);
229256

230-
end
257+
func_end
231258
}
232259
}

src/debuginfo/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -312,10 +312,6 @@ impl<'a, 'tcx> FunctionDebugContext<'a, 'tcx> {
312312
source_info_set: &indexmap::IndexSet<SourceInfo>,
313313
local_map: FxHashMap<mir::Local, CPlace<'tcx>>,
314314
) {
315-
if isa.get_mach_backend().is_some() {
316-
return; // The AArch64 backend doesn't support line debuginfo yet.
317-
}
318-
319315
let end = self.create_debug_lines(context, isa, source_info_set);
320316

321317
self.debug_context
@@ -329,6 +325,10 @@ impl<'a, 'tcx> FunctionDebugContext<'a, 'tcx> {
329325
length: u64::from(end),
330326
});
331327

328+
if isa.get_mach_backend().is_some() {
329+
return; // Not yet implemented for the AArch64 backend.
330+
}
331+
332332
let func_entry = self.debug_context.dwarf.unit.get_mut(self.entry_id);
333333
// Gdb requires both DW_AT_low_pc and DW_AT_high_pc. Otherwise the DW_TAG_subprogram is skipped.
334334
func_entry.set(gimli::DW_AT_low_pc, AttributeValue::Address(Address::Symbol {

0 commit comments

Comments
 (0)