Skip to content

Commit 2aea7a4

Browse files
authored
Merge pull request #25493 from alexrp/std-debug-mips-ppc
`std.debug`: MIPS and PowerPC unwind support + some other stuff
2 parents e959a86 + a54906b commit 2aea7a4

File tree

9 files changed

+436
-81
lines changed

9 files changed

+436
-81
lines changed

lib/std/debug.zig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -623,7 +623,7 @@ pub const StackUnwindOptions = struct {
623623
/// the given buffer, so `addr_buf` must have a lifetime at least equal to the `StackTrace`.
624624
///
625625
/// See `writeCurrentStackTrace` to immediately print the trace instead of capturing it.
626-
pub fn captureCurrentStackTrace(options: StackUnwindOptions, addr_buf: []usize) std.builtin.StackTrace {
626+
pub noinline fn captureCurrentStackTrace(options: StackUnwindOptions, addr_buf: []usize) std.builtin.StackTrace {
627627
const empty_trace: std.builtin.StackTrace = .{ .index = 0, .instruction_addresses = &.{} };
628628
if (!std.options.allow_stack_tracing) return empty_trace;
629629
var it = StackIterator.init(options.context) catch return empty_trace;
@@ -661,7 +661,7 @@ pub fn captureCurrentStackTrace(options: StackUnwindOptions, addr_buf: []usize)
661661
/// Write the current stack trace to `writer`, annotated with source locations.
662662
///
663663
/// See `captureCurrentStackTrace` to capture the trace addresses into a buffer instead of printing.
664-
pub fn writeCurrentStackTrace(options: StackUnwindOptions, writer: *Writer, tty_config: tty.Config) Writer.Error!void {
664+
pub noinline fn writeCurrentStackTrace(options: StackUnwindOptions, writer: *Writer, tty_config: tty.Config) Writer.Error!void {
665665
if (!std.options.allow_stack_tracing) {
666666
tty_config.setColor(writer, .dim) catch {};
667667
try writer.print("Cannot print stack trace: stack tracing is disabled\n", .{});

lib/std/debug/Dwarf.zig

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1432,8 +1432,10 @@ pub fn ipRegNum(arch: std.Target.Cpu.Arch) ?u16 {
14321432
.aarch64, .aarch64_be => 32,
14331433
.arm, .armeb, .thumb, .thumbeb => 15,
14341434
.hexagon => 76,
1435-
.loongarch32, .loongarch64 => 32,
1436-
.riscv32, .riscv32be, .riscv64, .riscv64be => 32,
1435+
.loongarch32, .loongarch64 => 64,
1436+
.mips, .mipsel, .mips64, .mips64el => 66,
1437+
.powerpc, .powerpcle, .powerpc64, .powerpc64le => 67,
1438+
.riscv32, .riscv32be, .riscv64, .riscv64be => 65,
14371439
.s390x => 65,
14381440
.x86 => 8,
14391441
.x86_64 => 16,
@@ -1447,6 +1449,8 @@ pub fn fpRegNum(arch: std.Target.Cpu.Arch) u16 {
14471449
.arm, .armeb, .thumb, .thumbeb => 11,
14481450
.hexagon => 30,
14491451
.loongarch32, .loongarch64 => 22,
1452+
.mips, .mipsel, .mips64, .mips64el => 30,
1453+
.powerpc, .powerpcle, .powerpc64, .powerpc64le => 1,
14501454
.riscv32, .riscv32be, .riscv64, .riscv64be => 8,
14511455
.s390x => 11,
14521456
.x86 => 5,
@@ -1461,6 +1465,8 @@ pub fn spRegNum(arch: std.Target.Cpu.Arch) u16 {
14611465
.arm, .armeb, .thumb, .thumbeb => 13,
14621466
.hexagon => 29,
14631467
.loongarch32, .loongarch64 => 3,
1468+
.mips, .mipsel, .mips64, .mips64el => 29,
1469+
.powerpc, .powerpcle, .powerpc64, .powerpc64le => 1,
14641470
.riscv32, .riscv32be, .riscv64, .riscv64be => 2,
14651471
.s390x => 15,
14661472
.x86 => 4,

lib/std/debug/Dwarf/SelfUnwinder.zig

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,8 +229,10 @@ fn nextInner(unwinder: *SelfUnwinder, gpa: Allocator, cache_entry: *const CacheE
229229
} = switch (rule) {
230230
.default => val: {
231231
// The default rule is typically equivalent to `.undefined`, but ABIs may override it.
232-
if (builtin.cpu.arch.isAARCH64() and register >= 19 and register <= 28) {
233-
break :val .same;
232+
switch (builtin.target.cpu.arch) {
233+
.aarch64, .aarch64_be => if (register >= 19 and register <= 28) break :val .same,
234+
.s390x => if (register >= 6 and register <= 15) break :val .same,
235+
else => {},
234236
}
235237
break :val .undefined;
236238
},

lib/std/debug/Dwarf/expression.zig

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1160,22 +1160,19 @@ test "basics" {
11601160

11611161
mem.writeInt(usize, reg_bytes[0..@sizeOf(usize)], 0xee, native_endian);
11621162
(try regNative(&cpu_context, fp_reg_num)).* = 1;
1163-
(try regNative(&cpu_context, sp_reg_num)).* = 2;
1164-
(try regNative(&cpu_context, ip_reg_num)).* = 3;
1163+
(try regNative(&cpu_context, ip_reg_num)).* = 2;
11651164

11661165
try b.writeBreg(writer, fp_reg_num, @as(usize, 100));
1167-
try b.writeBreg(writer, sp_reg_num, @as(usize, 200));
1168-
try b.writeBregx(writer, ip_reg_num, @as(usize, 300));
1169-
try b.writeRegvalType(writer, @as(u8, 0), @as(usize, 400));
1166+
try b.writeBregx(writer, ip_reg_num, @as(usize, 200));
1167+
try b.writeRegvalType(writer, @as(u8, 0), @as(usize, 300));
11701168

11711169
_ = try stack_machine.run(program.written(), allocator, context, 0);
11721170

11731171
const regval_type = stack_machine.stack.pop().?.regval_type;
1174-
try testing.expectEqual(@as(usize, 400), regval_type.type_offset);
1172+
try testing.expectEqual(@as(usize, 300), regval_type.type_offset);
11751173
try testing.expectEqual(@as(u8, @sizeOf(usize)), regval_type.type_size);
11761174
try testing.expectEqual(@as(usize, 0xee), regval_type.value);
11771175

1178-
try testing.expectEqual(@as(usize, 303), stack_machine.stack.pop().?.generic);
11791176
try testing.expectEqual(@as(usize, 202), stack_machine.stack.pop().?.generic);
11801177
try testing.expectEqual(@as(usize, 101), stack_machine.stack.pop().?.generic);
11811178
}

lib/std/debug/SelfInfo/Elf.zig

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,14 @@ pub const can_unwind: bool = s: {
9999
.aarch64_be,
100100
.hexagon,
101101
.loongarch64,
102+
.mips,
103+
.mipsel,
104+
.mips64,
105+
.mips64el,
106+
.powerpc,
107+
.powerpcle,
108+
.powerpc64,
109+
.powerpc64le,
102110
.riscv32,
103111
.riscv64,
104112
.s390x,

0 commit comments

Comments
 (0)