authorgravatar for kcbanner@gmail.comCasey Banner <kcbanner@gmail.com> 2023-06-23 11:54:06-04:00
committergravatar for kcbanner@gmail.comCasey Banner <kcbanner@gmail.com> 2023-07-20 22:58:13-04:00
loga47212c72e9d156e06cb278ac681e51e11e140b7
tree189aab57b5b54081fb7d86a6a3d47dbe29707850
parentadbc5bbdb317847d1446395d24cd92c0ffc7fc49

- rebase and update to lastest master


3 files changed, 36 insertions(+), 38 deletions(-)

lib/std/debug.zig+13-15
......@@ -988,7 +988,7 @@ pub fn readElfDebugInfo(
988988 if (mem.eql(u8, name, ".gnu_debuglink")) {
989989 const gnu_debuglink = try chopSlice(mapped_mem, shdr.sh_offset, shdr.sh_size);
990990 const debug_filename = mem.sliceTo(@ptrCast([*:0]const u8, gnu_debuglink.ptr), 0);
991 const crc_offset = mem.alignForward(@ptrToInt(&debug_filename[debug_filename.len]) + 1, 4) - @ptrToInt(gnu_debuglink.ptr);
991 const crc_offset = mem.alignForward(usize, @intFromPtr(&debug_filename[debug_filename.len]) + 1, 4) - @intFromPtr(gnu_debuglink.ptr);
992992 const crc_bytes = gnu_debuglink[crc_offset .. crc_offset + 4];
993993 separate_debug_crc = mem.readIntSliceNative(u32, crc_bytes);
994994 separate_debug_filename = debug_filename;
......@@ -1007,11 +1007,9 @@ pub fn readElfDebugInfo(
10071007 var section_stream = io.fixedBufferStream(section_bytes);
10081008 var section_reader = section_stream.reader();
10091009 const chdr = section_reader.readStruct(elf.Chdr) catch continue;
1010
1011 // TODO: Support ZSTD
10121010 if (chdr.ch_type != .ZLIB) continue;
10131011
1014 var zlib_stream = std.compress.zlib.zlibStream(allocator, section_stream.reader()) catch continue;
1012 var zlib_stream = std.compress.zlib.decompressStream(allocator, section_stream.reader()) catch continue;
10151013 defer zlib_stream.deinit();
10161014
10171015 var decompressed_section = try allocator.alloc(u8, chdr.ch_size);
......@@ -1031,10 +1029,10 @@ pub fn readElfDebugInfo(
10311029 }
10321030
10331031 const missing_debug_info =
1034 sections[@enumToInt(DW.DwarfSection.debug_info)] == null or
1035 sections[@enumToInt(DW.DwarfSection.debug_abbrev)] == null or
1036 sections[@enumToInt(DW.DwarfSection.debug_str)] == null or
1037 sections[@enumToInt(DW.DwarfSection.debug_line)] == null;
1032 sections[@intFromEnum(DW.DwarfSection.debug_info)] == null or
1033 sections[@intFromEnum(DW.DwarfSection.debug_abbrev)] == null or
1034 sections[@intFromEnum(DW.DwarfSection.debug_str)] == null or
1035 sections[@intFromEnum(DW.DwarfSection.debug_line)] == null;
10381036
10391037 // Attempt to load debug info from an external file
10401038 // See: https://sourceware.org/gdb/onlinedocs/gdb/Separate-Debug-Files.html
......@@ -1537,7 +1535,7 @@ pub const DebugInfo = struct {
15371535 switch (phdr.p_type) {
15381536 elf.PT_NOTE => {
15391537 // Look for .note.gnu.build-id
1540 const note_bytes = @intToPtr([*]const u8, info.dlpi_addr + phdr.p_vaddr)[0..phdr.p_memsz];
1538 const note_bytes = @ptrFromInt([*]const u8, info.dlpi_addr + phdr.p_vaddr)[0..phdr.p_memsz];
15411539 const name_size = mem.readIntSliceNative(u32, note_bytes[0..4]);
15421540 if (name_size != 4) continue;
15431541 const desc_size = mem.readIntSliceNative(u32, note_bytes[4..8]);
......@@ -1547,7 +1545,7 @@ pub const DebugInfo = struct {
15471545 context.build_id = note_bytes[16..][0..desc_size];
15481546 },
15491547 elf.PT_GNU_EH_FRAME => {
1550 context.gnu_eh_frame = @intToPtr([*]const u8, info.dlpi_addr + phdr.p_vaddr)[0..phdr.p_memsz];
1548 context.gnu_eh_frame = @ptrFromInt([*]const u8, info.dlpi_addr + phdr.p_vaddr)[0..phdr.p_memsz];
15511549 },
15521550 else => {},
15531551 }
......@@ -1575,7 +1573,7 @@ pub const DebugInfo = struct {
15751573 // are encoded relative to its base address, so we must use the
15761574 // version that is already memory mapped, and not the one that
15771575 // will be mapped separately from the ELF file.
1578 sections[@enumToInt(DW.DwarfSection.eh_frame_hdr)] = .{
1576 sections[@intFromEnum(DW.DwarfSection.eh_frame_hdr)] = .{
15791577 .data = eh_frame_hdr,
15801578 .owned = false,
15811579 };
......@@ -1689,10 +1687,10 @@ pub const ModuleDebugInfo = switch (native_os) {
16891687 }
16901688
16911689 const missing_debug_info =
1692 sections[@enumToInt(DW.DwarfSection.debug_info)] == null or
1693 sections[@enumToInt(DW.DwarfSection.debug_abbrev)] == null or
1694 sections[@enumToInt(DW.DwarfSection.debug_str)] == null or
1695 sections[@enumToInt(DW.DwarfSection.debug_line)] == null;
1690 sections[@intFromEnum(DW.DwarfSection.debug_info)] == null or
1691 sections[@intFromEnum(DW.DwarfSection.debug_abbrev)] == null or
1692 sections[@intFromEnum(DW.DwarfSection.debug_str)] == null or
1693 sections[@intFromEnum(DW.DwarfSection.debug_line)] == null;
16961694 if (missing_debug_info) return error.MissingDebugInfo;
16971695
16981696 var di = DW.DwarfInfo{
lib/std/dwarf.zig+16-16
......@@ -691,7 +691,7 @@ pub const DwarfInfo = struct {
691691 is_macho: bool,
692692
693693 pub fn section(di: DwarfInfo, dwarf_section: DwarfSection) ?[]const u8 {
694 return if (di.sections[@enumToInt(dwarf_section)]) |s| s.data else null;
694 return if (di.sections[@intFromEnum(dwarf_section)]) |s| s.data else null;
695695 }
696696
697697 pub fn deinit(di: *DwarfInfo, allocator: mem.Allocator) void {
......@@ -1506,12 +1506,12 @@ pub const DwarfInfo = struct {
15061506 if (table_enc == EH.PE.omit) break :blk;
15071507
15081508 const eh_frame_ptr = std.math.cast(usize, try readEhPointer(reader, eh_frame_ptr_enc, @sizeOf(usize), .{
1509 .pc_rel_base = @ptrToInt(&eh_frame_hdr[stream.pos]),
1509 .pc_rel_base = @intFromPtr(&eh_frame_hdr[stream.pos]),
15101510 .follow_indirect = true,
15111511 }, builtin.cpu.arch.endian()) orelse return badDwarf()) orelse return badDwarf();
15121512
15131513 const fde_count = std.math.cast(usize, try readEhPointer(reader, fde_count_enc, @sizeOf(usize), .{
1514 .pc_rel_base = @ptrToInt(&eh_frame_hdr[stream.pos]),
1514 .pc_rel_base = @intFromPtr(&eh_frame_hdr[stream.pos]),
15151515 .follow_indirect = true,
15161516 }, builtin.cpu.arch.endian()) orelse return badDwarf()) orelse return badDwarf();
15171517
......@@ -1538,7 +1538,7 @@ pub const DwarfInfo = struct {
15381538 .cie => {
15391539 const cie = try CommonInformationEntry.parse(
15401540 entry_header.entry_bytes,
1541 -@intCast(isize, @ptrToInt(binary_mem.ptr)),
1541 -@intCast(isize, @intFromPtr(binary_mem.ptr)),
15421542 //@ptrToInt(eh_frame.ptr),
15431543 //@ptrToInt(eh_frame.ptr) - @ptrToInt(binary_mem.ptr),
15441544 true,
......@@ -1552,7 +1552,7 @@ pub const DwarfInfo = struct {
15521552 const cie = di.cie_map.get(cie_offset) orelse return badDwarf();
15531553 const fde = try FrameDescriptionEntry.parse(
15541554 entry_header.entry_bytes,
1555 -@intCast(isize, @ptrToInt(binary_mem.ptr)),
1555 -@intCast(isize, @intFromPtr(binary_mem.ptr)),
15561556 //@ptrToInt(eh_frame.ptr),
15571557 //@ptrToInt(eh_frame.ptr) - @ptrToInt(binary_mem.ptr),
15581558 true,
......@@ -1594,7 +1594,7 @@ pub const DwarfInfo = struct {
15941594
15951595 if (di.eh_frame_hdr) |header| {
15961596 mapped_pc = context.pc;
1597 try header.findEntry(context.isValidMemory, @ptrToInt(di.section(.eh_frame_hdr).?.ptr), mapped_pc, &cie, &fde);
1597 try header.findEntry(context.isValidMemory, @intFromPtr(di.section(.eh_frame_hdr).?.ptr), mapped_pc, &cie, &fde);
15981598 } else {
15991599 mapped_pc = context.pc - module_base_address;
16001600 const index = std.sort.binarySearch(FrameDescriptionEntry, mapped_pc, di.fde_list.items, {}, struct {
......@@ -1790,7 +1790,7 @@ fn readEhPointer(reader: anytype, enc: u8, addr_size_bytes: u8, ctx: EhPointerCo
17901790
17911791 const native_ptr = math.cast(usize, ptr) orelse return error.PointerOverflow;
17921792 return switch (addr_size_bytes) {
1793 2, 4, 8 => return @intToPtr(*const usize, native_ptr).*,
1793 2, 4, 8 => return @ptrFromInt(*const usize, native_ptr).*,
17941794 else => return error.UnsupportedAddrSize,
17951795 };
17961796 } else {
......@@ -1842,7 +1842,7 @@ pub const ExceptionFrameHeader = struct {
18421842
18431843 try stream.seekTo(mid * entry_size);
18441844 const pc_begin = try readEhPointer(reader, self.table_enc, @sizeOf(usize), .{
1845 .pc_rel_base = @ptrToInt(&self.entries[stream.pos]),
1845 .pc_rel_base = @intFromPtr(&self.entries[stream.pos]),
18461846 .follow_indirect = true,
18471847 .data_rel_base = eh_frame_hdr_ptr,
18481848 }, builtin.cpu.arch.endian()) orelse return badDwarf();
......@@ -1857,13 +1857,13 @@ pub const ExceptionFrameHeader = struct {
18571857
18581858 // Read past pc_begin
18591859 _ = try readEhPointer(reader, self.table_enc, @sizeOf(usize), .{
1860 .pc_rel_base = @ptrToInt(&self.entries[stream.pos]),
1860 .pc_rel_base = @intFromPtr(&self.entries[stream.pos]),
18611861 .follow_indirect = true,
18621862 .data_rel_base = eh_frame_hdr_ptr,
18631863 }, builtin.cpu.arch.endian()) orelse return badDwarf();
18641864
18651865 const fde_ptr = math.cast(usize, try readEhPointer(reader, self.table_enc, @sizeOf(usize), .{
1866 .pc_rel_base = @ptrToInt(&self.entries[stream.pos]),
1866 .pc_rel_base = @intFromPtr(&self.entries[stream.pos]),
18671867 .follow_indirect = true,
18681868 .data_rel_base = eh_frame_hdr_ptr,
18691869 }, builtin.cpu.arch.endian()) orelse return badDwarf()) orelse return badDwarf();
......@@ -1872,20 +1872,20 @@ pub const ExceptionFrameHeader = struct {
18721872
18731873 // The length of the .eh_frame section is unknown at this point, since .eh_frame_hdr only provides the start
18741874 if (!isValidMemory(fde_ptr) or fde_ptr < self.eh_frame_ptr) return badDwarf();
1875 const eh_frame = @intToPtr([*]const u8, self.eh_frame_ptr)[0..math.maxInt(usize)];
1875 const eh_frame = @ptrFromInt([*]const u8, self.eh_frame_ptr)[0..math.maxInt(usize)];
18761876 const fde_offset = fde_ptr - self.eh_frame_ptr;
18771877
18781878 var eh_frame_stream = io.fixedBufferStream(eh_frame);
18791879 try eh_frame_stream.seekTo(fde_offset);
18801880
18811881 const fde_entry_header = try EntryHeader.read(&eh_frame_stream, builtin.cpu.arch.endian());
1882 if (!isValidMemory(@ptrToInt(&fde_entry_header.entry_bytes[fde_entry_header.entry_bytes.len - 1]))) return badDwarf();
1882 if (!isValidMemory(@intFromPtr(&fde_entry_header.entry_bytes[fde_entry_header.entry_bytes.len - 1]))) return badDwarf();
18831883 if (fde_entry_header.type != .fde) return badDwarf();
18841884
18851885 const cie_offset = fde_entry_header.type.fde;
18861886 try eh_frame_stream.seekTo(cie_offset);
18871887 const cie_entry_header = try EntryHeader.read(&eh_frame_stream, builtin.cpu.arch.endian());
1888 if (!isValidMemory(@ptrToInt(&cie_entry_header.entry_bytes[cie_entry_header.entry_bytes.len - 1]))) return badDwarf();
1888 if (!isValidMemory(@intFromPtr(&cie_entry_header.entry_bytes[cie_entry_header.entry_bytes.len - 1]))) return badDwarf();
18891889 if (cie_entry_header.type != .cie) return badDwarf();
18901890
18911891 cie.* = try CommonInformationEntry.parse(
......@@ -2083,7 +2083,7 @@ pub const CommonInformationEntry = struct {
20832083 personality_enc.?,
20842084 addr_size_bytes,
20852085 .{
2086 .pc_rel_base = try pcRelBase(@ptrToInt(&cie_bytes[stream.pos]), pc_rel_offset),
2086 .pc_rel_base = try pcRelBase(@intFromPtr(&cie_bytes[stream.pos]), pc_rel_offset),
20872087 .follow_indirect = is_runtime,
20882088 },
20892089 endian,
......@@ -2161,7 +2161,7 @@ pub const FrameDescriptionEntry = struct {
21612161 cie.fde_pointer_enc,
21622162 addr_size_bytes,
21632163 .{
2164 .pc_rel_base = try pcRelBase(@ptrToInt(&fde_bytes[stream.pos]), pc_rel_offset),
2164 .pc_rel_base = try pcRelBase(@intFromPtr(&fde_bytes[stream.pos]), pc_rel_offset),
21652165 .follow_indirect = is_runtime,
21662166 },
21672167 endian,
......@@ -2190,7 +2190,7 @@ pub const FrameDescriptionEntry = struct {
21902190 cie.lsda_pointer_enc,
21912191 addr_size_bytes,
21922192 .{
2193 .pc_rel_base = try pcRelBase(@ptrToInt(&fde_bytes[stream.pos]), pc_rel_offset),
2193 .pc_rel_base = try pcRelBase(@intFromPtr(&fde_bytes[stream.pos]), pc_rel_offset),
21942194 .follow_indirect = is_runtime,
21952195 },
21962196 endian,
lib/std/dwarf/call_frame.zig+7-7
......@@ -38,12 +38,12 @@ const Opcode = enum(u8) {
3838 val_expression = 0x16,
3939
4040 // These opcodes encode an operand in the lower 6 bits of the opcode itself
41 pub const lo_inline = @enumToInt(Opcode.advance_loc);
42 pub const hi_inline = @enumToInt(Opcode.restore) | 0b111111;
41 pub const lo_inline = @intFromEnum(Opcode.advance_loc);
42 pub const hi_inline = @intFromEnum(Opcode.restore) | 0b111111;
4343
4444 // These opcodes are trailed by zero or more operands
45 pub const lo_reserved = @enumToInt(Opcode.nop);
46 pub const hi_reserved = @enumToInt(Opcode.val_expression);
45 pub const lo_reserved = @intFromEnum(Opcode.nop);
46 pub const hi_reserved = @intFromEnum(Opcode.val_expression);
4747
4848 // Vendor-specific opcodes
4949 pub const lo_user = 0x1c;
......@@ -206,13 +206,13 @@ pub const Instruction = union(Opcode) {
206206 ) !Instruction {
207207 return switch (try stream.reader().readByte()) {
208208 inline Opcode.lo_inline...Opcode.hi_inline => |opcode| blk: {
209 const e = @intToEnum(Opcode, opcode & 0b11000000);
209 const e = @enumFromInt(Opcode, opcode & 0b11000000);
210210 var result = @unionInit(Instruction, @tagName(e), undefined);
211211 try result.readOperands(stream, @intCast(u6, opcode & 0b111111), addr_size_bytes, endian);
212212 break :blk result;
213213 },
214214 inline Opcode.lo_reserved...Opcode.hi_reserved => |opcode| blk: {
215 const e = @intToEnum(Opcode, opcode);
215 const e = @enumFromInt(Opcode, opcode);
216216 var result = @unionInit(Instruction, @tagName(e), undefined);
217217 try result.readOperands(stream, null, addr_size_bytes, endian);
218218 break :blk result;
......@@ -304,7 +304,7 @@ pub const VirtualMachine = struct {
304304 .same_value => {},
305305 .offset => |offset| {
306306 if (context.cfa) |cfa| {
307 const ptr = @intToPtr(*const usize, try applyOffset(cfa, offset));
307 const ptr = @ptrFromInt(*const usize, try applyOffset(cfa, offset));
308308
309309 // TODO: context.isValidMemory(ptr)
310310 mem.writeIntSliceNative(usize, out, ptr.*);