summaryrefslogtreecommitdiff
path: root/src/cli
diff options
context:
space:
mode:
Diffstat (limited to 'src/cli')
-rw-r--r--src/cli/disasm.c3
-rw-r--r--src/cli/record.zig13
2 files changed, 15 insertions, 1 deletions
diff --git a/src/cli/disasm.c b/src/cli/disasm.c
index 9b15e0c..6f2ffa4 100644
--- a/src/cli/disasm.c
+++ b/src/cli/disasm.c
@@ -21,6 +21,8 @@ struct zt_branch {
// A conditional jump whose condition does not hold is not taken.
uint8_t taken;
uint8_t indirect;
+ // A jump on a condition.
+ uint8_t conditional;
};
// Whether the flags (and rcx) make a conditional jump go.
@@ -96,6 +98,7 @@ size_t zt_disasm(const uint8_t *code, size_t len, uint64_t addr, char *text, siz
branch->taken = regs ? holds(insn->id, regs[18], regs[11]) : 1;
branch->indirect = 0;
branch->target = 0;
+ branch->conditional = branch->kind == 2 && insn->id != X86_INS_JMP && insn->id != X86_INS_LJMP;
if (branch->kind == 1 || branch->kind == 2) {
const cs_x86_op *op = &x->operands[0];
if (x->op_count < 1) branch->kind = 0;
diff --git a/src/cli/record.zig b/src/cli/record.zig
index 6743ec4..5d3726c 100644
--- a/src/cli/record.zig
+++ b/src/cli/record.zig
@@ -10,7 +10,7 @@ pub const usage =
\\usage: ztrace record [-o FILE] [--by insn|line|syscall|break] [-b WHERE]... [-w WHAT[,LEN]]...
\\ [--from WHERE] [--stack BYTES] [-s BYTES] [--telescope DEPTH]
\\ [--around BYTES] [--disasm ROWS] [--steps N]
- \\ [--max-size BYTES] [--strace] [--heap]
+ \\ [--max-size BYTES] [--strace] [--heap] [--asan]
\\ [--ring] [--preload LIB] [--alloc] -- PROGRAM [ARGS]
\\
\\Runs PROGRAM under ptrace into a recording (default out.ztrace). --by
@@ -44,6 +44,10 @@ pub const usage =
\\tcache, and the links of every chunk on a list; at most 4096 chunks and
\\256 entries a list. glibc 2.40 and 2.44 only, linked dynamically or
\\statically; the main arena's heap, the stopped thread's tcache.
+ \\--asan also records AddressSanitizer's shadow of all memory recorded (a
+ \\byte for 8: 00 addressable, f1 f2 f3 a stack frame's redzones, fa a
+ \\heap's, fd freed), where the runtime puts it; for a program built with
+ \\-fsanitize=address only.
\\--steps ends the recording after N moments (N stops from the --from
\\place, when there is one), and --max-size when the
\\file is that large (default 1G). Sizes take a suffix: 64K, 4G.
@@ -74,6 +78,7 @@ pub fn run(init: std.process.Init, args: []const [:0]const u8) !void {
var max_bytes: ?u64 = null;
var strace = false;
var heap = false;
+ var asan = false;
var from: ?[]const u8 = null;
var breaks: std.ArrayList([]const u8) = .empty;
var watches: std.ArrayList([]const u8) = .empty;
@@ -94,6 +99,8 @@ pub fn run(init: std.process.Init, args: []const [:0]const u8) !void {
strace = true;
} else if (std.mem.eql(u8, arg, "--heap")) {
heap = true;
+ } else if (std.mem.eql(u8, arg, "--asan")) {
+ asan = true;
} else if (producer.take(args, &i)) {
// Its own argument, when it has one, is taken.
} else if (value == null) {
@@ -157,6 +164,9 @@ 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 (heap) d.heap = .{};
+ // Built with ASan, the program has its runtime or calls it (`__asan_init`, from a constructor).
+ if (asan and d.symbol("__asan_init") == null and !d.syms.imported.contains("__asan_init")) fail("--asan: {s} has no ASan runtime: build it with -fsanitize=address\n", .{args[i]});
+ d.asan = asan;
if (capture) |n| d.capture = n;
for (breaks.items) |where| {
if (std.mem.startsWith(u8, where, "usdt:")) {
@@ -234,6 +244,7 @@ pub fn run(init: std.process.Init, args: []const [:0]const u8) !void {
.no_layout => std.debug.print("heap: not recorded: no layout known for glibc {d}.{d} (known: 2.40, 2.44)\n", .{ h.version[0], h.version[1] }),
.no_arena => std.debug.print("heap: not recorded: more than one place in glibc looks like the main arena\n", .{}),
};
+ if (asan) if (d.asan_shadow) |offset| std.debug.print("asan: shadow at {x}\n", .{offset}) else std.debug.print("asan: not recorded: the runtime never set its shadow\n", .{});
std.debug.print("{s}: {d} moments, {d} events, {d} bytes ({d} bytes/moment), {d:.1} ms, {d:.0} moments/s, exit {d}\n", .{
out, moments,
events, size,