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 {
7979 has_children: bool,
8080 attrs: []Attr,
8181
82 fn deinit(abbrev: *Abbrev, allocator: Allocator) void {
83 allocator.free(abbrev.attrs);
82 fn deinit(abbrev: *Abbrev, gpa: Allocator) void {
83 gpa.free(abbrev.attrs);
8484 abbrev.* = undefined;
8585 }
8686
......@@ -96,11 +96,11 @@ pub const Abbrev = struct {
9696 offset: u64,
9797 abbrevs: []Abbrev,
9898
99 fn deinit(table: *Table, allocator: Allocator) void {
99 fn deinit(table: *Table, gpa: Allocator) void {
100100 for (table.abbrevs) |*abbrev| {
101 abbrev.deinit(allocator);
101 abbrev.deinit(gpa);
102102 }
103 allocator.free(table.abbrevs);
103 gpa.free(table.abbrevs);
104104 table.* = undefined;
105105 }
106106
......@@ -213,8 +213,8 @@ pub const Die = struct {
213213 value: FormValue,
214214 };
215215
216 fn deinit(self: *Die, allocator: Allocator) void {
217 allocator.free(self.attrs);
216 fn deinit(self: *Die, gpa: Allocator) void {
217 gpa.free(self.attrs);
218218 self.* = undefined;
219219 }
220220
......@@ -368,7 +368,7 @@ pub const ScanError = error{
368368 StreamTooLong,
369369} || Allocator.Error;
370370
371fn scanAllFunctions(di: *Dwarf, allocator: Allocator, endian: Endian) ScanError!void {
371fn scanAllFunctions(di: *Dwarf, gpa: Allocator, endian: Endian) ScanError!void {
372372 var fr: Reader = .fixed(di.section(.debug_info).?);
373373 var this_unit_offset: u64 = 0;
374374
......@@ -394,7 +394,7 @@ fn scanAllFunctions(di: *Dwarf, allocator: Allocator, endian: Endian) ScanError!
394394 address_size = try fr.takeByte();
395395 }
396396
397 const abbrev_table = try di.getAbbrevTable(allocator, debug_abbrev_offset);
397 const abbrev_table = try di.getAbbrevTable(gpa, debug_abbrev_offset);
398398
399399 var max_attrs: usize = 0;
400400 var zig_padding_abbrev_code: u7 = 0;
......@@ -409,8 +409,8 @@ fn scanAllFunctions(di: *Dwarf, allocator: Allocator, endian: Endian) ScanError!
409409 }
410410 }
411411 }
412 const attrs_buf = try allocator.alloc(Die.Attr, max_attrs * 3);
413 defer allocator.free(attrs_buf);
412 const attrs_buf = try gpa.alloc(Die.Attr, max_attrs * 3);
413 defer gpa.free(attrs_buf);
414414 var attrs_bufs: [3][]Die.Attr = undefined;
415415 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!
510510 else => return bad(),
511511 };
512512
513 try di.func_list.append(allocator, .{
513 try di.func_list.append(gpa, .{
514514 .name = fn_name,
515515 .pc_range = .{
516516 .start = low_pc,
......@@ -535,7 +535,7 @@ fn scanAllFunctions(di: *Dwarf, allocator: Allocator, endian: Endian) ScanError!
535535
536536 while (try iter.next()) |range| {
537537 range_added = true;
538 try di.func_list.append(allocator, .{
538 try di.func_list.append(gpa, .{
539539 .name = fn_name,
540540 .pc_range = .{
541541 .start = range.start,
......@@ -546,7 +546,7 @@ fn scanAllFunctions(di: *Dwarf, allocator: Allocator, endian: Endian) ScanError!
546546 }
547547
548548 if (fn_name != null and !range_added) {
549 try di.func_list.append(allocator, .{
549 try di.func_list.append(gpa, .{
550550 .name = fn_name,
551551 .pc_range = null,
552552 });
......@@ -560,11 +560,11 @@ fn scanAllFunctions(di: *Dwarf, allocator: Allocator, endian: Endian) ScanError!
560560 }
561561}
562562
563fn scanAllCompileUnits(di: *Dwarf, allocator: Allocator, endian: Endian) ScanError!void {
563fn scanAllCompileUnits(di: *Dwarf, gpa: Allocator, endian: Endian) ScanError!void {
564564 var fr: Reader = .fixed(di.section(.debug_info).?);
565565 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);
568568 defer attrs_buf.deinit();
569569
570570 while (this_unit_offset < fr.buffer.len) {
......@@ -589,7 +589,7 @@ fn scanAllCompileUnits(di: *Dwarf, allocator: Allocator, endian: Endian) ScanErr
589589 address_size = try fr.takeByte();
590590 }
591591
592 const abbrev_table = try di.getAbbrevTable(allocator, debug_abbrev_offset);
592 const abbrev_table = try di.getAbbrevTable(gpa, debug_abbrev_offset);
593593
594594 var max_attrs: usize = 0;
595595 for (abbrev_table.abbrevs) |abbrev| {
......@@ -608,7 +608,7 @@ fn scanAllCompileUnits(di: *Dwarf, allocator: Allocator, endian: Endian) ScanErr
608608
609609 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
613613 var compile_unit: CompileUnit = .{
614614 .version = version,
......@@ -645,7 +645,7 @@ fn scanAllCompileUnits(di: *Dwarf, allocator: Allocator, endian: Endian) ScanErr
645645 }
646646 };
647647
648 try di.compile_unit_list.append(allocator, compile_unit);
648 try di.compile_unit_list.append(gpa, compile_unit);
649649
650650 this_unit_offset += next_offset;
651651 }
......@@ -855,32 +855,32 @@ pub fn findCompileUnit(di: *const Dwarf, endian: Endian, target_address: u64) !*
855855
856856/// Gets an already existing AbbrevTable given the abbrev_offset, or if not found,
857857/// 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 {
859859 for (di.abbrev_table_list.items) |*table| {
860860 if (table.offset == abbrev_offset) {
861861 return table;
862862 }
863863 }
864864 try di.abbrev_table_list.append(
865 allocator,
866 try di.parseAbbrevTable(allocator, abbrev_offset),
865 gpa,
866 try di.parseAbbrevTable(gpa, abbrev_offset),
867867 );
868868 return &di.abbrev_table_list.items[di.abbrev_table_list.items.len - 1];
869869}
870870
871fn parseAbbrevTable(di: *Dwarf, allocator: Allocator, offset: u64) !Abbrev.Table {
871fn parseAbbrevTable(di: *Dwarf, gpa: Allocator, offset: u64) !Abbrev.Table {
872872 var fr: Reader = .fixed(di.section(.debug_abbrev).?);
873873 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);
876876 defer {
877877 for (abbrevs.items) |*abbrev| {
878 abbrev.deinit(allocator);
878 abbrev.deinit(gpa);
879879 }
880880 abbrevs.deinit();
881881 }
882882
883 var attrs = std.array_list.Managed(Abbrev.Attr).init(allocator);
883 var attrs = std.array_list.Managed(Abbrev.Attr).init(gpa);
884884 defer attrs.deinit();
885885
886886 while (true) {
......@@ -1446,7 +1446,7 @@ fn getStringGeneric(opt_str: ?[]const u8, offset: u64) ![:0]const u8 {
14461446 return str[casted_offset..last :0];
14471447}
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 {
14501450 const compile_unit = di.findCompileUnit(endian, address) catch |err| switch (err) {
14511451 error.MissingDebugInfo, error.InvalidDebugInfo => return .unknown,
14521452 else => return err,
......@@ -1456,7 +1456,7 @@ pub fn getSymbol(di: *Dwarf, allocator: Allocator, endian: Endian, address: u64)
14561456 .compile_unit_name = compile_unit.die.getAttrString(di, endian, std.dwarf.AT.name, di.section(.debug_str), compile_unit) catch |err| switch (err) {
14571457 error.MissingDebugInfo, error.InvalidDebugInfo => null,
14581458 },
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) {
14601460 error.MissingDebugInfo, error.InvalidDebugInfo => null,
14611461 else => return err,
14621462 },