Introduce FunctionDebugContext
This will make it easier to move TyCtxt requiring operations before clif ir compilation.
This commit is contained in:
parent
312563f3c4
commit
dbf5457308
@ -214,10 +214,10 @@ fn compile_fn<'tcx>(
|
|||||||
let unwind_context = &mut cx.unwind_context;
|
let unwind_context = &mut cx.unwind_context;
|
||||||
cx.profiler.verbose_generic_activity("generate debug info").run(|| {
|
cx.profiler.verbose_generic_activity("generate debug info").run(|| {
|
||||||
if let Some(debug_context) = debug_context {
|
if let Some(debug_context) = debug_context {
|
||||||
debug_context.define_function(
|
debug_context.define_function(codegened_func.symbol_name.name).finalize(
|
||||||
|
debug_context,
|
||||||
tcx,
|
tcx,
|
||||||
codegened_func.func_id,
|
codegened_func.func_id,
|
||||||
codegened_func.symbol_name.name,
|
|
||||||
context,
|
context,
|
||||||
codegened_func.function_span,
|
codegened_func.function_span,
|
||||||
&codegened_func.source_info_set,
|
&codegened_func.source_info_set,
|
||||||
|
@ -10,7 +10,9 @@
|
|||||||
use cranelift_codegen::ir::Endianness;
|
use cranelift_codegen::ir::Endianness;
|
||||||
use cranelift_codegen::isa::TargetIsa;
|
use cranelift_codegen::isa::TargetIsa;
|
||||||
|
|
||||||
use gimli::write::{Address, AttributeValue, DwarfUnit, LineProgram, LineString, Range, RangeList};
|
use gimli::write::{
|
||||||
|
Address, AttributeValue, DwarfUnit, LineProgram, LineString, Range, RangeList, UnitEntryId,
|
||||||
|
};
|
||||||
use gimli::{Encoding, Format, LineEncoding, RunTimeEndian};
|
use gimli::{Encoding, Format, LineEncoding, RunTimeEndian};
|
||||||
|
|
||||||
pub(crate) use emit::{DebugReloc, DebugRelocName};
|
pub(crate) use emit::{DebugReloc, DebugRelocName};
|
||||||
@ -23,6 +25,10 @@ pub(crate) struct DebugContext {
|
|||||||
unit_range_list: RangeList,
|
unit_range_list: RangeList,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub(crate) struct FunctionDebugContext {
|
||||||
|
entry_id: UnitEntryId,
|
||||||
|
}
|
||||||
|
|
||||||
impl DebugContext {
|
impl DebugContext {
|
||||||
pub(crate) fn new(tcx: TyCtxt<'_>, isa: &dyn TargetIsa) -> Self {
|
pub(crate) fn new(tcx: TyCtxt<'_>, isa: &dyn TargetIsa) -> Self {
|
||||||
let encoding = Encoding {
|
let encoding = Encoding {
|
||||||
@ -93,17 +99,7 @@ pub(crate) fn new(tcx: TyCtxt<'_>, isa: &dyn TargetIsa) -> Self {
|
|||||||
DebugContext { endian, dwarf, unit_range_list: RangeList(Vec::new()) }
|
DebugContext { endian, dwarf, unit_range_list: RangeList(Vec::new()) }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn define_function(
|
pub(crate) fn define_function(&mut self, name: &str) -> FunctionDebugContext {
|
||||||
&mut self,
|
|
||||||
tcx: TyCtxt<'_>,
|
|
||||||
func_id: FuncId,
|
|
||||||
name: &str,
|
|
||||||
context: &Context,
|
|
||||||
function_span: Span,
|
|
||||||
source_info_set: &indexmap::IndexSet<SourceInfo>,
|
|
||||||
) {
|
|
||||||
let symbol = func_id.as_u32() as usize;
|
|
||||||
|
|
||||||
// FIXME: add to appropriate scope instead of root
|
// FIXME: add to appropriate scope instead of root
|
||||||
let scope = self.dwarf.unit.root();
|
let scope = self.dwarf.unit.root();
|
||||||
|
|
||||||
@ -114,15 +110,37 @@ pub(crate) fn define_function(
|
|||||||
entry.set(gimli::DW_AT_name, AttributeValue::StringRef(name_id));
|
entry.set(gimli::DW_AT_name, AttributeValue::StringRef(name_id));
|
||||||
entry.set(gimli::DW_AT_linkage_name, AttributeValue::StringRef(name_id));
|
entry.set(gimli::DW_AT_linkage_name, AttributeValue::StringRef(name_id));
|
||||||
|
|
||||||
let end =
|
FunctionDebugContext { entry_id }
|
||||||
self.create_debug_lines(tcx, symbol, entry_id, context, function_span, source_info_set);
|
}
|
||||||
|
}
|
||||||
|
|
||||||
self.unit_range_list.0.push(Range::StartLength {
|
impl FunctionDebugContext {
|
||||||
|
pub(crate) fn finalize(
|
||||||
|
self,
|
||||||
|
debug_context: &mut DebugContext,
|
||||||
|
tcx: TyCtxt<'_>,
|
||||||
|
func_id: FuncId,
|
||||||
|
context: &Context,
|
||||||
|
function_span: Span,
|
||||||
|
source_info_set: &indexmap::IndexSet<SourceInfo>,
|
||||||
|
) {
|
||||||
|
let symbol = func_id.as_u32() as usize;
|
||||||
|
|
||||||
|
let end = debug_context.create_debug_lines(
|
||||||
|
tcx,
|
||||||
|
symbol,
|
||||||
|
self.entry_id,
|
||||||
|
context,
|
||||||
|
function_span,
|
||||||
|
source_info_set,
|
||||||
|
);
|
||||||
|
|
||||||
|
debug_context.unit_range_list.0.push(Range::StartLength {
|
||||||
begin: Address::Symbol { symbol, addend: 0 },
|
begin: Address::Symbol { symbol, addend: 0 },
|
||||||
length: u64::from(end),
|
length: u64::from(end),
|
||||||
});
|
});
|
||||||
|
|
||||||
let func_entry = self.dwarf.unit.get_mut(entry_id);
|
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.
|
// Gdb requires both DW_AT_low_pc and DW_AT_high_pc. Otherwise the DW_TAG_subprogram is skipped.
|
||||||
func_entry.set(
|
func_entry.set(
|
||||||
gimli::DW_AT_low_pc,
|
gimli::DW_AT_low_pc,
|
||||||
|
Loading…
Reference in New Issue
Block a user