|
|
@ -86,27 +86,27 @@ else
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/// The microzig default panic handler. Will disable interrupts and loop endlessly.
|
|
|
|
/// The microzig default panic handler. Will disable interrupts and loop endlessly.
|
|
|
|
pub fn microzig_panic(message: []const u8, maybe_stack_trace: ?*std.builtin.StackTrace, _: ?usize) noreturn {
|
|
|
|
pub fn microzig_panic(message: []const u8, _: ?*std.builtin.StackTrace, _: ?usize) noreturn {
|
|
|
|
|
|
|
|
|
|
|
|
// utilize logging functions
|
|
|
|
// utilize logging functions
|
|
|
|
std.log.err("microzig PANIC: {s}", .{message});
|
|
|
|
std.log.err("microzig PANIC: {s}", .{message});
|
|
|
|
|
|
|
|
|
|
|
|
if (builtin.cpu.arch != .avr) {
|
|
|
|
if (builtin.cpu.arch != .avr) {
|
|
|
|
var writer = debug.writer();
|
|
|
|
var index: usize = 0;
|
|
|
|
writer.print("microzig PANIC: {s}\r\n", .{message}) catch unreachable;
|
|
|
|
var iter = std.debug.StackIterator.init(@returnAddress(), null);
|
|
|
|
|
|
|
|
while (iter.next()) |address| : (index += 1) {
|
|
|
|
if (maybe_stack_trace) |stack_trace| {
|
|
|
|
if (index == 0) {
|
|
|
|
var frame_index: usize = 0;
|
|
|
|
std.log.err("stack trace:", .{});
|
|
|
|
var frames_left: usize = std.math.min(stack_trace.index, stack_trace.instruction_addresses.len);
|
|
|
|
|
|
|
|
while (frames_left != 0) : ({
|
|
|
|
|
|
|
|
frames_left -= 1;
|
|
|
|
|
|
|
|
frame_index = (frame_index + 1) % stack_trace.instruction_addresses.len;
|
|
|
|
|
|
|
|
}) {
|
|
|
|
|
|
|
|
const return_address = stack_trace.instruction_addresses[frame_index];
|
|
|
|
|
|
|
|
writer.print("0x{X:0>8}\r\n", .{return_address}) catch unreachable;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
std.log.err("{d: >3}: 0x{X:0>8}", .{ index, address });
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (@import("builtin").mode == .Debug) {
|
|
|
|
|
|
|
|
// attach a breakpoint, this might trigger another
|
|
|
|
|
|
|
|
// panic internally, so only do that in debug mode.
|
|
|
|
|
|
|
|
std.log.info("triggering breakpoint...", .{});
|
|
|
|
|
|
|
|
@breakpoint();
|
|
|
|
|
|
|
|
}
|
|
|
|
hang();
|
|
|
|
hang();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|