@@ -200,127 +200,37 @@ impl<'a, 'tcx: 'a> DebugContext<'tcx> {
200
200
)
201
201
. unwrap ( ) ;
202
202
203
- artifact
204
- . declare_with (
205
- SectionId :: DebugAbbrev . name ( ) ,
206
- Decl :: DebugSection ,
207
- debug_abbrev. 0 . writer . into_vec ( ) ,
208
- )
209
- . unwrap ( ) ;
210
- artifact
211
- . declare_with (
212
- SectionId :: DebugInfo . name ( ) ,
213
- Decl :: DebugSection ,
214
- debug_info. 0 . writer . into_vec ( ) ,
215
- )
216
- . unwrap ( ) ;
217
- artifact
218
- . declare_with (
219
- SectionId :: DebugStr . name ( ) ,
220
- Decl :: DebugSection ,
221
- debug_str. 0 . writer . into_vec ( ) ,
222
- )
223
- . unwrap ( ) ;
224
- artifact
225
- . declare_with (
226
- SectionId :: DebugLine . name ( ) ,
227
- Decl :: DebugSection ,
228
- debug_line. 0 . writer . into_vec ( ) ,
229
- )
230
- . unwrap ( ) ;
231
-
232
- let debug_ranges_not_empty = !debug_ranges. 0 . writer . slice ( ) . is_empty ( ) ;
233
- if debug_ranges_not_empty {
203
+ macro decl_section ( $section: ident = $name: ident) {
234
204
artifact
235
205
. declare_with (
236
- SectionId :: DebugRanges . name ( ) ,
206
+ SectionId :: $section . name ( ) ,
237
207
Decl :: DebugSection ,
238
- debug_ranges . 0 . writer . into_vec ( ) ,
208
+ $name . 0 . writer . into_vec ( ) ,
239
209
)
240
210
. unwrap ( ) ;
241
211
}
242
212
243
- let debug_rnglists_not_empty = !debug_rnglists. 0 . writer . slice ( ) . is_empty ( ) ;
244
- if debug_rnglists_not_empty {
245
- artifact
246
- . declare_with (
247
- SectionId :: DebugRngLists . name ( ) ,
248
- Decl :: DebugSection ,
249
- debug_rnglists. 0 . writer . into_vec ( ) ,
250
- )
251
- . unwrap ( ) ;
252
- }
253
-
254
- for reloc in debug_abbrev. 0 . relocs {
255
- artifact
256
- . link_with (
257
- faerie:: Link {
258
- from : SectionId :: DebugAbbrev . name ( ) ,
259
- to : & reloc. name ,
260
- at : u64:: from ( reloc. offset ) ,
261
- } ,
262
- faerie:: Reloc :: Debug {
263
- size : reloc. size ,
264
- addend : reloc. addend as i32 ,
265
- } ,
266
- )
267
- . expect ( "faerie relocation error" ) ;
268
- }
269
-
270
- for reloc in debug_info. 0 . relocs {
271
- artifact
272
- . link_with (
273
- faerie:: Link {
274
- from : SectionId :: DebugInfo . name ( ) ,
275
- to : & reloc. name ,
276
- at : u64:: from ( reloc. offset ) ,
277
- } ,
278
- faerie:: Reloc :: Debug {
279
- size : reloc. size ,
280
- addend : reloc. addend as i32 ,
281
- } ,
282
- )
283
- . expect ( "faerie relocation error" ) ;
284
- }
213
+ decl_section ! ( DebugAbbrev = debug_abbrev) ;
214
+ decl_section ! ( DebugInfo = debug_info) ;
215
+ decl_section ! ( DebugStr = debug_str) ;
216
+ decl_section ! ( DebugLine = debug_line) ;
285
217
286
- for reloc in debug_str. 0 . relocs {
287
- artifact
288
- . link_with (
289
- faerie:: Link {
290
- from : SectionId :: DebugStr . name ( ) ,
291
- to : & reloc. name ,
292
- at : u64:: from ( reloc. offset ) ,
293
- } ,
294
- faerie:: Reloc :: Debug {
295
- size : reloc. size ,
296
- addend : reloc. addend as i32 ,
297
- } ,
298
- )
299
- . expect ( "faerie relocation error" ) ;
218
+ let debug_ranges_not_empty = !debug_ranges. 0 . writer . slice ( ) . is_empty ( ) ;
219
+ if debug_ranges_not_empty {
220
+ decl_section ! ( DebugRanges = debug_ranges) ;
300
221
}
301
222
302
- for reloc in debug_line. 0 . relocs {
303
- artifact
304
- . link_with (
305
- faerie:: Link {
306
- from : SectionId :: DebugLine . name ( ) ,
307
- to : & reloc. name ,
308
- at : u64:: from ( reloc. offset ) ,
309
- } ,
310
- faerie:: Reloc :: Debug {
311
- size : reloc. size ,
312
- addend : reloc. addend as i32 ,
313
- } ,
314
- )
315
- . expect ( "faerie relocation error" ) ;
223
+ let debug_rnglists_not_empty = !debug_rnglists. 0 . writer . slice ( ) . is_empty ( ) ;
224
+ if debug_rnglists_not_empty {
225
+ decl_section ! ( DebugRngLists = debug_rnglists) ;
316
226
}
317
227
318
- if debug_ranges_not_empty {
319
- for reloc in debug_ranges . 0 . relocs {
228
+ macro sect_relocs ( $section : ident = $name : ident ) {
229
+ for reloc in $name . 0 . relocs {
320
230
artifact
321
231
. link_with (
322
232
faerie:: Link {
323
- from : SectionId :: DebugRanges . name ( ) ,
233
+ from : SectionId :: $section . name ( ) ,
324
234
to : & reloc. name ,
325
235
at : u64:: from ( reloc. offset ) ,
326
236
} ,
@@ -333,22 +243,17 @@ impl<'a, 'tcx: 'a> DebugContext<'tcx> {
333
243
}
334
244
}
335
245
246
+ sect_relocs ! ( DebugAbbrev = debug_abbrev) ;
247
+ sect_relocs ! ( DebugInfo = debug_info) ;
248
+ sect_relocs ! ( DebugStr = debug_str) ;
249
+ sect_relocs ! ( DebugLine = debug_line) ;
250
+
251
+ if debug_ranges_not_empty {
252
+ sect_relocs ! ( DebugRanges = debug_ranges) ;
253
+ }
254
+
336
255
if debug_rnglists_not_empty {
337
- for reloc in debug_rnglists. 0 . relocs {
338
- artifact
339
- . link_with (
340
- faerie:: Link {
341
- from : SectionId :: DebugRngLists . name ( ) ,
342
- to : & reloc. name ,
343
- at : u64:: from ( reloc. offset ) ,
344
- } ,
345
- faerie:: Reloc :: Debug {
346
- size : reloc. size ,
347
- addend : reloc. addend as i32 ,
348
- } ,
349
- )
350
- . expect ( "faerie relocation error" ) ;
351
- }
256
+ sect_relocs ! ( DebugRngLists = debug_rnglists) ;
352
257
}
353
258
}
354
259
0 commit comments