authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-08-02 21:22:33-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-08-07 00:48:32-07:00
log66954e833051872308641b3a1af12aa865d5d59a
treea20b0eed54f21d5081acea7f4d8387fdc3ace4a0
parentde47acd732dca8b4d2f2b3559307f488ccac940d

std.debug.FixedBufferReader is fine

it does not need to be deprecated

4 files changed, 114 insertions(+), 115 deletions(-)

lib/std/debug.zig+2-93
...@@ -14,6 +14,7 @@ const native_os = builtin.os.tag;...@@ -14,6 +14,7 @@ const native_os = builtin.os.tag;
14const native_endian = native_arch.endian();14const native_endian = native_arch.endian();
1515
16pub const MemoryAccessor = @import("debug/MemoryAccessor.zig");16pub const MemoryAccessor = @import("debug/MemoryAccessor.zig");
17pub const FixedBufferReader = @import("debug/FixedBufferReader.zig");
17pub const Dwarf = @import("debug/Dwarf.zig");18pub const Dwarf = @import("debug/Dwarf.zig");
18pub const Pdb = @import("debug/Pdb.zig");19pub const Pdb = @import("debug/Pdb.zig");
19pub const SelfInfo = @import("debug/SelfInfo.zig");20pub const SelfInfo = @import("debug/SelfInfo.zig");
...@@ -1494,99 +1495,6 @@ pub const SafetyLock = struct {...@@ -1494,99 +1495,6 @@ pub const SafetyLock = struct {
1494 }1495 }
1495};1496};
14961497
1497/// Deprecated. Don't use this, just read from your memory directly.
1498///
1499/// This only exists because someone was too lazy to rework logic that used to
1500/// operate on an open file to operate on a memory buffer instead.
1501pub const DeprecatedFixedBufferReader = struct {
1502 buf: []const u8,
1503 pos: usize = 0,
1504 endian: std.builtin.Endian,
1505
1506 pub const Error = error{ EndOfBuffer, Overflow, InvalidBuffer };
1507
1508 pub fn seekTo(fbr: *DeprecatedFixedBufferReader, pos: u64) Error!void {
1509 if (pos > fbr.buf.len) return error.EndOfBuffer;
1510 fbr.pos = @intCast(pos);
1511 }
1512
1513 pub fn seekForward(fbr: *DeprecatedFixedBufferReader, amount: u64) Error!void {
1514 if (fbr.buf.len - fbr.pos < amount) return error.EndOfBuffer;
1515 fbr.pos += @intCast(amount);
1516 }
1517
1518 pub inline fn readByte(fbr: *DeprecatedFixedBufferReader) Error!u8 {
1519 if (fbr.pos >= fbr.buf.len) return error.EndOfBuffer;
1520 defer fbr.pos += 1;
1521 return fbr.buf[fbr.pos];
1522 }
1523
1524 pub fn readByteSigned(fbr: *DeprecatedFixedBufferReader) Error!i8 {
1525 return @bitCast(try fbr.readByte());
1526 }
1527
1528 pub fn readInt(fbr: *DeprecatedFixedBufferReader, comptime T: type) Error!T {
1529 const size = @divExact(@typeInfo(T).Int.bits, 8);
1530 if (fbr.buf.len - fbr.pos < size) return error.EndOfBuffer;
1531 defer fbr.pos += size;
1532 return std.mem.readInt(T, fbr.buf[fbr.pos..][0..size], fbr.endian);
1533 }
1534
1535 pub fn readIntChecked(
1536 fbr: *DeprecatedFixedBufferReader,
1537 comptime T: type,
1538 ma: *MemoryAccessor,
1539 ) Error!T {
1540 if (ma.load(T, @intFromPtr(fbr.buf[fbr.pos..].ptr)) == null)
1541 return error.InvalidBuffer;
1542
1543 return fbr.readInt(T);
1544 }
1545
1546 pub fn readUleb128(fbr: *DeprecatedFixedBufferReader, comptime T: type) Error!T {
1547 return std.leb.readUleb128(T, fbr);
1548 }
1549
1550 pub fn readIleb128(fbr: *DeprecatedFixedBufferReader, comptime T: type) Error!T {
1551 return std.leb.readIleb128(T, fbr);
1552 }
1553
1554 pub fn readAddress(fbr: *DeprecatedFixedBufferReader, format: std.dwarf.Format) Error!u64 {
1555 return switch (format) {
1556 .@"32" => try fbr.readInt(u32),
1557 .@"64" => try fbr.readInt(u64),
1558 };
1559 }
1560
1561 pub fn readAddressChecked(
1562 fbr: *DeprecatedFixedBufferReader,
1563 format: std.dwarf.Format,
1564 ma: *MemoryAccessor,
1565 ) Error!u64 {
1566 return switch (format) {
1567 .@"32" => try fbr.readIntChecked(u32, ma),
1568 .@"64" => try fbr.readIntChecked(u64, ma),
1569 };
1570 }
1571
1572 pub fn readBytes(fbr: *DeprecatedFixedBufferReader, len: usize) Error![]const u8 {
1573 if (fbr.buf.len - fbr.pos < len) return error.EndOfBuffer;
1574 defer fbr.pos += len;
1575 return fbr.buf[fbr.pos..][0..len];
1576 }
1577
1578 pub fn readBytesTo(fbr: *DeprecatedFixedBufferReader, comptime sentinel: u8) Error![:sentinel]const u8 {
1579 const end = @call(.always_inline, std.mem.indexOfScalarPos, .{
1580 u8,
1581 fbr.buf,
1582 fbr.pos,
1583 sentinel,
1584 }) orelse return error.EndOfBuffer;
1585 defer fbr.pos = end + 1;
1586 return fbr.buf[fbr.pos..end :sentinel];
1587 }
1588};
1589
1590/// Detect whether the program is being executed in the Valgrind virtual machine.1498/// Detect whether the program is being executed in the Valgrind virtual machine.
1591///1499///
1592/// When Valgrind integrations are disabled, this returns comptime-known false.1500/// When Valgrind integrations are disabled, this returns comptime-known false.
...@@ -1600,6 +1508,7 @@ pub inline fn inValgrind() bool {...@@ -1600,6 +1508,7 @@ pub inline fn inValgrind() bool {
1600test {1508test {
1601 _ = &Dwarf;1509 _ = &Dwarf;
1602 _ = &MemoryAccessor;1510 _ = &MemoryAccessor;
1511 _ = &FixedBufferReader;
1603 _ = &Pdb;1512 _ = &Pdb;
1604 _ = &SelfInfo;1513 _ = &SelfInfo;
1605 _ = &dumpHex;1514 _ = &dumpHex;
lib/std/debug/Dwarf.zig+20-21
...@@ -27,8 +27,7 @@ const maxInt = std.math.maxInt;...@@ -27,8 +27,7 @@ const maxInt = std.math.maxInt;
27const MemoryAccessor = std.debug.MemoryAccessor;27const MemoryAccessor = std.debug.MemoryAccessor;
28const Path = std.Build.Cache.Path;28const Path = std.Build.Cache.Path;
2929
30/// Did I mention this is deprecated?30const FixedBufferReader = std.debug.FixedBufferReader;
31const DeprecatedFixedBufferReader = std.debug.DeprecatedFixedBufferReader;
3231
33const Dwarf = @This();32const Dwarf = @This();
3433
...@@ -328,7 +327,7 @@ pub const ExceptionFrameHeader = struct {...@@ -328,7 +327,7 @@ pub const ExceptionFrameHeader = struct {
328 var left: usize = 0;327 var left: usize = 0;
329 var len: usize = self.fde_count;328 var len: usize = self.fde_count;
330329
331 var fbr: DeprecatedFixedBufferReader = .{ .buf = self.entries, .endian = native_endian };330 var fbr: FixedBufferReader = .{ .buf = self.entries, .endian = native_endian };
332331
333 while (len > 1) {332 while (len > 1) {
334 const mid = left + len / 2;333 const mid = left + len / 2;
...@@ -371,7 +370,7 @@ pub const ExceptionFrameHeader = struct {...@@ -371,7 +370,7 @@ pub const ExceptionFrameHeader = struct {
371 const eh_frame = @as([*]const u8, @ptrFromInt(self.eh_frame_ptr))[0 .. eh_frame_len orelse maxInt(u32)];370 const eh_frame = @as([*]const u8, @ptrFromInt(self.eh_frame_ptr))[0 .. eh_frame_len orelse maxInt(u32)];
372371
373 const fde_offset = fde_ptr - self.eh_frame_ptr;372 const fde_offset = fde_ptr - self.eh_frame_ptr;
374 var eh_frame_fbr: DeprecatedFixedBufferReader = .{373 var eh_frame_fbr: FixedBufferReader = .{
375 .buf = eh_frame,374 .buf = eh_frame,
376 .pos = fde_offset,375 .pos = fde_offset,
377 .endian = native_endian,376 .endian = native_endian,
...@@ -429,9 +428,9 @@ pub const EntryHeader = struct {...@@ -429,9 +428,9 @@ pub const EntryHeader = struct {
429 }428 }
430429
431 /// Reads a header for either an FDE or a CIE, then advances the fbr to the position after the trailing structure.430 /// Reads a header for either an FDE or a CIE, then advances the fbr to the position after the trailing structure.
432 /// `fbr` must be a DeprecatedFixedBufferReader backed by either the .eh_frame or .debug_frame sections.431 /// `fbr` must be a FixedBufferReader backed by either the .eh_frame or .debug_frame sections.
433 pub fn read(432 pub fn read(
434 fbr: *DeprecatedFixedBufferReader,433 fbr: *FixedBufferReader,
435 opt_ma: ?*MemoryAccessor,434 opt_ma: ?*MemoryAccessor,
436 dwarf_section: Section.Id,435 dwarf_section: Section.Id,
437 ) !EntryHeader {436 ) !EntryHeader {
...@@ -544,7 +543,7 @@ pub const CommonInformationEntry = struct {...@@ -544,7 +543,7 @@ pub const CommonInformationEntry = struct {
544 ) !CommonInformationEntry {543 ) !CommonInformationEntry {
545 if (addr_size_bytes > 8) return error.UnsupportedAddrSize;544 if (addr_size_bytes > 8) return error.UnsupportedAddrSize;
546545
547 var fbr: DeprecatedFixedBufferReader = .{ .buf = cie_bytes, .endian = endian };546 var fbr: FixedBufferReader = .{ .buf = cie_bytes, .endian = endian };
548547
549 const version = try fbr.readByte();548 const version = try fbr.readByte();
550 switch (dwarf_section) {549 switch (dwarf_section) {
...@@ -678,7 +677,7 @@ pub const FrameDescriptionEntry = struct {...@@ -678,7 +677,7 @@ pub const FrameDescriptionEntry = struct {
678 ) !FrameDescriptionEntry {677 ) !FrameDescriptionEntry {
679 if (addr_size_bytes > 8) return error.InvalidAddrSize;678 if (addr_size_bytes > 8) return error.InvalidAddrSize;
680679
681 var fbr: DeprecatedFixedBufferReader = .{ .buf = fde_bytes, .endian = endian };680 var fbr: FixedBufferReader = .{ .buf = fde_bytes, .endian = endian };
682681
683 const pc_begin = try readEhPointer(&fbr, cie.fde_pointer_enc, addr_size_bytes, .{682 const pc_begin = try readEhPointer(&fbr, cie.fde_pointer_enc, addr_size_bytes, .{
684 .pc_rel_base = try pcRelBase(@intFromPtr(&fde_bytes[fbr.pos]), pc_rel_offset),683 .pc_rel_base = try pcRelBase(@intFromPtr(&fde_bytes[fbr.pos]), pc_rel_offset),
...@@ -785,10 +784,10 @@ pub fn getSymbolName(di: *Dwarf, address: u64) ?[]const u8 {...@@ -785,10 +784,10 @@ pub fn getSymbolName(di: *Dwarf, address: u64) ?[]const u8 {
785const ScanError = error{784const ScanError = error{
786 InvalidDebugInfo,785 InvalidDebugInfo,
787 MissingDebugInfo,786 MissingDebugInfo,
788} || Allocator.Error || std.debug.DeprecatedFixedBufferReader.Error;787} || Allocator.Error || std.debug.FixedBufferReader.Error;
789788
790fn scanAllFunctions(di: *Dwarf, allocator: Allocator) ScanError!void {789fn scanAllFunctions(di: *Dwarf, allocator: Allocator) ScanError!void {
791 var fbr: DeprecatedFixedBufferReader = .{ .buf = di.section(.debug_info).?, .endian = di.endian };790 var fbr: FixedBufferReader = .{ .buf = di.section(.debug_info).?, .endian = di.endian };
792 var this_unit_offset: u64 = 0;791 var this_unit_offset: u64 = 0;
793792
794 while (this_unit_offset < fbr.buf.len) {793 while (this_unit_offset < fbr.buf.len) {
...@@ -975,7 +974,7 @@ fn scanAllFunctions(di: *Dwarf, allocator: Allocator) ScanError!void {...@@ -975,7 +974,7 @@ fn scanAllFunctions(di: *Dwarf, allocator: Allocator) ScanError!void {
975}974}
976975
977fn scanAllCompileUnits(di: *Dwarf, allocator: Allocator) ScanError!void {976fn scanAllCompileUnits(di: *Dwarf, allocator: Allocator) ScanError!void {
978 var fbr: DeprecatedFixedBufferReader = .{ .buf = di.section(.debug_info).?, .endian = di.endian };977 var fbr: FixedBufferReader = .{ .buf = di.section(.debug_info).?, .endian = di.endian };
979 var this_unit_offset: u64 = 0;978 var this_unit_offset: u64 = 0;
980979
981 var attrs_buf = std.ArrayList(Die.Attr).init(allocator);980 var attrs_buf = std.ArrayList(Die.Attr).init(allocator);
...@@ -1100,7 +1099,7 @@ const DebugRangeIterator = struct {...@@ -1100,7 +1099,7 @@ const DebugRangeIterator = struct {
1100 section_type: Section.Id,1099 section_type: Section.Id,
1101 di: *const Dwarf,1100 di: *const Dwarf,
1102 compile_unit: *const CompileUnit,1101 compile_unit: *const CompileUnit,
1103 fbr: DeprecatedFixedBufferReader,1102 fbr: FixedBufferReader,
11041103
1105 pub fn init(ranges_value: *const FormValue, di: *const Dwarf, compile_unit: *const CompileUnit) !@This() {1104 pub fn init(ranges_value: *const FormValue, di: *const Dwarf, compile_unit: *const CompileUnit) !@This() {
1106 const section_type = if (compile_unit.version >= 5) Section.Id.debug_rnglists else Section.Id.debug_ranges;1105 const section_type = if (compile_unit.version >= 5) Section.Id.debug_rnglists else Section.Id.debug_ranges;
...@@ -1275,7 +1274,7 @@ fn getAbbrevTable(di: *Dwarf, allocator: Allocator, abbrev_offset: u64) !*const...@@ -1275,7 +1274,7 @@ fn getAbbrevTable(di: *Dwarf, allocator: Allocator, abbrev_offset: u64) !*const
1275}1274}
12761275
1277fn parseAbbrevTable(di: *Dwarf, allocator: Allocator, offset: u64) !Abbrev.Table {1276fn parseAbbrevTable(di: *Dwarf, allocator: Allocator, offset: u64) !Abbrev.Table {
1278 var fbr: DeprecatedFixedBufferReader = .{1277 var fbr: FixedBufferReader = .{
1279 .buf = di.section(.debug_abbrev).?,1278 .buf = di.section(.debug_abbrev).?,
1280 .pos = cast(usize, offset) orelse return bad(),1279 .pos = cast(usize, offset) orelse return bad(),
1281 .endian = di.endian,1280 .endian = di.endian,
...@@ -1327,7 +1326,7 @@ fn parseAbbrevTable(di: *Dwarf, allocator: Allocator, offset: u64) !Abbrev.Table...@@ -1327,7 +1326,7 @@ fn parseAbbrevTable(di: *Dwarf, allocator: Allocator, offset: u64) !Abbrev.Table
1327}1326}
13281327
1329fn parseDie(1328fn parseDie(
1330 fbr: *DeprecatedFixedBufferReader,1329 fbr: *FixedBufferReader,
1331 attrs_buf: []Die.Attr,1330 attrs_buf: []Die.Attr,
1332 abbrev_table: *const Abbrev.Table,1331 abbrev_table: *const Abbrev.Table,
1333 format: Format,1332 format: Format,
...@@ -1362,7 +1361,7 @@ pub fn getLineNumberInfo(...@@ -1362,7 +1361,7 @@ pub fn getLineNumberInfo(
1362 const compile_unit_cwd = try compile_unit.die.getAttrString(di, AT.comp_dir, di.section(.debug_line_str), compile_unit);1361 const compile_unit_cwd = try compile_unit.die.getAttrString(di, AT.comp_dir, di.section(.debug_line_str), compile_unit);
1363 const line_info_offset = try compile_unit.die.getAttrSecOffset(AT.stmt_list);1362 const line_info_offset = try compile_unit.die.getAttrSecOffset(AT.stmt_list);
13641363
1365 var fbr: DeprecatedFixedBufferReader = .{ .buf = di.section(.debug_line).?, .endian = di.endian };1364 var fbr: FixedBufferReader = .{ .buf = di.section(.debug_line).?, .endian = di.endian };
1366 try fbr.seekTo(line_info_offset);1365 try fbr.seekTo(line_info_offset);
13671366
1368 const unit_header = try readUnitHeader(&fbr, null);1367 const unit_header = try readUnitHeader(&fbr, null);
...@@ -1655,7 +1654,7 @@ fn readDebugAddr(di: Dwarf, compile_unit: CompileUnit, index: u64) !u64 {...@@ -1655,7 +1654,7 @@ fn readDebugAddr(di: Dwarf, compile_unit: CompileUnit, index: u64) !u64 {
1655/// of FDEs is built for binary searching during unwinding.1654/// of FDEs is built for binary searching during unwinding.
1656pub fn scanAllUnwindInfo(di: *Dwarf, allocator: Allocator, base_address: usize) !void {1655pub fn scanAllUnwindInfo(di: *Dwarf, allocator: Allocator, base_address: usize) !void {
1657 if (di.section(.eh_frame_hdr)) |eh_frame_hdr| blk: {1656 if (di.section(.eh_frame_hdr)) |eh_frame_hdr| blk: {
1658 var fbr: DeprecatedFixedBufferReader = .{ .buf = eh_frame_hdr, .endian = native_endian };1657 var fbr: FixedBufferReader = .{ .buf = eh_frame_hdr, .endian = native_endian };
16591658
1660 const version = try fbr.readByte();1659 const version = try fbr.readByte();
1661 if (version != 1) break :blk;1660 if (version != 1) break :blk;
...@@ -1695,7 +1694,7 @@ pub fn scanAllUnwindInfo(di: *Dwarf, allocator: Allocator, base_address: usize)...@@ -1695,7 +1694,7 @@ pub fn scanAllUnwindInfo(di: *Dwarf, allocator: Allocator, base_address: usize)
1695 const frame_sections = [2]Section.Id{ .eh_frame, .debug_frame };1694 const frame_sections = [2]Section.Id{ .eh_frame, .debug_frame };
1696 for (frame_sections) |frame_section| {1695 for (frame_sections) |frame_section| {
1697 if (di.section(frame_section)) |section_data| {1696 if (di.section(frame_section)) |section_data| {
1698 var fbr: DeprecatedFixedBufferReader = .{ .buf = section_data, .endian = di.endian };1697 var fbr: FixedBufferReader = .{ .buf = section_data, .endian = di.endian };
1699 while (fbr.pos < fbr.buf.len) {1698 while (fbr.pos < fbr.buf.len) {
1700 const entry_header = try EntryHeader.read(&fbr, null, frame_section);1699 const entry_header = try EntryHeader.read(&fbr, null, frame_section);
1701 switch (entry_header.type) {1700 switch (entry_header.type) {
...@@ -1739,7 +1738,7 @@ pub fn scanAllUnwindInfo(di: *Dwarf, allocator: Allocator, base_address: usize)...@@ -1739,7 +1738,7 @@ pub fn scanAllUnwindInfo(di: *Dwarf, allocator: Allocator, base_address: usize)
1739}1738}
17401739
1741fn parseFormValue(1740fn parseFormValue(
1742 fbr: *DeprecatedFixedBufferReader,1741 fbr: *FixedBufferReader,
1743 form_id: u64,1742 form_id: u64,
1744 format: Format,1743 format: Format,
1745 implicit_const: ?i64,1744 implicit_const: ?i64,
...@@ -1937,7 +1936,7 @@ const UnitHeader = struct {...@@ -1937,7 +1936,7 @@ const UnitHeader = struct {
1937 unit_length: u64,1936 unit_length: u64,
1938};1937};
19391938
1940fn readUnitHeader(fbr: *DeprecatedFixedBufferReader, opt_ma: ?*MemoryAccessor) ScanError!UnitHeader {1939fn readUnitHeader(fbr: *FixedBufferReader, opt_ma: ?*MemoryAccessor) ScanError!UnitHeader {
1941 return switch (try if (opt_ma) |ma| fbr.readIntChecked(u32, ma) else fbr.readInt(u32)) {1940 return switch (try if (opt_ma) |ma| fbr.readIntChecked(u32, ma) else fbr.readInt(u32)) {
1942 0...0xfffffff0 - 1 => |unit_length| .{1941 0...0xfffffff0 - 1 => |unit_length| .{
1943 .format = .@"32",1942 .format = .@"32",
...@@ -2002,7 +2001,7 @@ const EhPointerContext = struct {...@@ -2002,7 +2001,7 @@ const EhPointerContext = struct {
2002 text_rel_base: ?u64 = null,2001 text_rel_base: ?u64 = null,
2003 function_rel_base: ?u64 = null,2002 function_rel_base: ?u64 = null,
2004};2003};
2005fn readEhPointer(fbr: *DeprecatedFixedBufferReader, enc: u8, addr_size_bytes: u8, ctx: EhPointerContext) !?u64 {2004fn readEhPointer(fbr: *FixedBufferReader, enc: u8, addr_size_bytes: u8, ctx: EhPointerContext) !?u64 {
2006 if (enc == EH.PE.omit) return null;2005 if (enc == EH.PE.omit) return null;
20072006
2008 const value: union(enum) {2007 const value: union(enum) {
...@@ -2362,7 +2361,7 @@ pub const ElfModule = struct {...@@ -2362,7 +2361,7 @@ pub const ElfModule = struct {
2362 }2361 }
2363};2362};
23642363
2365pub const ResolveSourceLocationsError = Allocator.Error || DeprecatedFixedBufferReader.Error;2364pub const ResolveSourceLocationsError = Allocator.Error || FixedBufferReader.Error;
23662365
2367/// Given an array of virtual memory addresses, sorted ascending, outputs a2366/// Given an array of virtual memory addresses, sorted ascending, outputs a
2368/// corresponding array of source locations, by appending to the provided2367/// corresponding array of source locations, by appending to the provided
lib/std/debug/FixedBufferReader.zig created+91
...@@ -0,0 +1,91 @@
1const std = @import("std.zig");
2const MemoryAccessor = std.debug.MemoryAccessor;
3
4const FixedBufferReader = @This();
5
6buf: []const u8,
7pos: usize = 0,
8endian: std.builtin.Endian,
9
10pub const Error = error{ EndOfBuffer, Overflow, InvalidBuffer };
11
12pub fn seekTo(fbr: *FixedBufferReader, pos: u64) Error!void {
13 if (pos > fbr.buf.len) return error.EndOfBuffer;
14 fbr.pos = @intCast(pos);
15}
16
17pub fn seekForward(fbr: *FixedBufferReader, amount: u64) Error!void {
18 if (fbr.buf.len - fbr.pos < amount) return error.EndOfBuffer;
19 fbr.pos += @intCast(amount);
20}
21
22pub inline fn readByte(fbr: *FixedBufferReader) Error!u8 {
23 if (fbr.pos >= fbr.buf.len) return error.EndOfBuffer;
24 defer fbr.pos += 1;
25 return fbr.buf[fbr.pos];
26}
27
28pub fn readByteSigned(fbr: *FixedBufferReader) Error!i8 {
29 return @bitCast(try fbr.readByte());
30}
31
32pub fn readInt(fbr: *FixedBufferReader, comptime T: type) Error!T {
33 const size = @divExact(@typeInfo(T).Int.bits, 8);
34 if (fbr.buf.len - fbr.pos < size) return error.EndOfBuffer;
35 defer fbr.pos += size;
36 return std.mem.readInt(T, fbr.buf[fbr.pos..][0..size], fbr.endian);
37}
38
39pub fn readIntChecked(
40 fbr: *FixedBufferReader,
41 comptime T: type,
42 ma: *MemoryAccessor,
43) Error!T {
44 if (ma.load(T, @intFromPtr(fbr.buf[fbr.pos..].ptr)) == null)
45 return error.InvalidBuffer;
46
47 return fbr.readInt(T);
48}
49
50pub fn readUleb128(fbr: *FixedBufferReader, comptime T: type) Error!T {
51 return std.leb.readUleb128(T, fbr);
52}
53
54pub fn readIleb128(fbr: *FixedBufferReader, comptime T: type) Error!T {
55 return std.leb.readIleb128(T, fbr);
56}
57
58pub fn readAddress(fbr: *FixedBufferReader, format: std.dwarf.Format) Error!u64 {
59 return switch (format) {
60 .@"32" => try fbr.readInt(u32),
61 .@"64" => try fbr.readInt(u64),
62 };
63}
64
65pub fn readAddressChecked(
66 fbr: *FixedBufferReader,
67 format: std.dwarf.Format,
68 ma: *MemoryAccessor,
69) Error!u64 {
70 return switch (format) {
71 .@"32" => try fbr.readIntChecked(u32, ma),
72 .@"64" => try fbr.readIntChecked(u64, ma),
73 };
74}
75
76pub fn readBytes(fbr: *FixedBufferReader, len: usize) Error![]const u8 {
77 if (fbr.buf.len - fbr.pos < len) return error.EndOfBuffer;
78 defer fbr.pos += len;
79 return fbr.buf[fbr.pos..][0..len];
80}
81
82pub fn readBytesTo(fbr: *FixedBufferReader, comptime sentinel: u8) Error![:sentinel]const u8 {
83 const end = @call(.always_inline, std.mem.indexOfScalarPos, .{
84 u8,
85 fbr.buf,
86 fbr.pos,
87 sentinel,
88 }) orelse return error.EndOfBuffer;
89 defer fbr.pos = end + 1;
90 return fbr.buf[fbr.pos..end :sentinel];
91}
lib/std/debug/SelfInfo.zig+1-1
...@@ -1576,7 +1576,7 @@ pub fn unwindFrameDwarf(...@@ -1576,7 +1576,7 @@ pub fn unwindFrameDwarf(
1576 const frame_section = di.section(dwarf_section) orelse return error.MissingFDE;1576 const frame_section = di.section(dwarf_section) orelse return error.MissingFDE;
1577 if (fde_offset >= frame_section.len) return error.MissingFDE;1577 if (fde_offset >= frame_section.len) return error.MissingFDE;
15781578
1579 var fbr: std.debug.DeprecatedFixedBufferReader = .{1579 var fbr: std.debug.FixedBufferReader = .{
1580 .buf = frame_section,1580 .buf = frame_section,
1581 .pos = fde_offset,1581 .pos = fde_offset,
1582 .endian = di.endian,1582 .endian = di.endian,