@@ -84,39 +84,41 @@ fn make_file_info(hash: SourceFileHash) -> Option<FileInfo> {
8484 }
8585}
8686
87- fn line_program_add_file (
88- line_program : & mut LineProgram ,
89- line_strings : & mut LineStringTable ,
90- file : & SourceFile ,
91- ) -> FileId {
92- match & file. name {
93- FileName :: Real ( path) => {
94- let ( dir_path, file_name) = split_path_dir_and_file ( path. remapped_path_if_available ( ) ) ;
95- let dir_name = osstr_as_utf8_bytes ( dir_path. as_os_str ( ) ) ;
96- let file_name = osstr_as_utf8_bytes ( file_name) ;
97-
98- let dir_id = if !dir_name. is_empty ( ) {
99- let dir_name = LineString :: new ( dir_name, line_program. encoding ( ) , line_strings) ;
100- line_program. add_directory ( dir_name)
101- } else {
102- line_program. default_directory ( )
103- } ;
104- let file_name = LineString :: new ( file_name, line_program. encoding ( ) , line_strings) ;
105-
106- let info = make_file_info ( file. src_hash ) ;
107-
108- line_program. file_has_md5 &= info. is_some ( ) ;
109- line_program. add_file ( file_name, dir_id, info)
110- }
111- // FIXME give more appropriate file names
112- filename => {
113- let dir_id = line_program. default_directory ( ) ;
114- let dummy_file_name = LineString :: new (
115- filename. prefer_remapped ( ) . to_string ( ) . into_bytes ( ) ,
116- line_program. encoding ( ) ,
117- line_strings,
118- ) ;
119- line_program. add_file ( dummy_file_name, dir_id, None )
87+ impl DebugContext {
88+ pub ( crate ) fn add_source_file ( & mut self , source_file : & SourceFile ) -> FileId {
89+ let line_program: & mut LineProgram = & mut self . dwarf . unit . line_program ;
90+ let line_strings: & mut LineStringTable = & mut self . dwarf . line_strings ;
91+
92+ match & source_file. name {
93+ FileName :: Real ( path) => {
94+ let ( dir_path, file_name) =
95+ split_path_dir_and_file ( path. remapped_path_if_available ( ) ) ;
96+ let dir_name = osstr_as_utf8_bytes ( dir_path. as_os_str ( ) ) ;
97+ let file_name = osstr_as_utf8_bytes ( file_name) ;
98+
99+ let dir_id = if !dir_name. is_empty ( ) {
100+ let dir_name = LineString :: new ( dir_name, line_program. encoding ( ) , line_strings) ;
101+ line_program. add_directory ( dir_name)
102+ } else {
103+ line_program. default_directory ( )
104+ } ;
105+ let file_name = LineString :: new ( file_name, line_program. encoding ( ) , line_strings) ;
106+
107+ let info = make_file_info ( source_file. src_hash ) ;
108+
109+ line_program. file_has_md5 &= info. is_some ( ) ;
110+ line_program. add_file ( file_name, dir_id, info)
111+ }
112+ // FIXME give more appropriate file names
113+ filename => {
114+ let dir_id = line_program. default_directory ( ) ;
115+ let dummy_file_name = LineString :: new (
116+ filename. prefer_remapped ( ) . to_string ( ) . into_bytes ( ) ,
117+ line_program. encoding ( ) ,
118+ line_strings,
119+ ) ;
120+ line_program. add_file ( dummy_file_name, dir_id, None )
121+ }
120122 }
121123 }
122124}
@@ -130,11 +132,7 @@ impl FunctionDebugContext {
130132 ) {
131133 let ( file, line, column) = get_span_loc ( tcx, span, span) ;
132134
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- ) ;
135+ let file_id = debug_context. add_source_file ( & file) ;
138136
139137 let entry = debug_context. dwarf . unit . get_mut ( self . entry_id ) ;
140138 entry. set ( gimli:: DW_AT_decl_file , AttributeValue :: FileIndex ( Some ( file_id) ) ) ;
@@ -151,15 +149,12 @@ impl FunctionDebugContext {
151149 function_span : Span ,
152150 source_info_set : & indexmap:: IndexSet < SourceInfo > ,
153151 ) -> CodeOffset {
154- let line_program = & mut debug_context. dwarf . unit . line_program ;
155-
156- let line_strings = & mut debug_context. dwarf . line_strings ;
157152 let mut last_span = None ;
158153 let mut last_file = None ;
159- let mut create_row_for_span = |line_program : & mut LineProgram , span : Span | {
154+ let mut create_row_for_span = |debug_context : & mut DebugContext , span : Span | {
160155 if let Some ( last_span) = last_span {
161156 if span == last_span {
162- line_program. generate_row ( ) ;
157+ debug_context . dwarf . unit . line_program . generate_row ( ) ;
163158 return ;
164159 }
165160 }
@@ -177,33 +172,37 @@ impl FunctionDebugContext {
177172 true
178173 } ;
179174 if current_file_changed {
180- let file_id = line_program_add_file ( line_program , line_strings , & file) ;
181- line_program. row ( ) . file = file_id;
175+ let file_id = debug_context . add_source_file ( & file) ;
176+ debug_context . dwarf . unit . line_program . row ( ) . file = file_id;
182177 last_file = Some ( file) ;
183178 }
184179
185- line_program. row ( ) . line = line;
186- line_program. row ( ) . column = col;
187- line_program. generate_row ( ) ;
180+ debug_context . dwarf . unit . line_program . row ( ) . line = line;
181+ debug_context . dwarf . unit . line_program . row ( ) . column = col;
182+ debug_context . dwarf . unit . line_program . generate_row ( ) ;
188183 } ;
189184
190- line_program. begin_sequence ( Some ( Address :: Symbol { symbol, addend : 0 } ) ) ;
185+ debug_context
186+ . dwarf
187+ . unit
188+ . line_program
189+ . begin_sequence ( Some ( Address :: Symbol { symbol, addend : 0 } ) ) ;
191190
192191 let mut func_end = 0 ;
193192
194193 let mcr = context. mach_compile_result . as_ref ( ) . unwrap ( ) ;
195194 for & MachSrcLoc { start, end, loc } in mcr. buffer . get_srclocs_sorted ( ) {
196- line_program. row ( ) . address_offset = u64:: from ( start) ;
195+ debug_context . dwarf . unit . line_program . row ( ) . address_offset = u64:: from ( start) ;
197196 if !loc. is_default ( ) {
198197 let source_info = * source_info_set. get_index ( loc. bits ( ) as usize ) . unwrap ( ) ;
199- create_row_for_span ( line_program , source_info. span ) ;
198+ create_row_for_span ( debug_context , source_info. span ) ;
200199 } else {
201- create_row_for_span ( line_program , function_span) ;
200+ create_row_for_span ( debug_context , function_span) ;
202201 }
203202 func_end = end;
204203 }
205204
206- line_program. end_sequence ( u64:: from ( func_end) ) ;
205+ debug_context . dwarf . unit . line_program . end_sequence ( u64:: from ( func_end) ) ;
207206
208207 let func_end = mcr. buffer . total_size ( ) ;
209208
0 commit comments