From 5589a9e3afd51bdf3d8715fb09b1667c6773b73f Mon Sep 17 00:00:00 2001 From: Malfurious Date: Sat, 7 Oct 2023 02:07:04 -0400 Subject: Ignore breakpoints during singlestep Due to new independent thread control, it is now possible and likely that breakpoints will be installed before singlesteps are waited upon to be completed. also clean detect_breakpoint with get_breakpoint. Signed-off-by: Malfurious --- debugger.c | 33 +++++++++++++-------------------- 1 file changed, 13 insertions(+), 20 deletions(-) diff --git a/debugger.c b/debugger.c index b08faf6..b646dc4 100644 --- a/debugger.c +++ b/debugger.c @@ -110,26 +110,19 @@ static int detect_breakpoint(struct thread *th, int *restart) { struct iovec ivregs = { ®s, sizeof(regs) }; ptrace(PTRACE_GETREGSET, th->id, NT_PRSTATUS, &ivregs); - /* implement with get_breakpoint? */ - struct list *breaks = &th->proc->breakpoints; - for (struct breakpoint *b = breaks->tail; b != breaks->end; b = b->prev) { - if (b->installed && (regs.rip - 1 == b->address)) { - regs.rip--; - ptrace(PTRACE_SETREGSET, th->id, NT_PRSTATUS, &ivregs); - b->hits++; - ret = b->user; - - if (b->stack != 0 && b->stack != regs.rsp) { - *restart = 1; - } - if (b->tid != 0 && b->tid != th->id) { - *restart = 1; - } - if (!b->enabled) { - *restart = 1; - } - - break; + struct breakpoint *b = get_breakpoint(th->proc, regs.rip - 1); + if (b && b->installed && th->doing != PTRACE_SINGLESTEP) { + regs.rip--; + ptrace(PTRACE_SETREGSET, th->id, NT_PRSTATUS, &ivregs); + b->hits++; /* todo: consider whether this is firing too much */ + ret = b->user; + + if (b->stack != 0 && b->stack != regs.rsp) { + *restart = 1; + } else if (b->tid != 0 && b->tid != th->id) { + *restart = 1; + } else if (!b->enabled) { + *restart = 1; } } -- cgit v1.2.3