Commit a325d7f6d1
Changed files (3)
lib
std
lib/std/dwarf/expressions.zig
@@ -18,14 +18,14 @@ pub const StackMachineOptions = struct {
/// Expressions can be decoded for non-native address size and endianness,
/// but can only be executed if the current target matches the configuration.
pub fn StackMachine(comptime options: StackMachineOptions) type {
- const addr_type = switch(options.addr_size) {
+ const addr_type = switch (options.addr_size) {
2 => u16,
4 => u32,
8 => u64,
else => @compileError("Unsupported address size of " ++ options.addr_size),
};
- const addr_type_signed = switch(options.addr_size) {
+ const addr_type_signed = switch (options.addr_size) {
2 => i16,
4 => i32,
8 => i64,
@@ -61,19 +61,15 @@ pub fn StackMachine(comptime options: StackMachineOptions) type {
fn generic(value: anytype) Value {
const int_info = @typeInfo(@TypeOf(value)).Int;
if (@sizeOf(@TypeOf(value)) > options.addr_size) {
- return .{
- .generic = switch (int_info.signedness) {
- .signed => @bitCast(addr_type, @truncate(addr_type_signed, value)),
- .unsigned => @truncate(addr_type, value),
- }
- };
+ return .{ .generic = switch (int_info.signedness) {
+ .signed => @bitCast(addr_type, @truncate(addr_type_signed, value)),
+ .unsigned => @truncate(addr_type, value),
+ } };
} else {
- return .{
- .generic = switch (int_info.signedness) {
- .signed => @bitCast(addr_type, @intCast(addr_type_signed, value)),
- .unsigned => @intCast(addr_type, value),
- }
- };
+ return .{ .generic = switch (int_info.signedness) {
+ .signed => @bitCast(addr_type, @intCast(addr_type_signed, value)),
+ .unsigned => @intCast(addr_type, value),
+ } };
}
}
@@ -113,20 +109,15 @@ pub fn StackMachine(comptime options: StackMachineOptions) type {
=> generic(try leb.readILEB128(i64, reader)),
OP.lit0...OP.lit31 => |n| generic(n - OP.lit0),
OP.reg0...OP.reg31 => |n| .{ .register = n - OP.reg0 },
- OP.breg0...OP.breg31 => |n| .{
- .base_register = .{
- .base_register = n - OP.breg0,
- .offset = try leb.readILEB128(i64, reader),
- }
- },
+ OP.breg0...OP.breg31 => |n| .{ .base_register = .{
+ .base_register = n - OP.breg0,
+ .offset = try leb.readILEB128(i64, reader),
+ } },
OP.regx => .{ .register = try leb.readULEB128(u8, reader) },
- OP.bregx,
- OP.regval_type => .{
- .base_register = .{
- .base_register = try leb.readULEB128(u8, reader),
- .offset = try leb.readILEB128(i64, reader),
- }
- },
+ OP.bregx, OP.regval_type => .{ .base_register = .{
+ .base_register = try leb.readULEB128(u8, reader),
+ .offset = try leb.readILEB128(i64, reader),
+ } },
OP.piece => .{
.composite_location = .{
.size = try leb.readULEB128(u8, reader),
@@ -139,9 +130,7 @@ pub fn StackMachine(comptime options: StackMachineOptions) type {
.offset = try leb.readILEB128(i64, reader),
},
},
- OP.implicit_value,
- OP.entry_value
- => blk: {
+ OP.implicit_value, OP.entry_value => blk: {
const size = try leb.readULEB128(u8, reader);
if (stream.pos + size > stream.buffer.len) return error.InvalidExpression;
const block = stream.buffer[stream.pos..][0..size];
@@ -156,12 +145,10 @@ pub fn StackMachine(comptime options: StackMachineOptions) type {
if (stream.pos + size > stream.buffer.len) return error.InvalidExpression;
const value_bytes = stream.buffer[stream.pos..][0..size];
stream.pos += size;
- break :blk .{
- .base_type = .{
- .type_offset = type_offset,
- .value_bytes = value_bytes,
- }
- };
+ break :blk .{ .base_type = .{
+ .type_offset = type_offset,
+ .value_bytes = value_bytes,
+ } };
},
OP.deref_type,
OP.xderef_type,
lib/std/debug.zig
@@ -162,8 +162,6 @@ pub fn dumpStackTraceFromBase(context: anytype) void {
}
var it = StackIterator.initWithContext(null, debug_info, context) catch return;
-
- // TODO: Should `it.dwarf_context.pc` be `it.getIp()`? (but then the non-dwarf case has to store ip)
printSourceAtAddress(debug_info, stderr, it.dwarf_context.pc, tty_config) catch return;
while (it.next()) |return_address| {
@@ -528,7 +526,7 @@ pub const StackIterator = struct {
}
fn next_internal(self: *StackIterator) ?usize {
- if (self.debug_info != null) {
+ if (self.debug_info != null) {
if (self.next_dwarf()) |_| {
return self.dwarf_context.pc;
} else |err| {
@@ -2039,59 +2037,6 @@ fn dumpSegfaultInfoPosix(sig: i32, addr: usize, ctx_ptr: ?*const anyopaque) void
},
else => {},
}
-
- // TODO: Move this logic to dwarf.abi.regBytes
-
- // switch (native_arch) {
- // .x86 => {
- // const ctx = @ptrCast(*const os.ucontext_t, @alignCast(@alignOf(os.ucontext_t), ctx_ptr));
- // const ip = @intCast(usize, ctx.mcontext.gregs[os.REG.EIP]) ;
- // const bp = @intCast(usize, ctx.mcontext.gregs[os.REG.EBP]);
- // dumpStackTraceFromBase(bp, ip);
- // },
- // .x86_64 => {
- // const ctx = @ptrCast(*const os.ucontext_t, @alignCast(@alignOf(os.ucontext_t), ctx_ptr));
- // const ip = switch (native_os) {
- // .linux, .netbsd, .solaris => @intCast(usize, ctx.mcontext.gregs[os.REG.RIP]),
- // .freebsd => @intCast(usize, ctx.mcontext.rip),
- // .openbsd => @intCast(usize, ctx.sc_rip),
- // .macos => @intCast(usize, ctx.mcontext.ss.rip),
- // else => unreachable,
- // };
- // const bp = switch (native_os) {
- // .linux, .netbsd, .solaris => @intCast(usize, ctx.mcontext.gregs[os.REG.RBP]),
- // .openbsd => @intCast(usize, ctx.sc_rbp),
- // .freebsd => @intCast(usize, ctx.mcontext.rbp),
- // .macos => @intCast(usize, ctx.mcontext.ss.rbp),
- // else => unreachable,
- // };
- // dumpStackTraceFromBase(bp, ip);
- // },
- // .arm => {
- // const ctx = @ptrCast(*const os.ucontext_t, @alignCast(@alignOf(os.ucontext_t), ctx_ptr));
- // const ip = @intCast(usize, ctx.mcontext.arm_pc);
- // const bp = @intCast(usize, ctx.mcontext.arm_fp);
- // dumpStackTraceFromBase(bp, ip);
- // },
- // .aarch64 => {
- // const ctx = @ptrCast(*const os.ucontext_t, @alignCast(@alignOf(os.ucontext_t), ctx_ptr));
- // const ip = switch (native_os) {
- // .macos => @intCast(usize, ctx.mcontext.ss.pc),
- // .netbsd => @intCast(usize, ctx.mcontext.gregs[os.REG.PC]),
- // .freebsd => @intCast(usize, ctx.mcontext.gpregs.elr),
- // else => @intCast(usize, ctx.mcontext.pc),
- // };
- // // x29 is the ABI-designated frame pointer
- // const bp = switch (native_os) {
- // .macos => @intCast(usize, ctx.mcontext.ss.fp),
- // .netbsd => @intCast(usize, ctx.mcontext.gregs[os.REG.FP]),
- // .freebsd => @intCast(usize, ctx.mcontext.gpregs.x[os.REG.FP]),
- // else => @intCast(usize, ctx.mcontext.regs[29]),
- // };
- // dumpStackTraceFromBase(bp, ip);
- // },
- // else => {},
- // }
}
fn handleSegfaultWindows(info: *windows.EXCEPTION_POINTERS) callconv(windows.WINAPI) c_long {
lib/std/dwarf.zig
@@ -1603,7 +1603,6 @@ pub const DwarfInfo = struct {
// TODO: Evaluate expression
_ = expression;
return error.UnimplementedTODO;
-
},
else => return error.InvalidCFARule,
};