@@ -84,39 +84,41 @@ fn make_file_info(hash: SourceFileHash) -> Option<FileInfo> {
84
84
}
85
85
}
86
86
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
+ }
120
122
}
121
123
}
122
124
}
@@ -130,11 +132,7 @@ impl FunctionDebugContext {
130
132
) {
131
133
let ( file, line, column) = get_span_loc ( tcx, span, span) ;
132
134
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) ;
138
136
139
137
let entry = debug_context. dwarf . unit . get_mut ( self . entry_id ) ;
140
138
entry. set ( gimli:: DW_AT_decl_file , AttributeValue :: FileIndex ( Some ( file_id) ) ) ;
@@ -151,15 +149,12 @@ impl FunctionDebugContext {
151
149
function_span : Span ,
152
150
source_info_set : & indexmap:: IndexSet < SourceInfo > ,
153
151
) -> CodeOffset {
154
- let line_program = & mut debug_context. dwarf . unit . line_program ;
155
-
156
- let line_strings = & mut debug_context. dwarf . line_strings ;
157
152
let mut last_span = None ;
158
153
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 | {
160
155
if let Some ( last_span) = last_span {
161
156
if span == last_span {
162
- line_program. generate_row ( ) ;
157
+ debug_context . dwarf . unit . line_program . generate_row ( ) ;
163
158
return ;
164
159
}
165
160
}
@@ -177,33 +172,37 @@ impl FunctionDebugContext {
177
172
true
178
173
} ;
179
174
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;
182
177
last_file = Some ( file) ;
183
178
}
184
179
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 ( ) ;
188
183
} ;
189
184
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 } ) ) ;
191
190
192
191
let mut func_end = 0 ;
193
192
194
193
let mcr = context. mach_compile_result . as_ref ( ) . unwrap ( ) ;
195
194
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) ;
197
196
if !loc. is_default ( ) {
198
197
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 ) ;
200
199
} else {
201
- create_row_for_span ( line_program , function_span) ;
200
+ create_row_for_span ( debug_context , function_span) ;
202
201
}
203
202
func_end = end;
204
203
}
205
204
206
- line_program. end_sequence ( u64:: from ( func_end) ) ;
205
+ debug_context . dwarf . unit . line_program . end_sequence ( u64:: from ( func_end) ) ;
207
206
208
207
let func_end = mcr. buffer . total_size ( ) ;
209
208
0 commit comments