@@ -5,7 +5,7 @@ use rustc_codegen_ssa::mir::debuginfo::VariableKind::*;
55use self :: metadata:: { file_metadata, type_di_node} ;
66use self :: metadata:: { UNKNOWN_COLUMN_NUMBER , UNKNOWN_LINE_NUMBER } ;
77use self :: namespace:: mangled_name_of_instance;
8- use self :: utils:: { create_DIArray, is_node_local_to_unit, DIB } ;
8+ use self :: utils:: { create_DIArray, debug_context , is_node_local_to_unit, DIB } ;
99
1010use crate :: abi:: FnAbi ;
1111use crate :: builder:: Builder ;
@@ -67,6 +67,8 @@ pub struct CodegenUnitDebugContext<'ll, 'tcx> {
6767 type_map : metadata:: TypeMap < ' ll , ' tcx > ,
6868 namespace_map : RefCell < DefIdMap < & ' ll DIScope > > ,
6969 recursion_marker_type : OnceCell < & ' ll DIType > ,
70+ /// Maps a varaible (name, scope, kind (argument or local), span) to its debug information.
71+ variables : RefCell < FxHashMap < ( Symbol , & ' ll DIScope , VariableKind , Span ) , & ' ll DIVariable > > ,
7072}
7173
7274impl Drop for CodegenUnitDebugContext < ' _ , ' _ > {
@@ -91,6 +93,7 @@ impl<'ll, 'tcx> CodegenUnitDebugContext<'ll, 'tcx> {
9193 type_map : Default :: default ( ) ,
9294 namespace_map : RefCell :: new ( Default :: default ( ) ) ,
9395 recursion_marker_type : OnceCell :: new ( ) ,
96+ variables : RefCell :: new ( Default :: default ( ) ) ,
9497 }
9598 }
9699
@@ -292,7 +295,7 @@ impl<'ll, 'tcx> DebugInfoMethods<'tcx> for CodegenCx<'ll, 'tcx> {
292295 fn_abi : & FnAbi < ' tcx , Ty < ' tcx > > ,
293296 llfn : & ' ll Value ,
294297 mir : & mir:: Body < ' tcx > ,
295- ) -> Option < FunctionDebugContext < & ' ll DIScope , & ' ll DILocation > > {
298+ ) -> Option < FunctionDebugContext < ' tcx , & ' ll DIScope , & ' ll DILocation > > {
296299 if self . sess ( ) . opts . debuginfo == DebugInfo :: None {
297300 return None ;
298301 }
@@ -304,8 +307,11 @@ impl<'ll, 'tcx> DebugInfoMethods<'tcx> for CodegenCx<'ll, 'tcx> {
304307 file_start_pos : BytePos ( 0 ) ,
305308 file_end_pos : BytePos ( 0 ) ,
306309 } ;
307- let mut fn_debug_context =
308- FunctionDebugContext { scopes : IndexVec :: from_elem ( empty_scope, & mir. source_scopes ) } ;
310+ let mut fn_debug_context = FunctionDebugContext {
311+ scopes : IndexVec :: from_elem ( empty_scope, & mir. source_scopes ) ,
312+ inlined_function_scopes : Default :: default ( ) ,
313+ lexical_blocks : Default :: default ( ) ,
314+ } ;
309315
310316 // Fill in all the scopes, with the information from the MIR body.
311317 compute_mir_scopes ( self , instance, mir, & mut fn_debug_context) ;
@@ -606,33 +612,39 @@ impl<'ll, 'tcx> DebugInfoMethods<'tcx> for CodegenCx<'ll, 'tcx> {
606612 variable_kind : VariableKind ,
607613 span : Span ,
608614 ) -> & ' ll DIVariable {
609- let loc = self . lookup_debug_loc ( span. lo ( ) ) ;
610- let file_metadata = file_metadata ( self , & loc. file ) ;
611-
612- let type_metadata = type_di_node ( self , variable_type) ;
613-
614- let ( argument_index, dwarf_tag) = match variable_kind {
615- ArgumentVariable ( index) => ( index as c_uint , DW_TAG_arg_variable ) ,
616- LocalVariable => ( 0 , DW_TAG_auto_variable ) ,
617- } ;
618- let align = self . align_of ( variable_type) ;
619-
620- let name = variable_name. as_str ( ) ;
621- unsafe {
622- llvm:: LLVMRustDIBuilderCreateVariable (
623- DIB ( self ) ,
624- dwarf_tag,
625- scope_metadata,
626- name. as_ptr ( ) . cast ( ) ,
627- name. len ( ) ,
628- file_metadata,
629- loc. line ,
630- type_metadata,
631- true ,
632- DIFlags :: FlagZero ,
633- argument_index,
634- align. bytes ( ) as u32 ,
635- )
636- }
615+ debug_context ( self )
616+ . variables
617+ . borrow_mut ( )
618+ . entry ( ( variable_name, scope_metadata, variable_kind, span) )
619+ . or_insert_with ( || {
620+ let loc = self . lookup_debug_loc ( span. lo ( ) ) ;
621+ let file_metadata = file_metadata ( self , & loc. file ) ;
622+
623+ let type_metadata = type_di_node ( self , variable_type) ;
624+
625+ let ( argument_index, dwarf_tag) = match variable_kind {
626+ ArgumentVariable ( index) => ( index as c_uint , DW_TAG_arg_variable ) ,
627+ LocalVariable => ( 0 , DW_TAG_auto_variable ) ,
628+ } ;
629+ let align = self . align_of ( variable_type) ;
630+
631+ let name = variable_name. as_str ( ) ;
632+ unsafe {
633+ llvm:: LLVMRustDIBuilderCreateVariable (
634+ DIB ( self ) ,
635+ dwarf_tag,
636+ scope_metadata,
637+ name. as_ptr ( ) . cast ( ) ,
638+ name. len ( ) ,
639+ file_metadata,
640+ loc. line ,
641+ type_metadata,
642+ true ,
643+ DIFlags :: FlagZero ,
644+ argument_index,
645+ align. bytes ( ) as u32 ,
646+ )
647+ }
648+ } )
637649 }
638650}
0 commit comments