void arch_kgdb_set_sw_break(struct kgdb_bkpt *bkpt) { int addr = bkpt->bpt_addr; memcpy(bkpt->saved_instr, (unsigned long *)addr, BREAK_INSTR_SIZE); *(unsigned long *)addr = KGDB_COMPILED_BREAK; kgdb_flush_cache_all(); }
/* * This function does all command processing for interfacing to gdb. */ static int handle_exception (struct pt_regs *regs) { int addr; int length; char *ptr; kgdb_data kd; int i; if (!initialized) { printf("kgdb: exception before kgdb is initialized! huh?\n"); return (0); } /* probably should check which exception occured as well */ if (longjmp_on_fault) { longjmp_on_fault = 0; kgdb_longjmp(error_jmp_buf, KGDBERR_MEMFAULT); panic("kgdb longjump failed!\n"); } if (kgdb_active) { printf("kgdb: unexpected exception from within kgdb\n"); return (0); } kgdb_active = 1; kgdb_interruptible(0); printf("kgdb: handle_exception; trap [0x%x]\n", kgdb_trap(regs)); if (kgdb_setjmp(error_jmp_buf) != 0) panic("kgdb: error or fault in entry init!\n"); kgdb_enter(regs, &kd); if (first_entry) { /* * the first time we enter kgdb, we save the processor * state so that we can return to the monitor if the * remote end quits gdb (or at least, tells us to quit * with the 'k' packet) */ entry_regs = *regs; first_entry = 0; } ptr = remcomOutBuffer; *ptr++ = 'T'; *ptr++ = hexchars[kd.sigval >> 4]; *ptr++ = hexchars[kd.sigval & 0xf]; for (i = 0; i < kd.nregs; i++) { kgdb_reg *rp = &kd.regs[i]; *ptr++ = hexchars[rp->num >> 4]; *ptr++ = hexchars[rp->num & 0xf]; *ptr++ = ':'; ptr = (char *)mem2hex((char *)&rp->val, ptr, 4); *ptr++ = ';'; } *ptr = 0; #ifdef KGDB_DEBUG if (kdebug) printf("kgdb: remcomOutBuffer: %s\n", remcomOutBuffer); #endif putpacket((unsigned char *)&remcomOutBuffer); while (1) { volatile int errnum; remcomOutBuffer[0] = 0; getpacket(remcomInBuffer); ptr = &remcomInBuffer[1]; #ifdef KGDB_DEBUG if (kdebug) printf("kgdb: remcomInBuffer: %s\n", remcomInBuffer); #endif errnum = kgdb_setjmp(error_jmp_buf); if (errnum == 0) switch (remcomInBuffer[0]) { case '?': /* report most recent signal */ remcomOutBuffer[0] = 'S'; remcomOutBuffer[1] = hexchars[kd.sigval >> 4]; remcomOutBuffer[2] = hexchars[kd.sigval & 0xf]; remcomOutBuffer[3] = 0; break; #ifdef KGDB_DEBUG case 'd': /* toggle debug flag */ kdebug ^= 1; break; #endif case 'g': /* return the value of the CPU registers. */ length = kgdb_getregs(regs, remcomRegBuffer, BUFMAX); mem2hex(remcomRegBuffer, remcomOutBuffer, length); break; case 'G': /* set the value of the CPU registers */ length = strlen(ptr); if ((length & 1) != 0) kgdb_error(KGDBERR_BADPARAMS); hex2mem(ptr, remcomRegBuffer, length/2); kgdb_putregs(regs, remcomRegBuffer, length/2); strcpy(remcomOutBuffer,"OK"); break; case 'm': /* mAA..AA,LLLL Read LLLL bytes at address AA..AA */ /* Try to read %x,%x. */ if (hexToInt(&ptr, &addr) && *ptr++ == ',' && hexToInt(&ptr, &length)) { mem2hex((char *)addr, remcomOutBuffer, length); } else { kgdb_error(KGDBERR_BADPARAMS); } break; case 'M': /* MAA..AA,LLLL: Write LLLL bytes at address AA.AA return OK */ /* Try to read '%x,%x:'. */ if (hexToInt(&ptr, &addr) && *ptr++ == ',' && hexToInt(&ptr, &length) && *ptr++ == ':') { hex2mem(ptr, (char *)addr, length); strcpy(remcomOutBuffer, "OK"); } else { kgdb_error(KGDBERR_BADPARAMS); } break; case 'k': /* kill the program, actually return to monitor */ kd.extype = KGDBEXIT_KILL; *regs = entry_regs; first_entry = 1; goto doexit; case 'C': /* CSS continue with signal SS */ *ptr = '\0'; /* ignore the signal number for now */ /* fall through */ case 'c': /* cAA..AA Continue; address AA..AA optional */ /* try to read optional parameter, pc unchanged if no parm */ kd.extype = KGDBEXIT_CONTINUE; if (hexToInt(&ptr, &addr)) { kd.exaddr = addr; kd.extype |= KGDBEXIT_WITHADDR; } goto doexit; case 'S': /* SSS single step with signal SS */ *ptr = '\0'; /* ignore the signal number for now */ /* fall through */ case 's': kd.extype = KGDBEXIT_SINGLE; if (hexToInt(&ptr, &addr)) { kd.exaddr = addr; kd.extype |= KGDBEXIT_WITHADDR; } doexit: /* Need to flush the instruction cache here, as we may have deposited a * breakpoint, and the icache probably has no way of knowing that a data ref to * some location may have changed something that is in the instruction cache. */ kgdb_flush_cache_all(); kgdb_exit(regs, &kd); kgdb_active = 0; kgdb_interruptible(1); return (1); case 'r': /* Reset (if user process..exit ???)*/ panic("kgdb reset."); break; case 'P': /* Pr=v set reg r to value v (r and v are hex) */ if (hexToInt(&ptr, &addr) && *ptr++ == '=' && ((length = strlen(ptr)) & 1) == 0) { hex2mem(ptr, remcomRegBuffer, length/2); kgdb_putreg(regs, addr, remcomRegBuffer, length/2); strcpy(remcomOutBuffer,"OK"); } else { kgdb_error(KGDBERR_BADPARAMS); } break; } /* switch */ if (errnum != 0) sprintf(remcomOutBuffer, "E%02d", errnum); #ifdef KGDB_DEBUG if (kdebug) printf("kgdb: remcomOutBuffer: %s\n", remcomOutBuffer); #endif /* reply to the request */ putpacket((unsigned char *)&remcomOutBuffer); } /* while(1) */ }
void arch_kgdb_remove_sw_break(struct kgdb_bkpt *bkpt) { int addr = bkpt->bpt_addr; memcpy((unsigned long *)addr, bkpt->saved_instr, BREAK_INSTR_SIZE); kgdb_flush_cache_all(); }