Use uint32_t instead of u_long as a storage for breakpoint instruction
to copy. All the platforms breakpoints fits this fine. This fixes operation on big-endian MIPS64 where we were coping zeroes instead of real instruction. Reviewed by: rpaulo Sponsored by: DARPA, AFRL Sponsored by: HEIF5 Differential Revision: https://reviews.freebsd.org/D8250
This commit is contained in:
parent
87e1355ba5
commit
1d290950b2
@ -68,6 +68,14 @@ __FBSDID("$FreeBSD$");
|
||||
#error "Add support for your architecture"
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Use 4-bytes holder for breakpoint instruction on all the platforms.
|
||||
* Works for x86 as well until it is endian-little platform.
|
||||
* (We are coping one byte only on x86 from this 4-bytes piece of
|
||||
* memory).
|
||||
*/
|
||||
typedef uint32_t instr_t;
|
||||
|
||||
static int
|
||||
proc_stop(struct proc_handle *phdl)
|
||||
{
|
||||
@ -92,8 +100,9 @@ proc_bkptset(struct proc_handle *phdl, uintptr_t address,
|
||||
unsigned long *saved)
|
||||
{
|
||||
struct ptrace_io_desc piod;
|
||||
unsigned long paddr, caddr;
|
||||
unsigned long caddr;
|
||||
int ret = 0, stopped;
|
||||
instr_t instr;
|
||||
|
||||
*saved = 0;
|
||||
if (phdl->status == PS_DEAD || phdl->status == PS_UNDEAD ||
|
||||
@ -115,10 +124,10 @@ proc_bkptset(struct proc_handle *phdl, uintptr_t address,
|
||||
* Read the original instruction.
|
||||
*/
|
||||
caddr = address;
|
||||
paddr = 0;
|
||||
instr = 0;
|
||||
piod.piod_op = PIOD_READ_I;
|
||||
piod.piod_offs = (void *)caddr;
|
||||
piod.piod_addr = &paddr;
|
||||
piod.piod_addr = &instr;
|
||||
piod.piod_len = BREAKPOINT_INSTR_SZ;
|
||||
if (ptrace(PT_IO, proc_getpid(phdl), (caddr_t)&piod, 0) < 0) {
|
||||
DPRINTF("ERROR: couldn't read instruction at address 0x%"
|
||||
@ -126,15 +135,15 @@ proc_bkptset(struct proc_handle *phdl, uintptr_t address,
|
||||
ret = -1;
|
||||
goto done;
|
||||
}
|
||||
*saved = paddr;
|
||||
*saved = instr;
|
||||
/*
|
||||
* Write a breakpoint instruction to that address.
|
||||
*/
|
||||
caddr = address;
|
||||
paddr = BREAKPOINT_INSTR;
|
||||
instr = BREAKPOINT_INSTR;
|
||||
piod.piod_op = PIOD_WRITE_I;
|
||||
piod.piod_offs = (void *)caddr;
|
||||
piod.piod_addr = &paddr;
|
||||
piod.piod_addr = &instr;
|
||||
piod.piod_len = BREAKPOINT_INSTR_SZ;
|
||||
if (ptrace(PT_IO, proc_getpid(phdl), (caddr_t)&piod, 0) < 0) {
|
||||
DPRINTF("ERROR: couldn't write instruction at address 0x%"
|
||||
@ -156,8 +165,9 @@ proc_bkptdel(struct proc_handle *phdl, uintptr_t address,
|
||||
unsigned long saved)
|
||||
{
|
||||
struct ptrace_io_desc piod;
|
||||
unsigned long paddr, caddr;
|
||||
unsigned long caddr;
|
||||
int ret = 0, stopped;
|
||||
instr_t instr;
|
||||
|
||||
if (phdl->status == PS_DEAD || phdl->status == PS_UNDEAD ||
|
||||
phdl->status == PS_IDLE) {
|
||||
@ -178,10 +188,10 @@ proc_bkptdel(struct proc_handle *phdl, uintptr_t address,
|
||||
* Overwrite the breakpoint instruction that we setup previously.
|
||||
*/
|
||||
caddr = address;
|
||||
paddr = saved;
|
||||
instr = saved;
|
||||
piod.piod_op = PIOD_WRITE_I;
|
||||
piod.piod_offs = (void *)caddr;
|
||||
piod.piod_addr = &paddr;
|
||||
piod.piod_addr = &instr;
|
||||
piod.piod_len = BREAKPOINT_INSTR_SZ;
|
||||
if (ptrace(PT_IO, proc_getpid(phdl), (caddr_t)&piod, 0) < 0) {
|
||||
DPRINTF("ERROR: couldn't write instruction at address 0x%"
|
||||
|
Loading…
Reference in New Issue
Block a user