blob: a00f0c74a2a4cd6e7bb42db50855c7b7553cb829 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
//! Render Stack Trace
const serial = @import("../../drivers/serial/serial.zig");
const types = @import("../types/types.zig");
const Context = types.Context;
pub fn render(context: *const Context) void {
serial.printf("Stack Trace:\n", .{});
var rbp = context.rbp;
var depth: usize = 0;
const max_depth: usize = 20;
while (rbp != 0 and depth < max_depth) {
const frame_ptr: [*]const u64 = @ptrFromInt(rbp);
const return_address = frame_ptr[1];
if (return_address == 0) break;
serial.printf(" [%d] %x\n", .{ depth, return_address });
const next_rbp = frame_ptr[0];
if (next_rbp <= rbp) break;
rbp = next_rbp;
depth += 1;
}
if (depth == 0) {
serial.printf(" (no stack frames available)\n", .{});
}
serial.printf("\n", .{});
}
pub fn render_raw_stack(rsp: u64, count: usize) void {
serial.printf("Raw Stack (from %x):\n", .{rsp});
const stack_ptr: [*]const u64 = @ptrFromInt(rsp);
for (0..count) |i| {
serial.printf(" [%x]: %x\n", .{ rsp + i * 8, stack_ptr[i] });
}
serial.printf("\n", .{});
}
|