authorgravatar for kcbanner@gmail.comCasey Banner <kcbanner@gmail.com> 2023-05-22 19:24:43-04:00
committergravatar for kcbanner@gmail.comCasey Banner <kcbanner@gmail.com> 2023-07-20 22:58:13-04:00
loga325d7f6d197f7ec1bb6b658075feb8b9e30a264
tree3cc1aef83702d9b90f58281d5af1443a39843169
parentc98e03fc7ed509536076132fe9ea5d9d00038c23

fmt and cleanup


3 files changed, 24 insertions(+), 93 deletions(-)

lib/std/debug.zig+1-56
...@@ -162,8 +162,6 @@ pub fn dumpStackTraceFromBase(context: anytype) void {...@@ -162,8 +162,6 @@ pub fn dumpStackTraceFromBase(context: anytype) void {
162 }162 }
163163
164 var it = StackIterator.initWithContext(null, debug_info, context) catch return;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 printSourceAtAddress(debug_info, stderr, it.dwarf_context.pc, tty_config) catch return;165 printSourceAtAddress(debug_info, stderr, it.dwarf_context.pc, tty_config) catch return;
168166
169 while (it.next()) |return_address| {167 while (it.next()) |return_address| {
...@@ -528,7 +526,7 @@ pub const StackIterator = struct {...@@ -528,7 +526,7 @@ pub const StackIterator = struct {
528 }526 }
529527
530 fn next_internal(self: *StackIterator) ?usize {528 fn next_internal(self: *StackIterator) ?usize {
531 if (self.debug_info != null) {529 if (self.debug_info != null) {
532 if (self.next_dwarf()) |_| {530 if (self.next_dwarf()) |_| {
533 return self.dwarf_context.pc;531 return self.dwarf_context.pc;
534 } else |err| {532 } else |err| {
...@@ -2039,59 +2037,6 @@ fn dumpSegfaultInfoPosix(sig: i32, addr: usize, ctx_ptr: ?*const anyopaque) void...@@ -2039,59 +2037,6 @@ fn dumpSegfaultInfoPosix(sig: i32, addr: usize, ctx_ptr: ?*const anyopaque) void
2039 },2037 },
2040 else => {},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}
20962041
2097fn handleSegfaultWindows(info: *windows.EXCEPTION_POINTERS) callconv(windows.WINAPI) c_long {2042fn handleSegfaultWindows(info: *windows.EXCEPTION_POINTERS) callconv(windows.WINAPI) c_long {
lib/std/dwarf.zig-1
...@@ -1603,7 +1603,6 @@ pub const DwarfInfo = struct {...@@ -1603,7 +1603,6 @@ pub const DwarfInfo = struct {
1603 // TODO: Evaluate expression1603 // TODO: Evaluate expression
1604 _ = expression;1604 _ = expression;
1605 return error.UnimplementedTODO;1605 return error.UnimplementedTODO;
1606
1607 },1606 },
1608 else => return error.InvalidCFARule,1607 else => return error.InvalidCFARule,
1609 };1608 };
lib/std/dwarf/expressions.zig+23-36
...@@ -18,14 +18,14 @@ pub const StackMachineOptions = struct {...@@ -18,14 +18,14 @@ pub const StackMachineOptions = struct {
18/// Expressions can be decoded for non-native address size and endianness,18/// Expressions can be decoded for non-native address size and endianness,
19/// but can only be executed if the current target matches the configuration.19/// but can only be executed if the current target matches the configuration.
20pub fn StackMachine(comptime options: StackMachineOptions) type {20pub fn StackMachine(comptime options: StackMachineOptions) type {
21 const addr_type = switch(options.addr_size) {21 const addr_type = switch (options.addr_size) {
22 2 => u16,22 2 => u16,
23 4 => u32,23 4 => u32,
24 8 => u64,24 8 => u64,
25 else => @compileError("Unsupported address size of " ++ options.addr_size),25 else => @compileError("Unsupported address size of " ++ options.addr_size),
26 };26 };
2727
28 const addr_type_signed = switch(options.addr_size) {28 const addr_type_signed = switch (options.addr_size) {
29 2 => i16,29 2 => i16,
30 4 => i32,30 4 => i32,
31 8 => i64,31 8 => i64,
...@@ -61,19 +61,15 @@ pub fn StackMachine(comptime options: StackMachineOptions) type {...@@ -61,19 +61,15 @@ pub fn StackMachine(comptime options: StackMachineOptions) type {
61 fn generic(value: anytype) Value {61 fn generic(value: anytype) Value {
62 const int_info = @typeInfo(@TypeOf(value)).Int;62 const int_info = @typeInfo(@TypeOf(value)).Int;
63 if (@sizeOf(@TypeOf(value)) > options.addr_size) {63 if (@sizeOf(@TypeOf(value)) > options.addr_size) {
64 return .{64 return .{ .generic = switch (int_info.signedness) {
65 .generic = switch (int_info.signedness) {65 .signed => @bitCast(addr_type, @truncate(addr_type_signed, value)),
66 .signed => @bitCast(addr_type, @truncate(addr_type_signed, value)),66 .unsigned => @truncate(addr_type, value),
67 .unsigned => @truncate(addr_type, value),67 } };
68 }
69 };
70 } else {68 } else {
71 return .{69 return .{ .generic = switch (int_info.signedness) {
72 .generic = switch (int_info.signedness) {70 .signed => @bitCast(addr_type, @intCast(addr_type_signed, value)),
73 .signed => @bitCast(addr_type, @intCast(addr_type_signed, value)),71 .unsigned => @intCast(addr_type, value),
74 .unsigned => @intCast(addr_type, value),72 } };
75 }
76 };
77 }73 }
78 }74 }
7975
...@@ -113,20 +109,15 @@ pub fn StackMachine(comptime options: StackMachineOptions) type {...@@ -113,20 +109,15 @@ pub fn StackMachine(comptime options: StackMachineOptions) type {
113 => generic(try leb.readILEB128(i64, reader)),109 => generic(try leb.readILEB128(i64, reader)),
114 OP.lit0...OP.lit31 => |n| generic(n - OP.lit0),110 OP.lit0...OP.lit31 => |n| generic(n - OP.lit0),
115 OP.reg0...OP.reg31 => |n| .{ .register = n - OP.reg0 },111 OP.reg0...OP.reg31 => |n| .{ .register = n - OP.reg0 },
116 OP.breg0...OP.breg31 => |n| .{112 OP.breg0...OP.breg31 => |n| .{ .base_register = .{
117 .base_register = .{113 .base_register = n - OP.breg0,
118 .base_register = n - OP.breg0,114 .offset = try leb.readILEB128(i64, reader),
119 .offset = try leb.readILEB128(i64, reader),115 } },
120 }
121 },
122 OP.regx => .{ .register = try leb.readULEB128(u8, reader) },116 OP.regx => .{ .register = try leb.readULEB128(u8, reader) },
123 OP.bregx,117 OP.bregx, OP.regval_type => .{ .base_register = .{
124 OP.regval_type => .{118 .base_register = try leb.readULEB128(u8, reader),
125 .base_register = .{119 .offset = try leb.readILEB128(i64, reader),
126 .base_register = try leb.readULEB128(u8, reader),120 } },
127 .offset = try leb.readILEB128(i64, reader),
128 }
129 },
130 OP.piece => .{121 OP.piece => .{
131 .composite_location = .{122 .composite_location = .{
132 .size = try leb.readULEB128(u8, reader),123 .size = try leb.readULEB128(u8, reader),
...@@ -139,9 +130,7 @@ pub fn StackMachine(comptime options: StackMachineOptions) type {...@@ -139,9 +130,7 @@ pub fn StackMachine(comptime options: StackMachineOptions) type {
139 .offset = try leb.readILEB128(i64, reader),130 .offset = try leb.readILEB128(i64, reader),
140 },131 },
141 },132 },
142 OP.implicit_value,133 OP.implicit_value, OP.entry_value => blk: {
143 OP.entry_value
144 => blk: {
145 const size = try leb.readULEB128(u8, reader);134 const size = try leb.readULEB128(u8, reader);
146 if (stream.pos + size > stream.buffer.len) return error.InvalidExpression;135 if (stream.pos + size > stream.buffer.len) return error.InvalidExpression;
147 const block = stream.buffer[stream.pos..][0..size];136 const block = stream.buffer[stream.pos..][0..size];
...@@ -156,12 +145,10 @@ pub fn StackMachine(comptime options: StackMachineOptions) type {...@@ -156,12 +145,10 @@ pub fn StackMachine(comptime options: StackMachineOptions) type {
156 if (stream.pos + size > stream.buffer.len) return error.InvalidExpression;145 if (stream.pos + size > stream.buffer.len) return error.InvalidExpression;
157 const value_bytes = stream.buffer[stream.pos..][0..size];146 const value_bytes = stream.buffer[stream.pos..][0..size];
158 stream.pos += size;147 stream.pos += size;
159 break :blk .{148 break :blk .{ .base_type = .{
160 .base_type = .{149 .type_offset = type_offset,
161 .type_offset = type_offset,150 .value_bytes = value_bytes,
162 .value_bytes = value_bytes,151 } };
163 }
164 };
165 },152 },
166 OP.deref_type,153 OP.deref_type,
167 OP.xderef_type,154 OP.xderef_type,