summaryrefslogtreecommitdiff
path: root/src/trace/control.zig
blob: c0a7906bb144cdb1c359981bf4c13bbb1f9ad25e (plain) (blame)
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
//! Small control messages shared by a debugger controller and its clients.
const std = @import("std");

pub const Status = enum { stopped, running, exited, failed };
pub const Reply = struct {
    status: Status,
    pid: i32,
    tid: u32,
    moments: u64,
    pc: u64,
    elapsed_ns: u64 = 0,
    capture_ns: u64 = 0,
    reason: []const u8 = "",
};

pub fn send(w: *std.Io.Writer, reply: Reply) !void {
    try std.json.Stringify.value(reply, .{}, w);
    try w.writeByte('\n');
    try w.flush();
}

test "control messages preserve 64-bit addresses" {
    var buf: [512]u8 = undefined;
    var w: std.Io.Writer = .fixed(&buf);
    const value: Reply = .{ .status = .stopped, .pid = 1, .tid = 2, .moments = 3, .pc = 0xffffffffffffffff };
    try send(&w, value);
    const parsed = try std.json.parseFromSlice(Reply, std.testing.allocator, w.buffered(), .{});
    defer parsed.deinit();
    try std.testing.expectEqual(value.pc, parsed.value.pc);
}