authorgravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2025-09-10 12:53:33+01:00
committergravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2025-09-30 13:44:52+01:00
log1123741fd5fc6545daf10e2bcdcad74ec148f61b
treed66c3b15d96fbbe94e2736e5f0a2a2c178a928db
parentbfbbda77517ec83ef7cfacced651acc9d85b8bb0
signaturelock-open Commit is signed but in an unrecognized format.

Dwarf: use 'gpa' terminology


1 files changed, 28 insertions(+), 28 deletions(-)

lib/std/debug/Dwarf.zig+28-28
...@@ -79,8 +79,8 @@ pub const Abbrev = struct {...@@ -79,8 +79,8 @@ pub const Abbrev = struct {
79 has_children: bool,79 has_children: bool,
80 attrs: []Attr,80 attrs: []Attr,
8181
82 fn deinit(abbrev: *Abbrev, allocator: Allocator) void {82 fn deinit(abbrev: *Abbrev, gpa: Allocator) void {
83 allocator.free(abbrev.attrs);83 gpa.free(abbrev.attrs);
84 abbrev.* = undefined;84 abbrev.* = undefined;
85 }85 }
8686
...@@ -96,11 +96,11 @@ pub const Abbrev = struct {...@@ -96,11 +96,11 @@ pub const Abbrev = struct {
96 offset: u64,96 offset: u64,
97 abbrevs: []Abbrev,97 abbrevs: []Abbrev,
9898
99 fn deinit(table: *Table, allocator: Allocator) void {99 fn deinit(table: *Table, gpa: Allocator) void {
100 for (table.abbrevs) |*abbrev| {100 for (table.abbrevs) |*abbrev| {
101 abbrev.deinit(allocator);101 abbrev.deinit(gpa);
102 }102 }
103 allocator.free(table.abbrevs);103 gpa.free(table.abbrevs);
104 table.* = undefined;104 table.* = undefined;
105 }105 }
106106
...@@ -213,8 +213,8 @@ pub const Die = struct {...@@ -213,8 +213,8 @@ pub const Die = struct {
213 value: FormValue,213 value: FormValue,
214 };214 };
215215
216 fn deinit(self: *Die, allocator: Allocator) void {216 fn deinit(self: *Die, gpa: Allocator) void {
217 allocator.free(self.attrs);217 gpa.free(self.attrs);
218 self.* = undefined;218 self.* = undefined;
219 }219 }
220220
...@@ -368,7 +368,7 @@ pub const ScanError = error{...@@ -368,7 +368,7 @@ pub const ScanError = error{
368 StreamTooLong,368 StreamTooLong,
369} || Allocator.Error;369} || Allocator.Error;
370370
371fn scanAllFunctions(di: *Dwarf, allocator: Allocator, endian: Endian) ScanError!void {371fn scanAllFunctions(di: *Dwarf, gpa: Allocator, endian: Endian) ScanError!void {
372 var fr: Reader = .fixed(di.section(.debug_info).?);372 var fr: Reader = .fixed(di.section(.debug_info).?);
373 var this_unit_offset: u64 = 0;373 var this_unit_offset: u64 = 0;
374374
...@@ -394,7 +394,7 @@ fn scanAllFunctions(di: *Dwarf, allocator: Allocator, endian: Endian) ScanError!...@@ -394,7 +394,7 @@ fn scanAllFunctions(di: *Dwarf, allocator: Allocator, endian: Endian) ScanError!
394 address_size = try fr.takeByte();394 address_size = try fr.takeByte();
395 }395 }
396396
397 const abbrev_table = try di.getAbbrevTable(allocator, debug_abbrev_offset);397 const abbrev_table = try di.getAbbrevTable(gpa, debug_abbrev_offset);
398398
399 var max_attrs: usize = 0;399 var max_attrs: usize = 0;
400 var zig_padding_abbrev_code: u7 = 0;400 var zig_padding_abbrev_code: u7 = 0;
...@@ -409,8 +409,8 @@ fn scanAllFunctions(di: *Dwarf, allocator: Allocator, endian: Endian) ScanError!...@@ -409,8 +409,8 @@ fn scanAllFunctions(di: *Dwarf, allocator: Allocator, endian: Endian) ScanError!
409 }409 }
410 }410 }
411 }411 }
412 const attrs_buf = try allocator.alloc(Die.Attr, max_attrs * 3);412 const attrs_buf = try gpa.alloc(Die.Attr, max_attrs * 3);
413 defer allocator.free(attrs_buf);413 defer gpa.free(attrs_buf);
414 var attrs_bufs: [3][]Die.Attr = undefined;414 var attrs_bufs: [3][]Die.Attr = undefined;
415 for (&attrs_bufs, 0..) |*buf, index| buf.* = attrs_buf[index * max_attrs ..][0..max_attrs];415 for (&attrs_bufs, 0..) |*buf, index| buf.* = attrs_buf[index * max_attrs ..][0..max_attrs];
416416
...@@ -510,7 +510,7 @@ fn scanAllFunctions(di: *Dwarf, allocator: Allocator, endian: Endian) ScanError!...@@ -510,7 +510,7 @@ fn scanAllFunctions(di: *Dwarf, allocator: Allocator, endian: Endian) ScanError!
510 else => return bad(),510 else => return bad(),
511 };511 };
512512
513 try di.func_list.append(allocator, .{513 try di.func_list.append(gpa, .{
514 .name = fn_name,514 .name = fn_name,
515 .pc_range = .{515 .pc_range = .{
516 .start = low_pc,516 .start = low_pc,
...@@ -535,7 +535,7 @@ fn scanAllFunctions(di: *Dwarf, allocator: Allocator, endian: Endian) ScanError!...@@ -535,7 +535,7 @@ fn scanAllFunctions(di: *Dwarf, allocator: Allocator, endian: Endian) ScanError!
535535
536 while (try iter.next()) |range| {536 while (try iter.next()) |range| {
537 range_added = true;537 range_added = true;
538 try di.func_list.append(allocator, .{538 try di.func_list.append(gpa, .{
539 .name = fn_name,539 .name = fn_name,
540 .pc_range = .{540 .pc_range = .{
541 .start = range.start,541 .start = range.start,
...@@ -546,7 +546,7 @@ fn scanAllFunctions(di: *Dwarf, allocator: Allocator, endian: Endian) ScanError!...@@ -546,7 +546,7 @@ fn scanAllFunctions(di: *Dwarf, allocator: Allocator, endian: Endian) ScanError!
546 }546 }
547547
548 if (fn_name != null and !range_added) {548 if (fn_name != null and !range_added) {
549 try di.func_list.append(allocator, .{549 try di.func_list.append(gpa, .{
550 .name = fn_name,550 .name = fn_name,
551 .pc_range = null,551 .pc_range = null,
552 });552 });
...@@ -560,11 +560,11 @@ fn scanAllFunctions(di: *Dwarf, allocator: Allocator, endian: Endian) ScanError!...@@ -560,11 +560,11 @@ fn scanAllFunctions(di: *Dwarf, allocator: Allocator, endian: Endian) ScanError!
560 }560 }
561}561}
562562
563fn scanAllCompileUnits(di: *Dwarf, allocator: Allocator, endian: Endian) ScanError!void {563fn scanAllCompileUnits(di: *Dwarf, gpa: Allocator, endian: Endian) ScanError!void {
564 var fr: Reader = .fixed(di.section(.debug_info).?);564 var fr: Reader = .fixed(di.section(.debug_info).?);
565 var this_unit_offset: u64 = 0;565 var this_unit_offset: u64 = 0;
566566
567 var attrs_buf = std.array_list.Managed(Die.Attr).init(allocator);567 var attrs_buf = std.array_list.Managed(Die.Attr).init(gpa);
568 defer attrs_buf.deinit();568 defer attrs_buf.deinit();
569569
570 while (this_unit_offset < fr.buffer.len) {570 while (this_unit_offset < fr.buffer.len) {
...@@ -589,7 +589,7 @@ fn scanAllCompileUnits(di: *Dwarf, allocator: Allocator, endian: Endian) ScanErr...@@ -589,7 +589,7 @@ fn scanAllCompileUnits(di: *Dwarf, allocator: Allocator, endian: Endian) ScanErr
589 address_size = try fr.takeByte();589 address_size = try fr.takeByte();
590 }590 }
591591
592 const abbrev_table = try di.getAbbrevTable(allocator, debug_abbrev_offset);592 const abbrev_table = try di.getAbbrevTable(gpa, debug_abbrev_offset);
593593
594 var max_attrs: usize = 0;594 var max_attrs: usize = 0;
595 for (abbrev_table.abbrevs) |abbrev| {595 for (abbrev_table.abbrevs) |abbrev| {
...@@ -608,7 +608,7 @@ fn scanAllCompileUnits(di: *Dwarf, allocator: Allocator, endian: Endian) ScanErr...@@ -608,7 +608,7 @@ fn scanAllCompileUnits(di: *Dwarf, allocator: Allocator, endian: Endian) ScanErr
608608
609 if (compile_unit_die.tag_id != DW.TAG.compile_unit) return bad();609 if (compile_unit_die.tag_id != DW.TAG.compile_unit) return bad();
610610
611 compile_unit_die.attrs = try allocator.dupe(Die.Attr, compile_unit_die.attrs);611 compile_unit_die.attrs = try gpa.dupe(Die.Attr, compile_unit_die.attrs);
612612
613 var compile_unit: CompileUnit = .{613 var compile_unit: CompileUnit = .{
614 .version = version,614 .version = version,
...@@ -645,7 +645,7 @@ fn scanAllCompileUnits(di: *Dwarf, allocator: Allocator, endian: Endian) ScanErr...@@ -645,7 +645,7 @@ fn scanAllCompileUnits(di: *Dwarf, allocator: Allocator, endian: Endian) ScanErr
645 }645 }
646 };646 };
647647
648 try di.compile_unit_list.append(allocator, compile_unit);648 try di.compile_unit_list.append(gpa, compile_unit);
649649
650 this_unit_offset += next_offset;650 this_unit_offset += next_offset;
651 }651 }
...@@ -855,32 +855,32 @@ pub fn findCompileUnit(di: *const Dwarf, endian: Endian, target_address: u64) !*...@@ -855,32 +855,32 @@ pub fn findCompileUnit(di: *const Dwarf, endian: Endian, target_address: u64) !*
855855
856/// Gets an already existing AbbrevTable given the abbrev_offset, or if not found,856/// Gets an already existing AbbrevTable given the abbrev_offset, or if not found,
857/// seeks in the stream and parses it.857/// seeks in the stream and parses it.
858fn getAbbrevTable(di: *Dwarf, allocator: Allocator, abbrev_offset: u64) !*const Abbrev.Table {858fn getAbbrevTable(di: *Dwarf, gpa: Allocator, abbrev_offset: u64) !*const Abbrev.Table {
859 for (di.abbrev_table_list.items) |*table| {859 for (di.abbrev_table_list.items) |*table| {
860 if (table.offset == abbrev_offset) {860 if (table.offset == abbrev_offset) {
861 return table;861 return table;
862 }862 }
863 }863 }
864 try di.abbrev_table_list.append(864 try di.abbrev_table_list.append(
865 allocator,865 gpa,
866 try di.parseAbbrevTable(allocator, abbrev_offset),866 try di.parseAbbrevTable(gpa, abbrev_offset),
867 );867 );
868 return &di.abbrev_table_list.items[di.abbrev_table_list.items.len - 1];868 return &di.abbrev_table_list.items[di.abbrev_table_list.items.len - 1];
869}869}
870870
871fn parseAbbrevTable(di: *Dwarf, allocator: Allocator, offset: u64) !Abbrev.Table {871fn parseAbbrevTable(di: *Dwarf, gpa: Allocator, offset: u64) !Abbrev.Table {
872 var fr: Reader = .fixed(di.section(.debug_abbrev).?);872 var fr: Reader = .fixed(di.section(.debug_abbrev).?);
873 fr.seek = cast(usize, offset) orelse return bad();873 fr.seek = cast(usize, offset) orelse return bad();
874874
875 var abbrevs = std.array_list.Managed(Abbrev).init(allocator);875 var abbrevs = std.array_list.Managed(Abbrev).init(gpa);
876 defer {876 defer {
877 for (abbrevs.items) |*abbrev| {877 for (abbrevs.items) |*abbrev| {
878 abbrev.deinit(allocator);878 abbrev.deinit(gpa);
879 }879 }
880 abbrevs.deinit();880 abbrevs.deinit();
881 }881 }
882882
883 var attrs = std.array_list.Managed(Abbrev.Attr).init(allocator);883 var attrs = std.array_list.Managed(Abbrev.Attr).init(gpa);
884 defer attrs.deinit();884 defer attrs.deinit();
885885
886 while (true) {886 while (true) {
...@@ -1446,7 +1446,7 @@ fn getStringGeneric(opt_str: ?[]const u8, offset: u64) ![:0]const u8 {...@@ -1446,7 +1446,7 @@ fn getStringGeneric(opt_str: ?[]const u8, offset: u64) ![:0]const u8 {
1446 return str[casted_offset..last :0];1446 return str[casted_offset..last :0];
1447}1447}
14481448
1449pub fn getSymbol(di: *Dwarf, allocator: Allocator, endian: Endian, address: u64) !std.debug.Symbol {1449pub fn getSymbol(di: *Dwarf, gpa: Allocator, endian: Endian, address: u64) !std.debug.Symbol {
1450 const compile_unit = di.findCompileUnit(endian, address) catch |err| switch (err) {1450 const compile_unit = di.findCompileUnit(endian, address) catch |err| switch (err) {
1451 error.MissingDebugInfo, error.InvalidDebugInfo => return .unknown,1451 error.MissingDebugInfo, error.InvalidDebugInfo => return .unknown,
1452 else => return err,1452 else => return err,
...@@ -1456,7 +1456,7 @@ pub fn getSymbol(di: *Dwarf, allocator: Allocator, endian: Endian, address: u64)...@@ -1456,7 +1456,7 @@ pub fn getSymbol(di: *Dwarf, allocator: Allocator, endian: Endian, address: u64)
1456 .compile_unit_name = compile_unit.die.getAttrString(di, endian, std.dwarf.AT.name, di.section(.debug_str), compile_unit) catch |err| switch (err) {1456 .compile_unit_name = compile_unit.die.getAttrString(di, endian, std.dwarf.AT.name, di.section(.debug_str), compile_unit) catch |err| switch (err) {
1457 error.MissingDebugInfo, error.InvalidDebugInfo => null,1457 error.MissingDebugInfo, error.InvalidDebugInfo => null,
1458 },1458 },
1459 .source_location = di.getLineNumberInfo(allocator, endian, compile_unit, address) catch |err| switch (err) {1459 .source_location = di.getLineNumberInfo(gpa, endian, compile_unit, address) catch |err| switch (err) {
1460 error.MissingDebugInfo, error.InvalidDebugInfo => null,1460 error.MissingDebugInfo, error.InvalidDebugInfo => null,
1461 else => return err,1461 else => return err,
1462 },1462 },