@@ -5,7 +5,7 @@ use rustc_codegen_ssa::mir::debuginfo::VariableKind::*;
5
5
use self :: metadata:: { file_metadata, type_di_node} ;
6
6
use self :: metadata:: { UNKNOWN_COLUMN_NUMBER , UNKNOWN_LINE_NUMBER } ;
7
7
use 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 } ;
9
9
10
10
use crate :: abi:: FnAbi ;
11
11
use crate :: builder:: Builder ;
@@ -67,6 +67,8 @@ pub struct CodegenUnitDebugContext<'ll, 'tcx> {
67
67
type_map : metadata:: TypeMap < ' ll , ' tcx > ,
68
68
namespace_map : RefCell < DefIdMap < & ' ll DIScope > > ,
69
69
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 > > ,
70
72
}
71
73
72
74
impl Drop for CodegenUnitDebugContext < ' _ , ' _ > {
@@ -91,6 +93,7 @@ impl<'ll, 'tcx> CodegenUnitDebugContext<'ll, 'tcx> {
91
93
type_map : Default :: default ( ) ,
92
94
namespace_map : RefCell :: new ( Default :: default ( ) ) ,
93
95
recursion_marker_type : OnceCell :: new ( ) ,
96
+ variables : RefCell :: new ( Default :: default ( ) ) ,
94
97
}
95
98
}
96
99
@@ -292,7 +295,7 @@ impl<'ll, 'tcx> DebugInfoMethods<'tcx> for CodegenCx<'ll, 'tcx> {
292
295
fn_abi : & FnAbi < ' tcx , Ty < ' tcx > > ,
293
296
llfn : & ' ll Value ,
294
297
mir : & mir:: Body < ' tcx > ,
295
- ) -> Option < FunctionDebugContext < & ' ll DIScope , & ' ll DILocation > > {
298
+ ) -> Option < FunctionDebugContext < ' tcx , & ' ll DIScope , & ' ll DILocation > > {
296
299
if self . sess ( ) . opts . debuginfo == DebugInfo :: None {
297
300
return None ;
298
301
}
@@ -304,8 +307,11 @@ impl<'ll, 'tcx> DebugInfoMethods<'tcx> for CodegenCx<'ll, 'tcx> {
304
307
file_start_pos : BytePos ( 0 ) ,
305
308
file_end_pos : BytePos ( 0 ) ,
306
309
} ;
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
+ } ;
309
315
310
316
// Fill in all the scopes, with the information from the MIR body.
311
317
compute_mir_scopes ( self , instance, mir, & mut fn_debug_context) ;
@@ -606,33 +612,39 @@ impl<'ll, 'tcx> DebugInfoMethods<'tcx> for CodegenCx<'ll, 'tcx> {
606
612
variable_kind : VariableKind ,
607
613
span : Span ,
608
614
) -> & ' 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
+ } )
637
649
}
638
650
}
0 commit comments