| author | |
| committer | |
| log | a325d7f6d197f7ec1bb6b658075feb8b9e30a264 |
| tree | 3cc1aef83702d9b90f58281d5af1443a39843169 |
| parent | c98e03fc7ed509536076132fe9ea5d9d00038c23 |
3 files changed, 24 insertions(+), 93 deletions(-)
lib/std/debug.zig+1-56| ... | ... | @@ -162,8 +162,6 @@ pub fn dumpStackTraceFromBase(context: anytype) void { |
| 162 | 162 | } |
| 163 | 163 | |
| 164 | 164 | var it = StackIterator.initWithContext(null, debug_info, context) catch return; |
| 165 | ||
| 166 | // TODO: Should `it.dwarf_context.pc` be `it.getIp()`? (but then the non-dwarf case has to store ip) | |
| 167 | 165 | printSourceAtAddress(debug_info, stderr, it.dwarf_context.pc, tty_config) catch return; |
| 168 | 166 | |
| 169 | 167 | while (it.next()) |return_address| { |
| ... | ... | @@ -528,7 +526,7 @@ pub const StackIterator = struct { |
| 528 | 526 | } |
| 529 | 527 | |
| 530 | 528 | fn next_internal(self: *StackIterator) ?usize { |
| 531 | if (self.debug_info != null) { | |
| 529 | if (self.debug_info != null) { | |
| 532 | 530 | if (self.next_dwarf()) |_| { |
| 533 | 531 | return self.dwarf_context.pc; |
| 534 | 532 | } else |err| { |
| ... | ... | @@ -2039,59 +2037,6 @@ fn dumpSegfaultInfoPosix(sig: i32, addr: usize, ctx_ptr: ?*const anyopaque) void |
| 2039 | 2037 | }, |
| 2040 | 2038 | else => {}, |
| 2041 | 2039 | } |
| 2042 | ||
| 2043 | // TODO: Move this logic to dwarf.abi.regBytes | |
| 2044 | ||
| 2045 | // switch (native_arch) { | |
| 2046 | // .x86 => { | |
| 2047 | // const ctx = @ptrCast(*const os.ucontext_t, @alignCast(@alignOf(os.ucontext_t), ctx_ptr)); | |
| 2048 | // const ip = @intCast(usize, ctx.mcontext.gregs[os.REG.EIP]) ; | |
| 2049 | // const bp = @intCast(usize, ctx.mcontext.gregs[os.REG.EBP]); | |
| 2050 | // dumpStackTraceFromBase(bp, ip); | |
| 2051 | // }, | |
| 2052 | // .x86_64 => { | |
| 2053 | // const ctx = @ptrCast(*const os.ucontext_t, @alignCast(@alignOf(os.ucontext_t), ctx_ptr)); | |
| 2054 | // const ip = switch (native_os) { | |
| 2055 | // .linux, .netbsd, .solaris => @intCast(usize, ctx.mcontext.gregs[os.REG.RIP]), | |
| 2056 | // .freebsd => @intCast(usize, ctx.mcontext.rip), | |
| 2057 | // .openbsd => @intCast(usize, ctx.sc_rip), | |
| 2058 | // .macos => @intCast(usize, ctx.mcontext.ss.rip), | |
| 2059 | // else => unreachable, | |
| 2060 | // }; | |
| 2061 | // const bp = switch (native_os) { | |
| 2062 | // .linux, .netbsd, .solaris => @intCast(usize, ctx.mcontext.gregs[os.REG.RBP]), | |
| 2063 | // .openbsd => @intCast(usize, ctx.sc_rbp), | |
| 2064 | // .freebsd => @intCast(usize, ctx.mcontext.rbp), | |
| 2065 | // .macos => @intCast(usize, ctx.mcontext.ss.rbp), | |
| 2066 | // else => unreachable, | |
| 2067 | // }; | |
| 2068 | // dumpStackTraceFromBase(bp, ip); | |
| 2069 | // }, | |
| 2070 | // .arm => { | |
| 2071 | // const ctx = @ptrCast(*const os.ucontext_t, @alignCast(@alignOf(os.ucontext_t), ctx_ptr)); | |
| 2072 | // const ip = @intCast(usize, ctx.mcontext.arm_pc); | |
| 2073 | // const bp = @intCast(usize, ctx.mcontext.arm_fp); | |
| 2074 | // dumpStackTraceFromBase(bp, ip); | |
| 2075 | // }, | |
| 2076 | // .aarch64 => { | |
| 2077 | // const ctx = @ptrCast(*const os.ucontext_t, @alignCast(@alignOf(os.ucontext_t), ctx_ptr)); | |
| 2078 | // const ip = switch (native_os) { | |
| 2079 | // .macos => @intCast(usize, ctx.mcontext.ss.pc), | |
| 2080 | // .netbsd => @intCast(usize, ctx.mcontext.gregs[os.REG.PC]), | |
| 2081 | // .freebsd => @intCast(usize, ctx.mcontext.gpregs.elr), | |
| 2082 | // else => @intCast(usize, ctx.mcontext.pc), | |
| 2083 | // }; | |
| 2084 | // // x29 is the ABI-designated frame pointer | |
| 2085 | // const bp = switch (native_os) { | |
| 2086 | // .macos => @intCast(usize, ctx.mcontext.ss.fp), | |
| 2087 | // .netbsd => @intCast(usize, ctx.mcontext.gregs[os.REG.FP]), | |
| 2088 | // .freebsd => @intCast(usize, ctx.mcontext.gpregs.x[os.REG.FP]), | |
| 2089 | // else => @intCast(usize, ctx.mcontext.regs[29]), | |
| 2090 | // }; | |
| 2091 | // dumpStackTraceFromBase(bp, ip); | |
| 2092 | // }, | |
| 2093 | // else => {}, | |
| 2094 | // } | |
| 2095 | 2040 | } |
| 2096 | 2041 | |
| 2097 | 2042 | fn handleSegfaultWindows(info: *windows.EXCEPTION_POINTERS) callconv(windows.WINAPI) c_long { |
lib/std/dwarf.zig-1| ... | ... | @@ -1603,7 +1603,6 @@ pub const DwarfInfo = struct { |
| 1603 | 1603 | // TODO: Evaluate expression |
| 1604 | 1604 | _ = expression; |
| 1605 | 1605 | return error.UnimplementedTODO; |
| 1606 | ||
| 1607 | 1606 | }, |
| 1608 | 1607 | else => return error.InvalidCFARule, |
| 1609 | 1608 | }; |
lib/std/dwarf/expressions.zig+23-36| ... | ... | @@ -18,14 +18,14 @@ pub const StackMachineOptions = struct { |
| 18 | 18 | /// Expressions can be decoded for non-native address size and endianness, |
| 19 | 19 | /// but can only be executed if the current target matches the configuration. |
| 20 | 20 | pub fn StackMachine(comptime options: StackMachineOptions) type { |
| 21 | const addr_type = switch(options.addr_size) { | |
| 21 | const addr_type = switch (options.addr_size) { | |
| 22 | 22 | 2 => u16, |
| 23 | 23 | 4 => u32, |
| 24 | 24 | 8 => u64, |
| 25 | 25 | else => @compileError("Unsupported address size of " ++ options.addr_size), |
| 26 | 26 | }; |
| 27 | 27 | |
| 28 | const addr_type_signed = switch(options.addr_size) { | |
| 28 | const addr_type_signed = switch (options.addr_size) { | |
| 29 | 29 | 2 => i16, |
| 30 | 30 | 4 => i32, |
| 31 | 31 | 8 => i64, |
| ... | ... | @@ -61,19 +61,15 @@ pub fn StackMachine(comptime options: StackMachineOptions) type { |
| 61 | 61 | fn generic(value: anytype) Value { |
| 62 | 62 | const int_info = @typeInfo(@TypeOf(value)).Int; |
| 63 | 63 | if (@sizeOf(@TypeOf(value)) > options.addr_size) { |
| 64 | return .{ | |
| 65 | .generic = switch (int_info.signedness) { | |
| 66 | .signed => @bitCast(addr_type, @truncate(addr_type_signed, value)), | |
| 67 | .unsigned => @truncate(addr_type, value), | |
| 68 | } | |
| 69 | }; | |
| 64 | return .{ .generic = switch (int_info.signedness) { | |
| 65 | .signed => @bitCast(addr_type, @truncate(addr_type_signed, value)), | |
| 66 | .unsigned => @truncate(addr_type, value), | |
| 67 | } }; | |
| 70 | 68 | } else { |
| 71 | return .{ | |
| 72 | .generic = switch (int_info.signedness) { | |
| 73 | .signed => @bitCast(addr_type, @intCast(addr_type_signed, value)), | |
| 74 | .unsigned => @intCast(addr_type, value), | |
| 75 | } | |
| 76 | }; | |
| 69 | return .{ .generic = switch (int_info.signedness) { | |
| 70 | .signed => @bitCast(addr_type, @intCast(addr_type_signed, value)), | |
| 71 | .unsigned => @intCast(addr_type, value), | |
| 72 | } }; | |
| 77 | 73 | } |
| 78 | 74 | } |
| 79 | 75 | |
| ... | ... | @@ -113,20 +109,15 @@ pub fn StackMachine(comptime options: StackMachineOptions) type { |
| 113 | 109 | => generic(try leb.readILEB128(i64, reader)), |
| 114 | 110 | OP.lit0...OP.lit31 => |n| generic(n - OP.lit0), |
| 115 | 111 | OP.reg0...OP.reg31 => |n| .{ .register = n - OP.reg0 }, |
| 116 | OP.breg0...OP.breg31 => |n| .{ | |
| 117 | .base_register = .{ | |
| 118 | .base_register = n - OP.breg0, | |
| 119 | .offset = try leb.readILEB128(i64, reader), | |
| 120 | } | |
| 121 | }, | |
| 112 | OP.breg0...OP.breg31 => |n| .{ .base_register = .{ | |
| 113 | .base_register = n - OP.breg0, | |
| 114 | .offset = try leb.readILEB128(i64, reader), | |
| 115 | } }, | |
| 122 | 116 | OP.regx => .{ .register = try leb.readULEB128(u8, reader) }, |
| 123 | OP.bregx, | |
| 124 | OP.regval_type => .{ | |
| 125 | .base_register = .{ | |
| 126 | .base_register = try leb.readULEB128(u8, reader), | |
| 127 | .offset = try leb.readILEB128(i64, reader), | |
| 128 | } | |
| 129 | }, | |
| 117 | OP.bregx, OP.regval_type => .{ .base_register = .{ | |
| 118 | .base_register = try leb.readULEB128(u8, reader), | |
| 119 | .offset = try leb.readILEB128(i64, reader), | |
| 120 | } }, | |
| 130 | 121 | OP.piece => .{ |
| 131 | 122 | .composite_location = .{ |
| 132 | 123 | .size = try leb.readULEB128(u8, reader), |
| ... | ... | @@ -139,9 +130,7 @@ pub fn StackMachine(comptime options: StackMachineOptions) type { |
| 139 | 130 | .offset = try leb.readILEB128(i64, reader), |
| 140 | 131 | }, |
| 141 | 132 | }, |
| 142 | OP.implicit_value, | |
| 143 | OP.entry_value | |
| 144 | => blk: { | |
| 133 | OP.implicit_value, OP.entry_value => blk: { | |
| 145 | 134 | const size = try leb.readULEB128(u8, reader); |
| 146 | 135 | if (stream.pos + size > stream.buffer.len) return error.InvalidExpression; |
| 147 | 136 | const block = stream.buffer[stream.pos..][0..size]; |
| ... | ... | @@ -156,12 +145,10 @@ pub fn StackMachine(comptime options: StackMachineOptions) type { |
| 156 | 145 | if (stream.pos + size > stream.buffer.len) return error.InvalidExpression; |
| 157 | 146 | const value_bytes = stream.buffer[stream.pos..][0..size]; |
| 158 | 147 | stream.pos += size; |
| 159 | break :blk .{ | |
| 160 | .base_type = .{ | |
| 161 | .type_offset = type_offset, | |
| 162 | .value_bytes = value_bytes, | |
| 163 | } | |
| 164 | }; | |
| 148 | break :blk .{ .base_type = .{ | |
| 149 | .type_offset = type_offset, | |
| 150 | .value_bytes = value_bytes, | |
| 151 | } }; | |
| 165 | 152 | }, |
| 166 | 153 | OP.deref_type, |
| 167 | 154 | OP.xderef_type, |