static void enable_bp_cb(void *addr, void *sbp, void *proc) { debug(DEBUG_FUNCTION, "enable_bp_cb(pid=%d)", ((Process *)proc)->pid); if (((Breakpoint *)sbp)->enabled) { enable_breakpoint(((Process *)proc)->pid, sbp); } }
/* Python function to set the enabled state of a breakpoint. */ static int bppy_set_enabled (PyObject *self, PyObject *newvalue, void *closure) { breakpoint_object *self_bp = (breakpoint_object *) self; int cmp; BPPY_SET_REQUIRE_VALID (self_bp); if (newvalue == NULL) { PyErr_SetString (PyExc_TypeError, _("Cannot delete `enabled' attribute.")); return -1; } else if (! PyBool_Check (newvalue)) { PyErr_SetString (PyExc_TypeError, _("The value of `enabled' must be a boolean.")); return -1; } cmp = PyObject_IsTrue (newvalue); if (cmp < 0) return -1; else if (cmp == 1) enable_breakpoint (self_bp->bp); else disable_breakpoint (self_bp->bp); return 0; }
EXPORT int CALL DebugBreakpointCommand(m64p_dbg_bkp_command command, unsigned int index, void *ptr) { #ifdef DBG switch (command) { case M64P_BKP_CMD_ADD_ADDR: return add_breakpoint(index); case M64P_BKP_CMD_ADD_STRUCT: return add_breakpoint_struct((breakpoint *) ptr); case M64P_BKP_CMD_REPLACE: replace_breakpoint_num(index, (breakpoint *) ptr); return 0; case M64P_BKP_CMD_REMOVE_ADDR: remove_breakpoint_by_address(index); return 0; case M64P_BKP_CMD_REMOVE_IDX: remove_breakpoint_by_num(index); return 0; case M64P_BKP_CMD_ENABLE: enable_breakpoint(index); return 0; case M64P_BKP_CMD_DISABLE: disable_breakpoint(index); return 0; case M64P_BKP_CMD_CHECK: return check_breakpoints(index); default: DebugMessage(M64MSG_ERROR, "Bug: DebugBreakpointCommand() called with invalid input m64p_dbg_bkp_command"); return -1; } #else DebugMessage(M64MSG_ERROR, "Bug: DebugBreakpointCommand() called, but Debugger not supported in Core library"); return -1; #endif }
debug_breakpoint* create_breakpoint(pid_t pid, void* addr) { debug_breakpoint* bp = malloc(sizeof(*bp)); bp->addr = addr; enable_breakpoint(pid, bp); return bp; }
void insert_breakpoint(Process *proc, void *addr, struct library_symbol *libsym) { Breakpoint *sbp; debug(DEBUG_FUNCTION, "insert_breakpoint(pid=%d, addr=%p, symbol=%s)", proc->pid, addr, libsym ? libsym->name : "NULL"); debug(1, "symbol=%s, addr=%p", libsym?libsym->name:"(nil)", addr); if (!addr) return; if (libsym) libsym->needs_init = 0; sbp = dict_find_entry(proc->breakpoints, addr); if (!sbp) { sbp = calloc(1, sizeof(Breakpoint)); if (!sbp) { return; /* TODO FIXME XXX: error_mem */ } dict_enter(proc->breakpoints, addr, sbp); sbp->addr = addr; sbp->libsym = libsym; } #ifdef __arm__ sbp->thumb_mode = proc->thumb_mode; proc->thumb_mode = 0; #endif sbp->enabled++; if (sbp->enabled == 1 && proc->pid) enable_breakpoint(proc->pid, sbp); }
error_t insert_breakpoints(mygdb_info_t* gdb_info){ int i; for(i = 0; i < gdb_info->breakpoints.count; i++){ enable_breakpoint(gdb_info, i); } return E_NONE; }
int breakpoint_turn_on(struct breakpoint *bp, struct process *proc) { bp->enabled++; if (bp->enabled == 1) { assert(proc->pid != 0); enable_breakpoint(proc, bp); } return 0; }
int resume_from_breakpoint(pid_t pid, debug_breakpoint* bp) { struct user_regs_struct regs; int wait_status; ptrace(PTRACE_GETREGS, pid, 0, ®s); /* Make sure we indeed are stopped at bp */ assert(regs.rip == (long) bp->addr + 1); /* Now disable the breakpoint, rewind EIP back to the original instruction ** and single-step the process. This executes the original instruction that ** was replaced by the breakpoint. */ regs.rip = (long) bp->addr; ptrace(PTRACE_SETREGS, pid, 0, ®s); disable_breakpoint(pid, bp); if (ptrace(PTRACE_SINGLESTEP, pid, 0, 0) < 0) { perror("ptrace"); return -1; } wait(&wait_status); if (WIFEXITED(wait_status)) { return 0; } /* Re-enable the breakpoint and let the process run. */ enable_breakpoint(pid, bp); if (ptrace(PTRACE_CONT, pid, 0, 0) < 0) { perror("ptrace"); return -1; } wait(&wait_status); if (WIFEXITED(wait_status)) return 0; else if (WIFSTOPPED(wait_status)) { return 1; } else return -1; }
/* Python function to set the enabled state of a breakpoint. */ static int bppy_set_enabled (PyObject *self, PyObject *newvalue, void *closure) { gdbpy_breakpoint_object *self_bp = (gdbpy_breakpoint_object *) self; int cmp; volatile struct gdb_exception except; BPPY_SET_REQUIRE_VALID (self_bp); if (newvalue == NULL) { PyErr_SetString (PyExc_TypeError, _("Cannot delete `enabled' attribute.")); return -1; } else if (! PyBool_Check (newvalue)) { PyErr_SetString (PyExc_TypeError, _("The value of `enabled' must be a boolean.")); return -1; } cmp = PyObject_IsTrue (newvalue); if (cmp < 0) return -1; TRY_CATCH (except, RETURN_MASK_ALL) { if (cmp == 1) enable_breakpoint (self_bp->bp); else disable_breakpoint (self_bp->bp); } GDB_PY_SET_HANDLE_EXCEPTION (except); return 0; }