From 4f31aaef1338b53195f8c475db5a72d75cc1fc82 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Fri, 13 Nov 2026 12:18:26 -0300 Subject: debugger: add refractive lenses and configurable memory values Use disassembly lenses for executable pointers, browse surrounding segment context, and keep the reading surface opaque with GPU refraction at the edges. Route right-clicks by stack mapping and expose byte-width and numeric-format controls. Replace matching-address arrows with staggered shared-renderer highlights. Verified GUI and renderer suites, native restart/zoom cycles, independent float-extrema and popup review, and a live wrong-map stop at Deoptimizer::New with JS origin context. Requires Sketchbook 409c1ac. --- gui/src/app.zig | 227 ++++++++++++++++++++++++++++++++++++++++------------- gui/src/glass.frag | 27 +++++++ 2 files changed, 201 insertions(+), 53 deletions(-) create mode 100644 gui/src/glass.frag (limited to 'gui/src') diff --git a/gui/src/app.zig b/gui/src/app.zig index bed93f4..c9600b8 100644 --- a/gui/src/app.zig +++ b/gui/src/app.zig @@ -36,6 +36,11 @@ pub const State = struct { annotations: bool = true, depth: u8 = 4, ascii: bool = true, + unit: u8 = 1, + number_format: canim.rows.NumberFormat = .hex, + selected_address: u64 = 0, + selected_box: Box = .{}, + glass: bool = true, zoom: u16 = 100, page_scroll: f32 = 0, register_scroll: f32 = 0, @@ -88,6 +93,10 @@ pub const Session = struct { origin_line: ?zt.store.Line = null, lens_at: u64 = 0, lens_previous: u64 = 0, + lens_inspected: [32]u64 = @splat(0), + match_address: u64 = 0, + match_box: Box = .{}, + match_at: u64 = 0, shown: ?u64 = null, tid: u32 = 0, @@ -102,8 +111,8 @@ pub const Session = struct { branch: ?canim.Recording.Branch = null, }; const Pane = enum { code, stack, memory }; -const Lens = struct { address: u64 = 0, origin: Box = .{}, cycle: bool = false }; -const Kind = enum { restart, graph, dim, segments, select_segment, cont, pause, stepi, step, previous, next, live, follow, back, forward, source, map, annotate, shallower, deeper, ascii, lens, close_lens, help, breakpoint, command, go, submit }; +const Lens = struct { address: u64 = 0, first: u64 = 0, focus_end: u64 = 0, origin: Box = .{}, cycle: bool = false }; +const Kind = enum { unit, number_format, restart, graph, dim, segments, select_segment, cont, pause, stepi, step, previous, next, live, follow, back, forward, source, map, annotate, shallower, deeper, ascii, lens, close_lens, help, breakpoint, command, go, submit }; const Action = struct { kind: Kind, pane: Pane = .code, address: u64 = 0, manual: bool = false }; const Box = sk.Rect; var geometry = Geometry.init(width, height, 0); @@ -173,7 +182,7 @@ pub fn command(s: *State, c: *sk.Console, line: []const u8) !bool { sources.clear(gpa); latest = .{}; loaded = 0; - s.* = .{ .launches = s.launches + 1, .status = .running, .zoom = s.zoom, .maps = s.maps, .source = s.source, .annotations = s.annotations, .depth = s.depth, .ascii = s.ascii, .dim = s.dim }; + s.* = .{ .launches = s.launches + 1, .status = .running, .zoom = s.zoom, .maps = s.maps, .source = s.source, .annotations = s.annotations, .depth = s.depth, .ascii = s.ascii, .unit = s.unit, .number_format = s.number_format, .glass = s.glass, .dim = s.dim }; client = Client.start(gpa, io, argv.items) catch |err| { s.status = .failed; return err; @@ -220,6 +229,21 @@ pub fn command(s: *State, c: *sk.Console, line: []const u8) !bool { if (std.mem.eql(u8, cmd, "continue") or (std.mem.eql(u8, cmd, "stepi") or std.mem.eql(u8, cmd, "nextline"))) s.following = true; return true; } + if (std.mem.eql(u8, cmd, "lens")) { + const address = try std.fmt.parseInt(u64, words.next() orelse return error.MissingAddress, 0); + if (words.next() != null) return error.InvalidAddress; + openLens(s, .{ .address = address, .box = .{}, .lens = null }); + return true; + } + if (std.mem.eql(u8, cmd, "memory-format")) { + const unit = try std.fmt.parseInt(u8, words.next() orelse return error.MissingSize, 10); + if (unit != 1 and unit != 2 and unit != 4 and unit != 8) return error.InvalidSize; + const format = std.meta.stringToEnum(canim.rows.NumberFormat, words.next() orelse return error.MissingFormat) orelse return error.InvalidFormat; + if (words.next() != null or (format == .float and unit < 4)) return error.InvalidFormat; + s.unit = unit; + s.number_format = format; + return true; + } if (std.mem.eql(u8, cmd, "origin")) { s.origin = try std.fmt.parseInt(u64, words.next() orelse return error.MissingAddress, 0); return true; @@ -353,6 +377,14 @@ fn act(s: *State, a: Action) void { .shallower => s.depth = @max(1, s.depth -| 1), .deeper => s.depth = @min(6, s.depth + 1), .ascii => s.ascii = !s.ascii, + .unit => { + s.unit = if (s.unit >= 8) 1 else s.unit * 2; + if (s.number_format == .float and s.unit < 4) s.number_format = .hex; + }, + .number_format => { + s.number_format = @fromBackingInt(@intCast(@backingInt(s.number_format) +% 1)); + if (s.number_format == .float and s.unit < 4) s.unit = 4; + }, .lens => { if (s.lens) { s.lens = false; @@ -375,15 +407,7 @@ fn act(s: *State, a: Action) void { fn semantic(s: *State, address: u64) void { const t = if (trace) |*t| t else return; const m = t.moment(@min(s.moment, t.len -| 1)) catch return; - const region = canim.rows.regionOf(m, address); - const pane: Pane = switch (region) { - .code, .rwx => .code, - .stack => .stack, - else => blk: { - const value = (canim.Recording.word(m, address, 8) catch null) orelse break :blk .memory; - break :blk if (canim.rows.regionOf(m, value) != .none) .stack else .memory; - }, - }; + const pane: Pane = if (canim.rows.regionOf(m, address) == .stack) .stack else .memory; s.lens_address = address; s.focus = pane; s.action.send(.{ .kind = .go, .pane = pane, .address = address }); @@ -415,16 +439,43 @@ fn openLens(s: *State, hit: Hit) void { for (s.lenses[0..at]) |lens| if (lens.address == hit.address) { cycle = true; }; - s.lenses[at] = .{ .address = hit.address, .origin = hit.box, .cycle = cycle }; + const m = if (trace) |*t| t.moment(@min(s.moment, t.len -| 1)) catch return else return; + const first = if (executable(m, hit.address)) hit.address else (hit.address & ~@as(u64, 15)) -| 32; + var focus_end = first +| 80; + if (executable(m, hit.address)) { + focus_end = first; + for (0..6) |_| { + var text: [1024]u8 = undefined; + const insn = (zt.telescope.instruction(m, focus_end, &text) catch null) orelse break; + if (insn.len == 0) break; + focus_end +|= insn.len; + } + if (focus_end == first) focus_end = first +| 24; + } + s.lenses[at] = .{ .address = hit.address, .first = first, .focus_end = focus_end, .origin = hit.box, .cycle = cycle }; s.lens_count = at + 1; s.lens = true; s.lens_address = hit.address; s.lens_scroll = lensScroll(s.lens_count, true); - if (client != null and s.status == .stopped and s.following and !cycle) { - var buf: [96]u8 = undefined; - client.?.send(std.fmt.bufPrint(&buf, "inspect memory 0x{x} 128", .{(hit.address & ~@as(u64, 15)) -| 32}) catch return) catch {}; +} +fn executable(m: zt.store.Moment, address: u64) bool { + const map = (m.mapping(address, null, &.{}) catch null) orelse return false; + return map.prot & 4 != 0; +} +fn scrollLens(s: *State, index: usize, rows: f32) void { + const m = if (trace) |*t| t.moment(@min(s.moment, t.len -| 1)) catch return else return; + const lens = &s.lenses[index]; + if (lens.cycle) return; + const map = (m.mapping(lens.address, null, &.{}) catch null) orelse return; + const count: usize = @min(64, @as(usize, @intFromFloat(@ceil(@abs(rows))))); + for (0..count) |_| { + var buf: [1024]u8 = undefined; + const insn = if (executable(m, lens.address)) zt.telescope.instruction(m, lens.first, &buf) catch null else null; + const step: u64 = if (executable(m, lens.address)) (if (insn) |v| if (rows < 0) @max(1, v.back) else @max(1, v.len) else 1) else 16; + lens.first = std.math.clamp(if (rows < 0) lens.first -| step else lens.first +| step, map.addr, map.addr +| map.len -| 1); } } + fn lensViewport() Box { const y = @max(140, geometry.top + 12); return .{ .x = @max(24, geometry.w - 1132), .y = y, .w = @min(1108, geometry.w - 48), .h = @max(0, geometry.h - y - 40) }; @@ -452,6 +503,10 @@ fn pointer(s: *State, mouse_button: u16, x: f32, y: f32) void { }; return; } + if (addressAt(x, y)) |hit| { + s.selected_address = hit.address; + s.selected_box = hit.box; + } if (paneAt(x, y)) |pane| s.focus = pane; if (mouse_button == 4 or mouse_button == 5) { act(s, .{ .kind = if (mouse_button == 4) .back else .forward, .pane = s.focus }); @@ -547,7 +602,11 @@ pub fn update(s: *State, in: *const sk.Input) void { }, .wheel => { if (s.lens and lens_box != null and contains(lens_box.?, e.x, e.y)) { - s.lens_scroll = std.math.clamp(s.lens_scroll - e.wheel() * 48, 0, lensScroll(s.lens_count, false)); + var body: ?usize = null; + for (lens_boxes[0..drawn_lenses], 0..) |box, i| if (contains(box, e.x, e.y) and e.y >= box.y + 30) { + body = i; + }; + if (body != null and !in.held(sk.Key.left_shift) and !in.held(sk.Key.right_shift)) scrollLens(s, body.?, -e.wheel() * 3) else s.lens_scroll = std.math.clamp(s.lens_scroll - e.wheel() * 48, 0, lensScroll(s.lens_count, false)); } else if (contains(geometry.registers, e.x, e.y) and e.y >= geometry.registers.y + 30) { s.register_scroll = std.math.clamp(s.register_scroll - e.wheel() * 3, 0, @max(0, 29 - Geometry.visible(geometry.registers))); } else if (paneAt(e.x, e.y)) |pane| { @@ -750,7 +809,10 @@ fn button(u: ui.Ui, x: f32, y: f32, action: Action, label: []const u8, available const v = (if (available) u else u.faded(0.32)).moved(x, y); v.fill(.{ .x = 0, .y = 0, .w = 34, .h = 32 }, if (hover or active) ui.theme.color.rule else ui.theme.color.raised); if (hover or active) v.frame(.{ .x = 0, .y = 0, .w = 34, .h = 32 }, if (active) ui.theme.mark(.current).solid else ui.theme.color.text.dim, 1); - icon(v, action.kind, active); + if (action.kind == .unit) v.text(.mono_bold, 17, 5, 23, v.print("{d}", .{action.address * 8}), ui.theme.color.text.primary) else if (action.kind == .number_format) { + const labels = [_][]const u8{ "x", "u", "d", "f" }; + v.text(.mono_bold, 20, 10, 23, labels[@min(action.address, 3)], ui.theme.color.text.primary); + } else icon(v, action.kind, active); } fn paneButtons(u: ui.Ui, s: *const State, pane: Pane) void { const p = @backingInt(pane); @@ -896,6 +958,7 @@ pub fn draw(s: *const State, ss: *Session, f: *sk.Frame) void { if (ss.capture_stop != s.execution) { ss.capture_stop = s.execution; ss.inspected = @splat(0); + ss.lens_inspected = @splat(0); } // Captures are bounded and only requested from the selected live stop. if (client != null and s.following and s.status == .stopped) for (0..3) |p| { @@ -916,14 +979,14 @@ pub fn draw(s: *const State, ss: *Session, f: *sk.Frame) void { drawMemory(u.moved(panes[2].x, panes[2].y), s, ss, m, heat); ui.bound = null; u.unclip(); - ties(u, s, ss, m, travel); const place = if (t.len <= 1) 1 else @as(f32, @floatFromInt(m.index)) / @as(f32, @floatFromInt(t.len - 1)); u.fill(.{ .x = 24, .y = geometry.h - 34, .w = geometry.w - 48, .h = 2 }, ui.theme.color.rule); u.fill(.{ .x = 24, .y = geometry.h - 34, .w = (geometry.w - 48) * place, .h = 2 }, gold.solid); u.fill(.{ .x = 22 + (geometry.w - 48) * place, .y = geometry.h - 37, .w = 4, .h = 8 }, gold.solid); - if (geometry.w >= 1200 and geometry.content <= geometry.h + 1) u.text(.sans, 17, 24, geometry.h - 9, if (s.following) "Live stop · right-click an address to follow its meaning · click for a lens" else "Recorded state · inspecting and navigating leave the target unchanged", ink.dim); + if (geometry.w >= 1200 and geometry.content <= geometry.h + 1) u.text(.sans, 17, 24, geometry.h - 9, if (s.following) "Live stop · right-click: stack / memory · click for a lens" else "Recorded state · inspecting and navigating leave the target unchanged", ink.dim); if (geometry.content > geometry.h) u.text(.sans, 16, 24, geometry.h - 9, "PgUp/PgDn · scroll pane headers", ink.dim); overlays(u, s, ss, m); + ties(u, s, ss); } fn listing(ss: *Session, m: zt.store.Moment, base: u64) void { if (ss.listing_at == m.index and ss.listing_base == base) return; @@ -1204,7 +1267,7 @@ fn drawStack(u: ui.Ui, s: *const State, ss: *Session, m: zt.store.Moment, regs: memoryMini(u, ss, m, 1); } } -fn memoryRow(u: ui.Ui, m: zt.store.Moment, addr: u64, y: f32, room: f32, ascii: bool, touch: ?canim.Recording.Touch, heat: ui.Heat, before: ?zt.store.Moment) void { +fn memoryRow(u: ui.Ui, m: zt.store.Moment, addr: u64, y: f32, room: f32, ascii: bool, unit: u8, format: canim.rows.NumberFormat, touch: ?canim.Recording.Touch, heat: ui.Heat, before: ?zt.store.Moment) void { var values: [16]u8 = @splat(0); var known: [16]bool = @splat(false); m.read(addr, &values, &known) catch {}; @@ -1223,12 +1286,15 @@ fn memoryRow(u: ui.Ui, m: zt.store.Moment, addr: u64, y: f32, room: f32, ascii: run.* = .{ .first = @intCast(offset), .len = 8, .kind = if (canim.rows.regionOf(m, word) != .none) .pointer else .number, .read = read, .heat = if (changed != null) heat else .none, .changed = changed }; } const shift = canim.rows.addressRoom(addr); - canim.rows.bytesAt(u, y, addr, &values, &known, &runs, canim.rows.ink(canim.rows.regionOf(m, addr)), 0, false, m, shift); + const text_x: f32 = if (unit == 1 and format == .hex) blk: { + canim.rows.bytesAt(u, y, addr, &values, &known, &runs, canim.rows.ink(canim.rows.regionOf(m, addr)), 0, false, m, shift); + break :blk 640 + shift; + } else canim.rows.wordsAt(u, y, addr, &values, &known, unit, format, m); if (ascii) { var chars: [16]u8 = undefined; for (&chars, values, known) |*c, v, k| c.* = if (!k) '?' else if (v >= 32 and v < 127) v else '.'; - u.text(.mono, 20, 640 + shift, canim.rows.baseline(y), &chars, ui.theme.color.text.dim); - } else { + u.text(.mono, 20, text_x, canim.rows.baseline(y), &chars, ui.theme.color.text.dim); + } else if (unit == 1 and format == .hex) { const fields = [_]canim.hexdump.Field{ .{ .at = 0, .len = 8, .reads = if (runs[0].kind == .pointer) .pointer else .number }, .{ .at = 8, .len = 8, .reads = if (runs[1].kind == .pointer) .pointer else .number } }; _ = canim.hexdump.readingIn(u, y, shift, m, &values, &known, &fields, room); } @@ -1239,13 +1305,15 @@ fn memoryRows(u: ui.Ui, s: *const State, ss: *Session, m: zt.store.Moment, first const before = if (m.index > 0) trace.?.moment(m.index - 1) catch null else null; for (start..@min(start + count, @as(usize, @intCast(ranges[2].len / 16)))) |i| { const y = (if (miniature) @as(f32, 0) else 32) + @as(f32, @floatCast((@as(f64, @floatFromInt(i)) - first) * 24)); - memoryRow(u, m, bases[2] +| i * 16, y, panes[2].w - if (s.maps[2]) @as(f32, 60) else 0, s.ascii, ss.touch, heat, if (miniature) null else before); + memoryRow(u, m, bases[2] +| i * 16, y, panes[2].w - if (s.maps[2]) @as(f32, 60) else 0, s.ascii, s.unit, s.number_format, ss.touch, heat, if (miniature) null else before); } } fn drawMemory(u: ui.Ui, s: *const State, ss: *Session, m: zt.store.Moment, heat: ui.Heat) void { - _ = u.panel(panes[2].w, panes[2].h, if (panes[2].w < 600) "memory" else "memory / bytes", .{ .focus = s.focus == .memory }); - if (panes[2].w > 800) u.text(.sans, 17, 220, 19, if (s.ascii) "hex · ASCII" else "hex · pointer words", ui.theme.color.text.dim); + _ = u.panel(panes[2].w, panes[2].h, "memory", .{ .focus = s.focus == .memory }); paneButtons(u, s, .memory); + button(u, 112, -3, .{ .kind = .unit, .address = s.unit }, "Group size: 8 / 16 / 32 / 64 bits", true, false); + button(u, 150, -3, .{ .kind = .number_format, .address = @backingInt(s.number_format) }, "Format: hex / unsigned / signed / float", true, false); + if (panes[2].w > 800) u.text(.sans, 16, 195, 19, u.print("{d}-bit {s}", .{ s.unit * 8, @tagName(s.number_format) }), ui.theme.color.text.dim); u.clip(.{ .x = 2, .y = 30, .w = panes[2].w - if (s.maps[2]) @as(f32, 60) else 4, .h = panes[2].h - 38 }); memoryRows(u.moved(-s.horizontal[2], 0), s, ss, m, ss.scroll[2], heat, false); u.unclip(); @@ -1278,7 +1346,7 @@ fn memoryMini(u: ui.Ui, ss: *Session, m: zt.store.Moment, p: usize) void { const y = @as(f32, @floatFromInt(row)) * 24; if (p == 1) { _ = canim.rows.slot(v, y, panes[p].w - 60, m, address, 0, &.{}, 0, .{ .most = 2 }, "", false, null); - } else memoryRow(v, m, address, y, panes[p].w - 60, true, null, .none, null); + } else memoryRow(v, m, address, y, panes[p].w - 60, true, 1, .hex, null, .none, null); } ui.strokes = false; u.unclip(); @@ -1307,27 +1375,43 @@ fn segmentMini(u: ui.Ui, p: usize, first: u64, len: u64, current: u64) void { u.line(.{ box.x, y }, .{ box.x + box.w, y }, ui.theme.mark(.current).solid, 2); } } -fn ties(u: ui.Ui, s: *const State, ss: *Session, m: zt.store.Moment, travel: f32) void { - _ = m; +fn visibleHit(hit: Hit) bool { + if (hit.lens != null) return true; + const overlay = lens_box orelse return true; + const x = hit.box.x + hit.box.w / 2; + const y = hit.box.y + hit.box.h / 2; + if (contains(overlay, x, y)) for (lens_boxes[0..drawn_lenses]) |box| if (contains(box, x, y)) return false; + return true; +} +fn ties(u: ui.Ui, s: *const State, ss: *Session) void { + if (s.help or s.segments or s.command_open) return; const hovered = addressAt(u.f.in.mouse_x / display_scale, u.f.in.mouse_y / display_scale); - const address = if (hovered) |hit| hit.address else if (ss.touch) |touch| touch.addr else return; - var from: ?Box = if (hovered) |hit| hit.box else null; - for (hits[0..hit_count]) |hit| if (hit.address == address) { - if (from == null) { - from = hit.box; - continue; - } - const a = from.?; - const b = hit.box; - if (a.x == b.x and a.y == b.y) continue; - u.read(.{ .x = b.x, .y = b.y, .w = b.w, .h = b.h }, 1); - if (s.annotations) { - const lane = @min(geometry.w - 12, @max(a.x + a.w, b.x + b.w) + 12); - u.route(&.{ .{ a.x + a.w, a.y + a.h / 2 }, .{ lane, a.y + a.h / 2 }, .{ lane, b.y + b.h / 2 }, .{ b.x + b.w, b.y + b.h / 2 } }, ui.theme.mark(.read).solid, .{ .width = 1.5, .head = .{ 6, 6 }, .progress = if (hovered != null) 1 else travel }); - break; - } + const address = if (hovered) |hit| hit.address else if (s.selected_address != 0) s.selected_address else if (ss.touch) |touch| touch.addr else return; + var from: ?Box = if (hovered) |hit| hit.box else if (s.selected_address != 0) s.selected_box else null; + if (from == null) for (hits[0..hit_count]) |hit| if (hit.address == address) { + from = hit.box; + break; + }; + var first_visible: ?Box = null; + var origin_visible = false; + for (hits[0..hit_count]) |hit| if (hit.address == address and visibleHit(hit)) { + if (first_visible == null) first_visible = hit.box; + if (from != null and std.meta.eql(hit.box, from.?)) origin_visible = true; + }; + if (!origin_visible) from = first_visible; + const origin = from orelse return; + if (ss.match_address != address or !std.meta.eql(ss.match_box, origin)) { + ss.match_address = address; + ss.match_box = origin; + ss.match_at = u.f.in.now; + } + const seconds = @as(f32, @floatFromInt(u.f.in.now -| ss.match_at)) / 1e9; + var rank: usize = 1; + for (hits[0..hit_count]) |hit| if (hit.address == address and visibleHit(hit)) { + const first = std.meta.eql(origin, hit.box); + u.matchHighlight(.{ .x = hit.box.x, .y = hit.box.y, .w = hit.box.w, .h = hit.box.h }, seconds, if (first) 0 else rank, .{}); + if (!first) rank += 1; }; - if (hovered) |h| u.read(.{ .x = h.box.x, .y = h.box.y, .w = h.box.w, .h = h.box.h }, 1); } fn overlays(u: ui.Ui, s: *const State, ss: *Session, moment: ?zt.store.Moment) void { const ink = ui.theme.color.text; @@ -1348,23 +1432,60 @@ fn overlays(u: ui.Ui, s: *const State, ss: *Session, moment: ?zt.store.Moment) v const box: Box = .{ .x = overlay.x, .y = overlay.y + @as(f32, @floatFromInt(k)) * 204 - s.lens_scroll + (if (k + 1 == s.lens_count) 8 * (1 - amount) else 0), .w = overlay.w, .h = 188 }; lens_boxes[k] = box; drawn_lenses = k + 1; - current_lens = @intCast(k); const v = u.moved(box.x, box.y); - v.fill(.{ .x = 0, .y = 0, .w = box.w, .h = box.h }, ui.theme.color.lift); - _ = v.panel(box.w, box.h, v.print("lens {d}", .{k + 1}), .{}); + if (box.y + box.h <= overlay.y or box.y >= overlay.y + overlay.h) continue; + current_lens = @intCast(k); + const code = executable(moment.?, lens.address); + if (s.glass and u.f.host.gpu()) { + const uniforms = [4]f32{ box.w * display_scale, box.h * display_scale, display_scale, 0 }; + u.f.backdrop(Geometry.scaled(box, display_scale), @embedFile("glass"), std.mem.asBytes(&uniforms)); + v.faded(0.25).fill(.{ .x = 0, .y = 0, .w = box.w, .h = box.h }, ui.theme.color.lift); + } else v.fill(.{ .x = 0, .y = 0, .w = box.w, .h = box.h }, ui.theme.color.lift); + _ = v.faded(if (s.glass) 0.8 else 1).panel(box.w, box.h, v.print("lens {d}", .{k + 1}), .{}); + if (box.w > 520) v.text(.sans, 15, 320, 21, if (code) "disassembly · wheel browse · Shift-wheel chain" else "memory · wheel browse · Shift-wheel chain", ink.dim); + if (client != null and s.following and s.status == .stopped and !lens.cycle) { + const key = lens.first ^ (s.pc *% 0x9e3779b97f4a7c15); + if (ss.lens_inspected[k] != key) { + ss.lens_inspected[k] = key; + u.f.run(v.print("inspect {s} 0x{x} {d}", .{ if (code) "code" else "memory", lens.first, @as(u32, if (code) 32 else 128) })); + } + } _ = v.address(90, 21, lens.address, .{ .ink = ui.rgb(canim.rows.ink(canim.rows.regionOf(moment.?, lens.address))) }); button(v, box.w - 40, -2, .{ .kind = .close_lens, .address = k }, "Close lens and descendants", true, false); v.clip(.{ .x = 2, .y = 30, .w = box.w - 4, .h = box.h - 32 }); if (lens.cycle) { v.text(.sans_medium, 20, 16, 65, "Cycle · this address is already an ancestor", ui.theme.mark(.current).solid); } else { - const first = (lens.address & ~@as(u64, 15)) -| 32; + const first = lens.first; + const focus_start = if (code) lens.address else (lens.address & ~@as(u64, 15)) -| 32; var bytes: [80]u8 = undefined; var known: [80]bool = @splat(false); moment.?.read(first, &bytes, &known) catch {}; if (std.mem.indexOfScalar(bool, &known, true) == null) { v.text(.sans, 18, 16, 62, if (s.following and s.status == .stopped) "Unreadable pointer · no bytes captured" else "Uncaptured at this recorded stop", ink.dim); - } else for (0..5) |i| memoryRow(v, moment.?, first +| i * 16, 34 + @as(f32, @floatFromInt(i)) * 24, box.w - 12, false, null, .none, null); + } else if (code) { + var pc = first; + for (0..6) |i| { + var text: [1024]u8 = undefined; + const insn = (zt.telescope.instruction(moment.?, pc, &text) catch null) orelse { + v.text(.sans, 18, 16, 53 + @as(f32, @floatFromInt(i)) * 24, "Instructions not captured at this stop", ink.dim); + break; + }; + var encoded: [15]u8 = undefined; + var captured: [15]bool = @splat(false); + if (insn.len == 0 or insn.len > 15) break; + moment.?.read(pc, encoded[0..insn.len], captured[0..insn.len]) catch break; + if (std.mem.indexOfScalar(bool, captured[0..insn.len], false) != null) break; + const row: canim.disasm.Insn = .{ .addr = pc, .len = insn.len, .text = insn.text }; + const context = pc < focus_start or pc >= lens.focus_end; + canim.disasm.liveRow(v.faded(if (context) 0.4 else 1), row, 34 + @as(f32, @floatFromInt(i)) * 24, box.w - 12, moment.?, (moment.?.regs(s.tid) catch null) orelse .{}, .{ .compact = box.w < 520 }); + pc +|= insn.len; + } + } else for (0..6) |i| { + const address = first +| i * 16; + const context = address < focus_start or address >= lens.focus_end; + memoryRow(v.faded(if (context) 0.4 else 1), moment.?, address, 34 + @as(f32, @floatFromInt(i)) * 24, box.w - 12, false, s.unit, s.number_format, null, .none, null); + } } v.unclip(); current_lens = null; @@ -1413,7 +1534,7 @@ fn overlays(u: ui.Ui, s: *const State, ss: *Session, moment: ?zt.store.Moment) v v.fill(.{ .x = 0, .y = 0, .w = w, .h = @min(560, geometry.h - 160) }, ui.theme.color.lift); _ = v.panel(w, @min(560, geometry.h - 160), "Keys · Esc closes", .{ .focus = true }); v.clip(.{ .x = 0, .y = 32, .w = w, .h = @max(0, geometry.h - 192) }); - const lines = [_][]const u8{ "s instruction · n source · c run", "Esc / Ctrl-c pause · Shift-r restart", "Ctrl +/− font · Ctrl-0 reset", "j/k scroll · PgUp/PgDn page", "h/l source · Shift-h/l horizontal", "Ctrl-d/u half page · Tab focus", "Ctrl-o/i address history", "[ / ] stops · F live · f follow", "t graph · d unobserved opacity", "p segments · v source · m minimap", "click: lens · right-click: navigate", "z lens · : command · ? help", "Gold current · bright observed", "Branch target: prediction only", "Dim: unknown between live stops" }; + const lines = [_][]const u8{ "s instruction · n source · c run", "Esc / Ctrl-c pause · Shift-r restart", "Ctrl +/− font · Ctrl-0 reset", "j/k scroll · PgUp/PgDn page", "h/l source · Shift-h/l horizontal", "Ctrl-d/u half page · Tab focus", "Ctrl-o/i address history", "[ / ] stops · F live · f follow", "t graph · d unobserved opacity", "p segments · v source · m minimap", "click: lens · right-click: stack/memory", "Lens wheel: browse · Shift: chain", "z lens · : command · ? help", "Gold current · bright observed", "Branch target: prediction only", "Dim: unknown between live stops" }; for (lines, 0..) |line, i| v.text(.mono, 16, 12, 58 + @as(f32, @floatFromInt(i)) * 30, canim.rows.fitted(v, line, w - 24), ink.primary); v.unclip(); } diff --git a/gui/src/glass.frag b/gui/src/glass.frag new file mode 100644 index 0000000..6e6f2a7 --- /dev/null +++ b/gui/src/glass.frag @@ -0,0 +1,27 @@ +#version 450 +layout(location=0) in vec4 color; +layout(location=1) in vec2 uv; +layout(set=2, binding=0) uniform sampler2D backdrop; +layout(set=3, binding=0) uniform Glass { vec4 size; } glass; +layout(location=0) out vec4 out_color; +void main() { + vec2 px = uv * glass.size.xy; + vec2 half_size = glass.size.xy * .5; + float radius = min(18.0 * glass.size.z, half_size.y); + vec2 q = abs(px - half_size) - (half_size - radius); + float distance = length(max(q, 0.0)) + min(max(q.x, q.y), 0.0) - radius; + float edge = 1.0 - smoothstep(0.0, 16.0 * glass.size.z, max(-distance, 0.0)); + vec2 normal = normalize((px - half_size) / max(half_size, vec2(1.0)) + vec2(.0001)); + vec2 offset = normal * (2.0 + 11.0 * edge) * glass.size.z / glass.size.xy; + vec2 refracted = clamp(uv - offset, vec2(.002), vec2(.998)); + vec2 split = normal * 1.2 * edge * glass.size.z / glass.size.xy; + vec3 scene = vec3(texture(backdrop, refracted + split).r, + texture(backdrop, refracted).g, + texture(backdrop, refracted - split).b); + vec3 tint = mix(vec3(.035, .05, .10), scene, .34 * edge); + float rim = exp(-abs(distance + 1.4 * glass.size.z) / (1.1 * glass.size.z)); + float light = .35 + .65 * max(dot(normal, normalize(vec2(-.4,-1.0))), 0.0); + tint += vec3(.23, .72, .85) * rim * light * .65; + tint += vec3(.025, .08, .1) * edge; + out_color = vec4(tint, 1.0 - smoothstep(-1.0, 1.0, distance)) * color; +} -- cgit v1.3