diff options
Diffstat (limited to 'src/host/probe.zig')
| -rw-r--r-- | src/host/probe.zig | 26 |
1 files changed, 24 insertions, 2 deletions
diff --git a/src/host/probe.zig b/src/host/probe.zig index 4a693ec..d8ed166 100644 --- a/src/host/probe.zig +++ b/src/host/probe.zig @@ -30,6 +30,8 @@ pub fn main(init: std.process.Init) !void { const file = path orelse fatal("no state file given"); const map = memory.mapReadOnly(file); if (map.len < memory.header_len) fatal("not a sketchbook state file"); + const magic = map[0..8]; + if (!std.mem.eql(u8, magic, &memory.file_magic) and !std.mem.eql(u8, magic, &memory.file_magic_v1)) fatal("not a sketchbook state file"); defer std.posix.munmap(map); var arena: std.heap.ArenaAllocator = .init(init.gpa); defer arena.deinit(); @@ -52,9 +54,29 @@ fn show(path: []const u8, layout: memory.Layout, live: []const u8) void { var w: std.Io.Writer = .fixed(&buf); std.debug.print("{s}: {d} bytes, layout {x:0>16}\n", .{ path, live.len, layout.hash }); for (layout.fields) |leaf| { + // Whole arrays are shown by their elements' leaves. + if (leaf.whole()) continue; w.end = 0; - fields.format(leaf, live, &w) catch {}; - std.debug.print(" +0x{x:0>4} {s:<28} {s}\n", .{ leaf.offset, leaf.path, w.buffered() }); + if (leaf.dims.len == 0) { + fields.format(leaf, live, &w) catch {}; + } else { + // Elements in index order, the first few. + var it = leaf.elements(); + var n: usize = 0; + while (it.next()) |offset| : (n += 1) { + if (n == 8) { + w.writeAll(" ...") catch {}; + break; + } + if (n > 0) w.writeAll(" ") catch {}; + fields.format(leaf.at(offset), live, &w) catch {}; + } + } + var name: [128]u8 = undefined; + var nw: std.Io.Writer = .fixed(&name); + nw.writeAll(leaf.path) catch {}; + for (leaf.dims) |d| nw.print(" [{d}]", .{d.count}) catch {}; + std.debug.print(" +0x{x:0>4} {s:<28} {s}\n", .{ leaf.offset, nw.buffered(), w.buffered() }); } } |
