Skip to content

Commit 1e57774

Browse files
committed
Move set_function_span earlier
1 parent 01be0dd commit 1e57774

File tree

3 files changed

+41
-24
lines changed

3 files changed

+41
-24
lines changed

src/base.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ fn codegen_fn<'tcx>(
8585
let clif_comments = crate::pretty_clif::CommentWriter::new(tcx, instance);
8686

8787
let func_debug_cx = if let Some(debug_context) = &mut cx.debug_context {
88-
Some(debug_context.define_function(symbol_name.name))
88+
Some(debug_context.define_function(tcx, symbol_name.name, mir.span))
8989
} else {
9090
None
9191
};

src/debuginfo/line_info.rs

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
use std::ffi::OsStr;
44
use std::path::{Component, Path};
55

6+
use crate::debuginfo::FunctionDebugContext;
67
use crate::prelude::*;
78

89
use rustc_data_structures::sync::Lrc;
@@ -15,7 +16,6 @@ use cranelift_codegen::MachSrcLoc;
1516

1617
use gimli::write::{
1718
Address, AttributeValue, FileId, FileInfo, LineProgram, LineString, LineStringTable,
18-
UnitEntryId,
1919
};
2020

2121
// OPTIMIZATION: It is cheaper to do this in one pass than using `.parent()` and `.file_name()`.
@@ -121,19 +121,39 @@ fn line_program_add_file(
121121
}
122122
}
123123

124-
impl DebugContext {
124+
impl FunctionDebugContext {
125+
pub(super) fn set_function_span(
126+
&mut self,
127+
debug_context: &mut DebugContext,
128+
tcx: TyCtxt<'_>,
129+
span: Span,
130+
) {
131+
let (file, line, column) = get_span_loc(tcx, span, span);
132+
133+
let file_id = line_program_add_file(
134+
&mut debug_context.dwarf.unit.line_program,
135+
&mut debug_context.dwarf.line_strings,
136+
&file,
137+
);
138+
139+
let entry = debug_context.dwarf.unit.get_mut(self.entry_id);
140+
entry.set(gimli::DW_AT_decl_file, AttributeValue::FileIndex(Some(file_id)));
141+
entry.set(gimli::DW_AT_decl_line, AttributeValue::Udata(line));
142+
entry.set(gimli::DW_AT_decl_column, AttributeValue::Udata(column));
143+
}
144+
125145
pub(super) fn create_debug_lines(
126146
&mut self,
147+
debug_context: &mut DebugContext,
127148
tcx: TyCtxt<'_>,
128149
symbol: usize,
129-
entry_id: UnitEntryId,
130150
context: &Context,
131151
function_span: Span,
132152
source_info_set: &indexmap::IndexSet<SourceInfo>,
133153
) -> CodeOffset {
134-
let line_program = &mut self.dwarf.unit.line_program;
154+
let line_program = &mut debug_context.dwarf.unit.line_program;
135155

136-
let line_strings = &mut self.dwarf.line_strings;
156+
let line_strings = &mut debug_context.dwarf.line_strings;
137157
let mut last_span = None;
138158
let mut last_file = None;
139159
let mut create_row_for_span = |line_program: &mut LineProgram, span: Span| {
@@ -189,24 +209,12 @@ impl DebugContext {
189209

190210
assert_ne!(func_end, 0);
191211

192-
let (function_file, function_line, function_col) =
193-
get_span_loc(tcx, function_span, function_span);
194-
195-
let function_file_id = line_program_add_file(
196-
&mut self.dwarf.unit.line_program,
197-
&mut self.dwarf.line_strings,
198-
&function_file,
199-
);
200-
201-
let entry = self.dwarf.unit.get_mut(entry_id);
212+
let entry = debug_context.dwarf.unit.get_mut(self.entry_id);
202213
entry.set(
203214
gimli::DW_AT_low_pc,
204215
AttributeValue::Address(Address::Symbol { symbol, addend: 0 }),
205216
);
206217
entry.set(gimli::DW_AT_high_pc, AttributeValue::Udata(u64::from(func_end)));
207-
entry.set(gimli::DW_AT_decl_file, AttributeValue::FileIndex(Some(function_file_id)));
208-
entry.set(gimli::DW_AT_decl_line, AttributeValue::Udata(function_line));
209-
entry.set(gimli::DW_AT_decl_column, AttributeValue::Udata(function_col));
210218

211219
func_end
212220
}

src/debuginfo/mod.rs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,12 @@ impl DebugContext {
9999
DebugContext { endian, dwarf, unit_range_list: RangeList(Vec::new()) }
100100
}
101101

102-
pub(crate) fn define_function(&mut self, name: &str) -> FunctionDebugContext {
102+
pub(crate) fn define_function(
103+
&mut self,
104+
tcx: TyCtxt<'_>,
105+
name: &str,
106+
function_span: Span,
107+
) -> FunctionDebugContext {
103108
// FIXME: add to appropriate scope instead of root
104109
let scope = self.dwarf.unit.root();
105110

@@ -110,13 +115,17 @@ impl DebugContext {
110115
entry.set(gimli::DW_AT_name, AttributeValue::StringRef(name_id));
111116
entry.set(gimli::DW_AT_linkage_name, AttributeValue::StringRef(name_id));
112117

113-
FunctionDebugContext { entry_id }
118+
let mut function_debug_context = FunctionDebugContext { entry_id };
119+
120+
function_debug_context.set_function_span(self, tcx, function_span);
121+
122+
function_debug_context
114123
}
115124
}
116125

117126
impl FunctionDebugContext {
118127
pub(crate) fn finalize(
119-
self,
128+
mut self,
120129
debug_context: &mut DebugContext,
121130
tcx: TyCtxt<'_>,
122131
func_id: FuncId,
@@ -126,10 +135,10 @@ impl FunctionDebugContext {
126135
) {
127136
let symbol = func_id.as_u32() as usize;
128137

129-
let end = debug_context.create_debug_lines(
138+
let end = self.create_debug_lines(
139+
debug_context,
130140
tcx,
131141
symbol,
132-
self.entry_id,
133142
context,
134143
function_span,
135144
source_info_set,

0 commit comments

Comments
 (0)