@@ -18,6 +18,8 @@ const native_arch = builtin.cpu.arch;
18
18
const native_os = builtin .os .tag ;
19
19
const native_endian = native_arch .endian ();
20
20
21
+ pub const Dwarf = @import ("debug/Dwarf.zig" );
22
+
21
23
pub const runtime_safety = switch (builtin .mode ) {
22
24
.Debug , .ReleaseSafe = > true ,
23
25
.ReleaseFast , .ReleaseSmall = > false ,
@@ -67,7 +69,7 @@ pub const SymbolInfo = struct {
67
69
};
68
70
const PdbOrDwarf = union (enum ) {
69
71
pdb : pdb.Pdb ,
70
- dwarf : DW.DwarfInfo ,
72
+ dwarf : Dwarf ,
71
73
72
74
fn deinit (self : * PdbOrDwarf , allocator : mem.Allocator ) void {
73
75
switch (self .* ) {
@@ -566,7 +568,7 @@ pub const StackIterator = struct {
566
568
// using DWARF and MachO unwind info.
567
569
unwind_state : if (have_ucontext ) ? struct {
568
570
debug_info : * Info ,
569
- dwarf_context : DW .UnwindContext ,
571
+ dwarf_context : Dwarf .UnwindContext ,
570
572
last_error : ? UnwindError = null ,
571
573
failed : bool = false ,
572
574
} else void = if (have_ucontext ) null else {},
@@ -599,7 +601,7 @@ pub const StackIterator = struct {
599
601
var iterator = init (first_address , null );
600
602
iterator .unwind_state = .{
601
603
.debug_info = debug_info ,
602
- .dwarf_context = try DW .UnwindContext .init (debug_info .allocator , context ),
604
+ .dwarf_context = try Dwarf .UnwindContext .init (debug_info .allocator , context ),
603
605
};
604
606
605
607
return iterator ;
@@ -783,7 +785,7 @@ pub const StackIterator = struct {
783
785
// __unwind_info is a requirement for unwinding on Darwin. It may fall back to DWARF, but unwinding
784
786
// via DWARF before attempting to use the compact unwind info will produce incorrect results.
785
787
if (module .unwind_info ) | unwind_info | {
786
- if (DW .unwindFrameMachO (& unwind_state .dwarf_context , & it .ma , unwind_info , module .eh_frame , module .base_address )) | return_address | {
788
+ if (Dwarf .unwindFrameMachO (& unwind_state .dwarf_context , & it .ma , unwind_info , module .eh_frame , module .base_address )) | return_address | {
787
789
return return_address ;
788
790
} else | err | {
789
791
if (err != error .RequiresDWARFUnwind ) return err ;
@@ -1140,10 +1142,10 @@ fn readCoffDebugInfo(allocator: mem.Allocator, coff_obj: *coff.Coff) !ModuleDebu
1140
1142
1141
1143
if (coff_obj .getSectionByName (".debug_info" )) | _ | {
1142
1144
// This coff file has embedded DWARF debug info
1143
- var sections : DW.DwarfInfo. SectionArray = DW . DwarfInfo .null_section_array ;
1145
+ var sections : Dwarf. SectionArray = Dwarf .null_section_array ;
1144
1146
errdefer for (sections ) | section | if (section ) | s | if (s .owned ) allocator .free (s .data );
1145
1147
1146
- inline for (@typeInfo (DW . DwarfSection ).Enum .fields , 0.. ) | section , i | {
1148
+ inline for (@typeInfo (Dwarf . Section . Id ).Enum .fields , 0.. ) | section , i | {
1147
1149
sections [i ] = if (coff_obj .getSectionByName ("." ++ section .name )) | section_header | blk : {
1148
1150
break :blk .{
1149
1151
.data = try coff_obj .getSectionDataAlloc (section_header , allocator ),
@@ -1153,13 +1155,13 @@ fn readCoffDebugInfo(allocator: mem.Allocator, coff_obj: *coff.Coff) !ModuleDebu
1153
1155
} else null ;
1154
1156
}
1155
1157
1156
- var dwarf = DW.DwarfInfo {
1158
+ var dwarf = Dwarf {
1157
1159
.endian = native_endian ,
1158
1160
.sections = sections ,
1159
1161
.is_macho = false ,
1160
1162
};
1161
1163
1162
- try DW . openDwarfDebugInfo (& dwarf , allocator );
1164
+ try Dwarf . open (& dwarf , allocator );
1163
1165
di .dwarf = dwarf ;
1164
1166
}
1165
1167
@@ -1211,7 +1213,7 @@ pub fn readElfDebugInfo(
1211
1213
elf_filename : ? []const u8 ,
1212
1214
build_id : ? []const u8 ,
1213
1215
expected_crc : ? u32 ,
1214
- parent_sections : * DW.DwarfInfo .SectionArray ,
1216
+ parent_sections : * Dwarf .SectionArray ,
1215
1217
parent_mapped_mem : ? []align (mem.page_size ) const u8 ,
1216
1218
) ! ModuleDebugInfo {
1217
1219
nosuspend {
@@ -1245,7 +1247,7 @@ pub fn readElfDebugInfo(
1245
1247
@ptrCast (@alignCast (& mapped_mem [shoff ])),
1246
1248
)[0.. hdr .e_shnum ];
1247
1249
1248
- var sections : DW.DwarfInfo. SectionArray = DW . DwarfInfo .null_section_array ;
1250
+ var sections : Dwarf. SectionArray = Dwarf .null_section_array ;
1249
1251
1250
1252
// Combine section list. This takes ownership over any owned sections from the parent scope.
1251
1253
for (parent_sections , & sections ) | * parent , * section | {
@@ -1274,7 +1276,7 @@ pub fn readElfDebugInfo(
1274
1276
}
1275
1277
1276
1278
var section_index : ? usize = null ;
1277
- inline for (@typeInfo (DW . DwarfSection ).Enum .fields , 0.. ) | section , i | {
1279
+ inline for (@typeInfo (Dwarf . Section . Id ).Enum .fields , 0.. ) | section , i | {
1278
1280
if (mem .eql (u8 , "." ++ section .name , name )) section_index = i ;
1279
1281
}
1280
1282
if (section_index == null ) continue ;
@@ -1308,10 +1310,10 @@ pub fn readElfDebugInfo(
1308
1310
}
1309
1311
1310
1312
const missing_debug_info =
1311
- sections [@intFromEnum (DW . DwarfSection .debug_info )] == null or
1312
- sections [@intFromEnum (DW . DwarfSection .debug_abbrev )] == null or
1313
- sections [@intFromEnum (DW . DwarfSection .debug_str )] == null or
1314
- sections [@intFromEnum (DW . DwarfSection .debug_line )] == null ;
1313
+ sections [@intFromEnum (Dwarf . Section . Id .debug_info )] == null or
1314
+ sections [@intFromEnum (Dwarf . Section . Id .debug_abbrev )] == null or
1315
+ sections [@intFromEnum (Dwarf . Section . Id .debug_str )] == null or
1316
+ sections [@intFromEnum (Dwarf . Section . Id .debug_line )] == null ;
1315
1317
1316
1318
// Attempt to load debug info from an external file
1317
1319
// See: https://sourceware.org/gdb/onlinedocs/gdb/Separate-Debug-Files.html
@@ -1379,13 +1381,13 @@ pub fn readElfDebugInfo(
1379
1381
return error .MissingDebugInfo ;
1380
1382
}
1381
1383
1382
- var di = DW.DwarfInfo {
1384
+ var di = Dwarf {
1383
1385
.endian = endian ,
1384
1386
.sections = sections ,
1385
1387
.is_macho = false ,
1386
1388
};
1387
1389
1388
- try DW . openDwarfDebugInfo (& di , allocator );
1390
+ try Dwarf . open (& di , allocator );
1389
1391
1390
1392
return ModuleDebugInfo {
1391
1393
.base_address = undefined ,
@@ -2168,13 +2170,13 @@ pub const Info = struct {
2168
2170
const obj_di = try self .allocator .create (ModuleDebugInfo );
2169
2171
errdefer self .allocator .destroy (obj_di );
2170
2172
2171
- var sections : DW.DwarfInfo. SectionArray = DW . DwarfInfo .null_section_array ;
2173
+ var sections : Dwarf. SectionArray = Dwarf .null_section_array ;
2172
2174
if (ctx .gnu_eh_frame ) | eh_frame_hdr | {
2173
2175
// This is a special case - pointer offsets inside .eh_frame_hdr
2174
2176
// are encoded relative to its base address, so we must use the
2175
2177
// version that is already memory mapped, and not the one that
2176
2178
// will be mapped separately from the ELF file.
2177
- sections [@intFromEnum (DW . DwarfSection .eh_frame_hdr )] = .{
2179
+ sections [@intFromEnum (Dwarf . Section . Id .eh_frame_hdr )] = .{
2178
2180
.data = eh_frame_hdr ,
2179
2181
.owned = false ,
2180
2182
};
@@ -2219,7 +2221,7 @@ pub const ModuleDebugInfo = switch (native_os) {
2219
2221
2220
2222
const OFileTable = std .StringHashMap (OFileInfo );
2221
2223
const OFileInfo = struct {
2222
- di : DW.DwarfInfo ,
2224
+ di : Dwarf ,
2223
2225
addr_table : std .StringHashMap (u64 ),
2224
2226
};
2225
2227
@@ -2278,8 +2280,8 @@ pub const ModuleDebugInfo = switch (native_os) {
2278
2280
addr_table .putAssumeCapacityNoClobber (sym_name , sym .n_value );
2279
2281
}
2280
2282
2281
- var sections : DW.DwarfInfo. SectionArray = DW . DwarfInfo .null_section_array ;
2282
- if (self .eh_frame ) | eh_frame | sections [@intFromEnum (DW . DwarfSection .eh_frame )] = .{
2283
+ var sections : Dwarf. SectionArray = Dwarf .null_section_array ;
2284
+ if (self .eh_frame ) | eh_frame | sections [@intFromEnum (Dwarf . Section . Id .eh_frame )] = .{
2283
2285
.data = eh_frame ,
2284
2286
.owned = false ,
2285
2287
};
@@ -2288,7 +2290,7 @@ pub const ModuleDebugInfo = switch (native_os) {
2288
2290
if (! std .mem .eql (u8 , "__DWARF" , sect .segName ())) continue ;
2289
2291
2290
2292
var section_index : ? usize = null ;
2291
- inline for (@typeInfo (DW . DwarfSection ).Enum .fields , 0.. ) | section , i | {
2293
+ inline for (@typeInfo (Dwarf . Section . Id ).Enum .fields , 0.. ) | section , i | {
2292
2294
if (mem .eql (u8 , "__" ++ section .name , sect .sectName ())) section_index = i ;
2293
2295
}
2294
2296
if (section_index == null ) continue ;
@@ -2302,19 +2304,19 @@ pub const ModuleDebugInfo = switch (native_os) {
2302
2304
}
2303
2305
2304
2306
const missing_debug_info =
2305
- sections [@intFromEnum (DW . DwarfSection .debug_info )] == null or
2306
- sections [@intFromEnum (DW . DwarfSection .debug_abbrev )] == null or
2307
- sections [@intFromEnum (DW . DwarfSection .debug_str )] == null or
2308
- sections [@intFromEnum (DW . DwarfSection .debug_line )] == null ;
2307
+ sections [@intFromEnum (Dwarf . Section . Id .debug_info )] == null or
2308
+ sections [@intFromEnum (Dwarf . Section . Id .debug_abbrev )] == null or
2309
+ sections [@intFromEnum (Dwarf . Section . Id .debug_str )] == null or
2310
+ sections [@intFromEnum (Dwarf . Section . Id .debug_line )] == null ;
2309
2311
if (missing_debug_info ) return error .MissingDebugInfo ;
2310
2312
2311
- var di = DW.DwarfInfo {
2313
+ var di = Dwarf {
2312
2314
.endian = .little ,
2313
2315
.sections = sections ,
2314
2316
.is_macho = true ,
2315
2317
};
2316
2318
2317
- try DW . openDwarfDebugInfo (& di , allocator );
2319
+ try Dwarf . open (& di , allocator );
2318
2320
const info = OFileInfo {
2319
2321
.di = di ,
2320
2322
.addr_table = addr_table ,
@@ -2411,14 +2413,14 @@ pub const ModuleDebugInfo = switch (native_os) {
2411
2413
}
2412
2414
}
2413
2415
2414
- pub fn getDwarfInfoForAddress (self : * @This (), allocator : mem .Allocator , address : usize ) ! ? * const DW.DwarfInfo {
2416
+ pub fn getDwarfInfoForAddress (self : * @This (), allocator : mem .Allocator , address : usize ) ! ? * const Dwarf {
2415
2417
return if ((try self .getOFileInfoForAddress (allocator , address )).o_file_info ) | o_file_info | & o_file_info .di else null ;
2416
2418
}
2417
2419
},
2418
2420
.uefi , .windows = > struct {
2419
2421
base_address : usize ,
2420
2422
pdb : ? pdb.Pdb = null ,
2421
- dwarf : ? DW.DwarfInfo = null ,
2423
+ dwarf : ? Dwarf = null ,
2422
2424
coff_image_base : u64 ,
2423
2425
2424
2426
/// Only used if pdb is non-null
@@ -2488,7 +2490,7 @@ pub const ModuleDebugInfo = switch (native_os) {
2488
2490
return SymbolInfo {};
2489
2491
}
2490
2492
2491
- pub fn getDwarfInfoForAddress (self : * @This (), allocator : mem .Allocator , address : usize ) ! ? * const DW.DwarfInfo {
2493
+ pub fn getDwarfInfoForAddress (self : * @This (), allocator : mem .Allocator , address : usize ) ! ? * const Dwarf {
2492
2494
_ = allocator ;
2493
2495
_ = address ;
2494
2496
@@ -2500,7 +2502,7 @@ pub const ModuleDebugInfo = switch (native_os) {
2500
2502
},
2501
2503
.linux , .netbsd , .freebsd , .dragonfly , .openbsd , .haiku , .solaris , .illumos = > struct {
2502
2504
base_address : usize ,
2503
- dwarf : DW.DwarfInfo ,
2505
+ dwarf : Dwarf ,
2504
2506
mapped_memory : []align (mem .page_size ) const u8 ,
2505
2507
external_mapped_memory : ? []align (mem .page_size ) const u8 ,
2506
2508
@@ -2516,7 +2518,7 @@ pub const ModuleDebugInfo = switch (native_os) {
2516
2518
return getSymbolFromDwarf (allocator , relocated_address , & self .dwarf );
2517
2519
}
2518
2520
2519
- pub fn getDwarfInfoForAddress (self : * @This (), allocator : mem .Allocator , address : usize ) ! ? * const DW.DwarfInfo {
2521
+ pub fn getDwarfInfoForAddress (self : * @This (), allocator : mem .Allocator , address : usize ) ! ? * const Dwarf {
2520
2522
_ = allocator ;
2521
2523
_ = address ;
2522
2524
return & self .dwarf ;
@@ -2535,17 +2537,17 @@ pub const ModuleDebugInfo = switch (native_os) {
2535
2537
return SymbolInfo {};
2536
2538
}
2537
2539
2538
- pub fn getDwarfInfoForAddress (self : * @This (), allocator : mem .Allocator , address : usize ) ! ? * const DW.DwarfInfo {
2540
+ pub fn getDwarfInfoForAddress (self : * @This (), allocator : mem .Allocator , address : usize ) ! ? * const Dwarf {
2539
2541
_ = self ;
2540
2542
_ = allocator ;
2541
2543
_ = address ;
2542
2544
return null ;
2543
2545
}
2544
2546
},
2545
- else = > DW . DwarfInfo ,
2547
+ else = > Dwarf ,
2546
2548
};
2547
2549
2548
- fn getSymbolFromDwarf (allocator : mem.Allocator , address : u64 , di : * DW.DwarfInfo ) ! SymbolInfo {
2550
+ fn getSymbolFromDwarf (allocator : mem.Allocator , address : u64 , di : * Dwarf ) ! SymbolInfo {
2549
2551
if (nosuspend di .findCompileUnit (address )) | compile_unit | {
2550
2552
return SymbolInfo {
2551
2553
.symbol_name = nosuspend di .getSymbolName (address ) orelse "???" ,
0 commit comments