summaryrefslogtreecommitdiff
path: root/src/cli
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-10 12:28:33 -0300
committerGabriel Schneider <[email protected]>2026-11-10 12:30:52 -0300
commit8ac0639bfc0186acedb11759432a2cfa277193f2 (patch)
tree5a20795dae8c3f33d0c61ff6401887165da8ba2f /src/cli
parent952af9711cc6a4de987a9d9d45e1e36721c5b470 (diff)
downloadcomputeranim-8ac0639bfc0186acedb11759432a2cfa277193f2.tar.gz
computeranim-8ac0639bfc0186acedb11759432a2cfa277193f2.zip
static probes from the debugger: -b usdt:PROVIDER:NAME, no root
Debugger.usdt arms the USDT probes of every mapped module as breakpoints whose hook records a probe event with its arguments and lets the program run on, raising a probe's semaphore first; record and dbg take usdt:PROVIDER:NAME (* for any), running the loader through when the probe is a library's. glibc's own 78 probes are there for the asking: memory_sbrk_more shows malloc growing the heap.
Diffstat (limited to 'src/cli')
-rw-r--r--src/cli/dbg.zig8
-rw-r--r--src/cli/record.zig15
2 files changed, 21 insertions, 2 deletions
diff --git a/src/cli/dbg.zig b/src/cli/dbg.zig
index 6876f84..02cebbc 100644
--- a/src/cli/dbg.zig
+++ b/src/cli/dbg.zig
@@ -168,7 +168,13 @@ const Session = struct {
_ = try if (is(cmd, "step", "s")) s.d.step() else if (is(cmd, "stepi", "si")) s.d.stepi() else s.d.cont();
try s.showStop();
} else if (is(cmd, "break", "b")) {
- const addr = try s.d.resolve(arg orelse return error.MissingArgument);
+ const where = arg orelse return error.MissingArgument;
+ if (std.mem.startsWith(u8, where, "usdt:")) {
+ s.rec.cut |= zt.Kind.probe.bit();
+ try s.w.print("{d} probes armed: each hit is recorded, the program runs on\n", .{try s.d.usdt(where[5..])});
+ return true;
+ }
+ const addr = try s.d.resolve(where);
try s.w.print("breakpoint {d} at ", .{try s.d.breakAt(addr, null)});
try s.d.describe(s.w, addr);
try s.w.writeAll("\n");
diff --git a/src/cli/record.zig b/src/cli/record.zig
index 8a30761..f508ddc 100644
--- a/src/cli/record.zig
+++ b/src/cli/record.zig
@@ -17,6 +17,9 @@ pub const usage =
\\ syscall every syscall (--syscalls is the same)
\\ break the breakpoints only
\\-b adds a breakpoint, in any of them: a function, file:line or *address.
+ \\-b usdt:PROVIDER:NAME (* for any) records the program's static probes
+ \\(USDT) instead, each hit a `probe` event with its arguments, without
+ \\stopping there.
\\Syscalls are recorded whatever the stops are, with at most -s bytes
\\(default 256) of the path or the buffer each points at; --strace also
\\prints them, a line each.
@@ -96,7 +99,17 @@ pub fn run(init: std.process.Init, args: []const [:0]const u8) !void {
d.syscalls = if (by == .syscall) .stop else .record;
d.stack_watch = stack_bytes;
if (capture) |n| d.capture = n;
- for (breaks.items) |where| _ = try d.breakAt(d.resolve(where) catch fail("{s}: no such place in the program\n", .{where}), null);
+ for (breaks.items) |where| {
+ if (std.mem.startsWith(u8, where, "usdt:")) {
+ // A library's probes are there once the loader has mapped it.
+ if (try d.usdt(where[5..]) == 0) {
+ try d.toEntry();
+ if (try d.usdt(where[5..]) == 0) fail("{s}: no such probe in the program or its libraries\n", .{where});
+ }
+ // A probe's hit is a moment, as any event asked for by name.
+ rec.cut |= zt.Kind.probe.bit();
+ } else _ = try d.breakAt(d.resolve(where) catch fail("{s}: no such place in the program\n", .{where}), null);
+ }
for (watches.items) |spec| {
const comma = std.mem.indexOfScalar(u8, spec, ',') orelse spec.len;
const what = d.place(spec[0..comma]) orelse fail("{s}: no such symbol\n", .{spec[0..comma]});