Skip to content

Commit 09ec683

Browse files
committed
Emit DW_AT_frame_base debuginfo attribute
1 parent cfd7325 commit 09ec683

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

src/debuginfo/mod.rs

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ mod unwind;
88
use cranelift_codegen::ir::Endianness;
99
use cranelift_codegen::isa::TargetIsa;
1010
use gimli::write::{
11-
Address, AttributeValue, DwarfUnit, FileId, LineProgram, LineString, Range, RangeList,
12-
UnitEntryId,
11+
Address, AttributeValue, DwarfUnit, Expression, FileId, LineProgram, LineString, Range,
12+
RangeList, UnitEntryId,
1313
};
14-
use gimli::{Encoding, Format, LineEncoding, RunTimeEndian};
14+
use gimli::{AArch64, Encoding, Format, LineEncoding, Register, RiscV, RunTimeEndian, X86_64};
1515
use indexmap::IndexSet;
1616
use rustc_session::Session;
1717

@@ -28,6 +28,7 @@ pub(crate) struct DebugContext {
2828

2929
dwarf: DwarfUnit,
3030
unit_range_list: RangeList,
31+
stack_pointer_register: Register,
3132

3233
should_remap_filepaths: bool,
3334
}
@@ -60,6 +61,15 @@ impl DebugContext {
6061
Endianness::Big => RunTimeEndian::Big,
6162
};
6263

64+
let stack_pointer_register = match isa.triple().architecture {
65+
target_lexicon::Architecture::Aarch64(_) => AArch64::SP,
66+
target_lexicon::Architecture::Riscv64(_) => RiscV::SP,
67+
target_lexicon::Architecture::X86_64 | target_lexicon::Architecture::X86_64h => {
68+
X86_64::RSP
69+
}
70+
_ => Register(u16::MAX),
71+
};
72+
6373
let mut dwarf = DwarfUnit::new(encoding);
6474

6575
let should_remap_filepaths = tcx.sess.should_prefer_remapped_for_codegen();
@@ -111,6 +121,7 @@ impl DebugContext {
111121
endian,
112122
dwarf,
113123
unit_range_list: RangeList(Vec::new()),
124+
stack_pointer_register,
114125
should_remap_filepaths,
115126
}
116127
}
@@ -135,6 +146,10 @@ impl DebugContext {
135146
entry.set(gimli::DW_AT_name, AttributeValue::StringRef(name_id));
136147
entry.set(gimli::DW_AT_linkage_name, AttributeValue::StringRef(name_id));
137148

149+
let mut frame_base_expr = Expression::new();
150+
frame_base_expr.op_reg(self.stack_pointer_register);
151+
entry.set(gimli::DW_AT_frame_base, AttributeValue::Exprloc(frame_base_expr));
152+
138153
entry.set(gimli::DW_AT_decl_file, AttributeValue::FileIndex(Some(file_id)));
139154
entry.set(gimli::DW_AT_decl_line, AttributeValue::Udata(line));
140155
entry.set(gimli::DW_AT_decl_column, AttributeValue::Udata(column));

0 commit comments

Comments
 (0)