19#include <linux/perf_event.h>
20#include <linux/hw_breakpoint.h>
25static constexpr size_t KT_WATCH_PAGES = 8;
32 KT_PERFWATCH_LEN_1 = 1,
33 KT_PERFWATCH_LEN_2 = 2,
34 KT_PERFWATCH_LEN_3 = 3,
35 KT_PERFWATCH_LEN_4 = 4,
36 KT_PERFWATCH_LEN_5 = 5,
37 KT_PERFWATCH_LEN_6 = 6,
38 KT_PERFWATCH_LEN_7 = 7,
39 KT_PERFWATCH_LEN_8 = 8,
47 KT_PERFWATCH_EMPTY = 0,
50 KT_PERFWATCH_RW = KT_PERFWATCH_R | KT_PERFWATCH_W,
52 KT_PERFWATCH_INVALID = KT_PERFWATCH_RW | KT_PERFWATCH_X,
101 KittyPerfWatch() =
default;
115 bool add(pid_t tid, uintptr_t addr, KT_WATCH_TYPE bp_type, KT_WATCH_LEN bp_len);
133 void *mmap =
nullptr;
137 std::vector<WatchInfo> _watches;
139 static inline int perf_event_open(
struct perf_event_attr *attr,
145#if defined(__aarch64__)
146 return syscall(241, attr, pid, cpu, group_fd, flags);
147#elif defined(__arm__)
148 return syscall(364, attr, pid, cpu, group_fd, flags);
149#elif defined(__i386__)
150 return syscall(336, attr, pid, cpu, group_fd, flags);
151#elif defined(__x86_64__)
152 return syscall(298, attr, pid, cpu, group_fd, flags);
154#error "Unsupported ABI"
178 bool add(pid_t tid, uintptr_t addr, KT_WATCH_TYPE bp_type, KT_WATCH_LEN bp_len);
Class to manage trap signaling hardware watchpoins.
Definition KittyPerfEvent.hpp:168
bool add(pid_t tid, uintptr_t addr, KT_WATCH_TYPE bp_type, KT_WATCH_LEN bp_len)
Adds a new trap signaling hardware watchpoint to the watch list.
void clear()
Clears all watchpoints from the watch list.
bool add(pid_t tid, uintptr_t addr, KT_WATCH_TYPE bp_type, KT_WATCH_LEN bp_len)
Adds a new hardware watchpoint to the watch list.
void poll(int timeout_ms, const std::function< bool(const KittyPerfSample &)> &cb)
Polls the watch list for new samples.
Structure to hold the performance sample.
Definition KittyPerfEvent.hpp:59
uint64_t time
The timestamp of the sample in nanoseconds.
Definition KittyPerfEvent.hpp:78
uint64_t addr
The address of the memory location being watched.
Definition KittyPerfEvent.hpp:83
uint64_t ip
The instruction pointer (IP) of the sampled event.
Definition KittyPerfEvent.hpp:63
uint32_t tid
The thread ID (TID) of the thread that generated the sample.
Definition KittyPerfEvent.hpp:73
uint32_t pid
The process ID (PID) of the process that generated the sample.
Definition KittyPerfEvent.hpp:68
Definition KittyPerfEvent.hpp:131