-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbreakpoint.cpp
More file actions
30 lines (22 loc) · 830 Bytes
/
breakpoint.cpp
File metadata and controls
30 lines (22 loc) · 830 Bytes
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
#include "breakpoint.hpp"
#include <sys/ptrace.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
void Breakpoint::enable() {
auto data = ptrace(PTRACE_PEEKDATA, m_pid, m_addr, nullptr);
m_data = static_cast<uint8_t>(data & 0xff);
// 0xcc -- encoded "int 3" instruction that we want to insert
// into debuggee. Data on that place will be stored in m_data
uint8_t int3 = 0xcc;
uint8_t modified_data = ((data & ~0xff) | int3);
ptrace(PTRACE_POKEDATA, m_pid, m_addr, modified_data);
m_enabled = true;
}
void Breakpoint::disable() {
auto data = ptrace(PTRACE_PEEKDATA, m_pid, m_addr, nullptr);
// Change inserted interrupt on the original instruction back
uint8_t restored_data = ((data & ~0xff) | m_data);
ptrace(PTRACE_POKEDATA, m_pid, m_addr, restored_data);
m_enabled = false;
}