33use std:: ffi:: OsStr ;
44use std:: path:: { Component , Path } ;
55
6+ use crate :: debuginfo:: FunctionDebugContext ;
67use crate :: prelude:: * ;
78
89use rustc_data_structures:: sync:: Lrc ;
@@ -15,7 +16,6 @@ use cranelift_codegen::MachSrcLoc;
1516
1617use 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 }
0 commit comments