Skip to content

Commit dbf5457

Browse files
committed
Introduce FunctionDebugContext
This will make it easier to move TyCtxt requiring operations before clif ir compilation.
1 parent 312563f commit dbf5457

File tree

2 files changed

+36
-18
lines changed

2 files changed

+36
-18
lines changed

src/base.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,10 +214,10 @@ fn compile_fn<'tcx>(
214214
let unwind_context = &mut cx.unwind_context;
215215
cx.profiler.verbose_generic_activity("generate debug info").run(|| {
216216
if let Some(debug_context) = debug_context {
217-
debug_context.define_function(
217+
debug_context.define_function(codegened_func.symbol_name.name).finalize(
218+
debug_context,
218219
tcx,
219220
codegened_func.func_id,
220-
codegened_func.symbol_name.name,
221221
context,
222222
codegened_func.function_span,
223223
&codegened_func.source_info_set,

src/debuginfo/mod.rs

Lines changed: 34 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ use crate::prelude::*;
1010
use cranelift_codegen::ir::Endianness;
1111
use cranelift_codegen::isa::TargetIsa;
1212

13-
use gimli::write::{Address, AttributeValue, DwarfUnit, LineProgram, LineString, Range, RangeList};
13+
use gimli::write::{
14+
Address, AttributeValue, DwarfUnit, LineProgram, LineString, Range, RangeList, UnitEntryId,
15+
};
1416
use gimli::{Encoding, Format, LineEncoding, RunTimeEndian};
1517

1618
pub(crate) use emit::{DebugReloc, DebugRelocName};
@@ -23,6 +25,10 @@ pub(crate) struct DebugContext {
2325
unit_range_list: RangeList,
2426
}
2527

28+
pub(crate) struct FunctionDebugContext {
29+
entry_id: UnitEntryId,
30+
}
31+
2632
impl DebugContext {
2733
pub(crate) fn new(tcx: TyCtxt<'_>, isa: &dyn TargetIsa) -> Self {
2834
let encoding = Encoding {
@@ -93,17 +99,7 @@ impl DebugContext {
9399
DebugContext { endian, dwarf, unit_range_list: RangeList(Vec::new()) }
94100
}
95101

96-
pub(crate) fn define_function(
97-
&mut self,
98-
tcx: TyCtxt<'_>,
99-
func_id: FuncId,
100-
name: &str,
101-
context: &Context,
102-
function_span: Span,
103-
source_info_set: &indexmap::IndexSet<SourceInfo>,
104-
) {
105-
let symbol = func_id.as_u32() as usize;
106-
102+
pub(crate) fn define_function(&mut self, name: &str) -> FunctionDebugContext {
107103
// FIXME: add to appropriate scope instead of root
108104
let scope = self.dwarf.unit.root();
109105

@@ -114,15 +110,37 @@ impl DebugContext {
114110
entry.set(gimli::DW_AT_name, AttributeValue::StringRef(name_id));
115111
entry.set(gimli::DW_AT_linkage_name, AttributeValue::StringRef(name_id));
116112

117-
let end =
118-
self.create_debug_lines(tcx, symbol, entry_id, context, function_span, source_info_set);
113+
FunctionDebugContext { entry_id }
114+
}
115+
}
116+
117+
impl FunctionDebugContext {
118+
pub(crate) fn finalize(
119+
self,
120+
debug_context: &mut DebugContext,
121+
tcx: TyCtxt<'_>,
122+
func_id: FuncId,
123+
context: &Context,
124+
function_span: Span,
125+
source_info_set: &indexmap::IndexSet<SourceInfo>,
126+
) {
127+
let symbol = func_id.as_u32() as usize;
128+
129+
let end = debug_context.create_debug_lines(
130+
tcx,
131+
symbol,
132+
self.entry_id,
133+
context,
134+
function_span,
135+
source_info_set,
136+
);
119137

120-
self.unit_range_list.0.push(Range::StartLength {
138+
debug_context.unit_range_list.0.push(Range::StartLength {
121139
begin: Address::Symbol { symbol, addend: 0 },
122140
length: u64::from(end),
123141
});
124142

125-
let func_entry = self.dwarf.unit.get_mut(entry_id);
143+
let func_entry = debug_context.dwarf.unit.get_mut(self.entry_id);
126144
// Gdb requires both DW_AT_low_pc and DW_AT_high_pc. Otherwise the DW_TAG_subprogram is skipped.
127145
func_entry.set(
128146
gimli::DW_AT_low_pc,

0 commit comments

Comments
 (0)