summaryrefslogtreecommitdiffstats
path: root/debugger.c
diff options
context:
space:
mode:
authorMalfurious <m@lfurio.us>2023-09-25 14:49:19 -0400
committerMalfurious <m@lfurio.us>2024-04-24 13:31:08 -0400
commit566d752918789b178a47393a78b41c90288e40e9 (patch)
treedfe515ae1d7546b34bb82c08b2b597e69dd8c54f /debugger.c
parent6a9e590b847a034d190fe3c89ef37656073d229a (diff)
downloadmisplays-566d752918789b178a47393a78b41c90288e40e9.tar.gz
misplays-566d752918789b178a47393a78b41c90288e40e9.zip
(Un)install breakpoints via specific thread
We need to perform these changes with a thread ID that is known to be in ptrace stop. This is a requirement of the API even though the memory change is seen by all threads of the guest process. Signed-off-by: Malfurious <m@lfurio.us>
Diffstat (limited to 'debugger.c')
-rw-r--r--debugger.c30
1 files changed, 15 insertions, 15 deletions
diff --git a/debugger.c b/debugger.c
index 73db856..ca774e8 100644
--- a/debugger.c
+++ b/debugger.c
@@ -65,26 +65,26 @@ static int detect_breakpoint(struct thread *th) {
return restart;
}
-static void install_breakpoints(struct process *proc) {
- struct list *breaks = &proc->breakpoints;
+static void install_breakpoints(struct thread *th) {
+ struct list *breaks = &th->proc->breakpoints;
for (struct breakpoint *b = breaks->head; b != breaks->end; b = b->next) {
if (!b->installed) {
unsigned long word;
- word = ptrace(PTRACE_PEEKTEXT, proc->id, b->address, NULL);
+ word = ptrace(PTRACE_PEEKTEXT, th->id, b->address, NULL);
b->text = word;
word = (word & ~0xff) | BREAKPOINT_INSN;
- ptrace(PTRACE_POKETEXT, proc->id, b->address, word);
+ ptrace(PTRACE_POKETEXT, th->id, b->address, word);
b->installed = 1;
}
}
}
-static void uninstall_breakpoints(struct process *proc) {
- struct list *breaks = &proc->breakpoints;
+static void uninstall_breakpoints(struct thread *th) {
+ struct list *breaks = &th->proc->breakpoints;
for (struct breakpoint *b = breaks->tail; b != breaks->end; b = b->prev) {
if (b->installed) {
- ptrace(PTRACE_POKETEXT, proc->id, b->address, b->text);
+ ptrace(PTRACE_POKETEXT, th->id, b->address, b->text);
b->installed = 0;
}
@@ -288,7 +288,7 @@ struct process *dbg_attach(pid_t pid, int child) {
int dbg_detach(struct process *proc) {
interrupt_all_threads(proc);
- uninstall_breakpoints(proc);
+ uninstall_breakpoints(proc->threads.head);
free_breakpoints(proc);
if (proc->child) {
@@ -362,7 +362,7 @@ int dbg_wait(struct thread *th, int recursion) {
if (!recursion) {
stopped = interrupt_all_threads(th->proc);
- uninstall_breakpoints(th->proc);
+ uninstall_breakpoints(th);
capture_state(th, stopped);
}
@@ -377,7 +377,7 @@ int dbg_wait(struct thread *th, int recursion) {
if (!recursion) {
stopped = interrupt_all_threads(th->proc);
- uninstall_breakpoints(th->proc);
+ uninstall_breakpoints(th);
capture_state(th, stopped);
}
@@ -392,7 +392,7 @@ int dbg_wait(struct thread *th, int recursion) {
if (!recursion) {
stopped = interrupt_all_threads(th->proc);
- uninstall_breakpoints(th->proc);
+ uninstall_breakpoints(th);
capture_state(th, stopped);
}
@@ -407,7 +407,7 @@ int dbg_wait(struct thread *th, int recursion) {
if (!recursion) {
stopped = interrupt_all_threads(th->proc);
- uninstall_breakpoints(th->proc);
+ uninstall_breakpoints(th);
capture_state(th, stopped);
}
@@ -421,7 +421,7 @@ int dbg_wait(struct thread *th, int recursion) {
if (th->cont != 0) {
/* gdb this portion. are there race conditions
* that matter?? */
- install_breakpoints(th->proc);
+ install_breakpoints(th);
ptrace(th->cont, th->id, NULL, NULL);
th->cont = 0;
th->stopped = 0;
@@ -439,7 +439,7 @@ int dbg_wait(struct thread *th, int recursion) {
if (!recursion) {
stopped = interrupt_all_threads(th->proc);
if (!restart) {
- uninstall_breakpoints(th->proc);
+ uninstall_breakpoints(th);
capture_state(th, stopped);
}
}
@@ -460,7 +460,7 @@ int dbg_wait(struct thread *th, int recursion) {
if (!recursion) {
stopped = interrupt_all_threads(th->proc);
- uninstall_breakpoints(th->proc);
+ uninstall_breakpoints(th);
capture_state(th, stopped);
}