If the traced process stops because it received a signal, libproc needs
to ensure that the signal is forwarded when proc_continue() is called. MFC after: 3 weeks
This commit is contained in:
parent
baf69d5639
commit
bddfd9feb6
@ -102,6 +102,7 @@ typedef struct lwpstatus {
|
|||||||
#define PR_FAULTED 2
|
#define PR_FAULTED 2
|
||||||
#define PR_SYSENTRY 3
|
#define PR_SYSENTRY 3
|
||||||
#define PR_SYSEXIT 4
|
#define PR_SYSEXIT 4
|
||||||
|
#define PR_SIGNALLED 5
|
||||||
int pr_what;
|
int pr_what;
|
||||||
#define FLTBPT -1
|
#define FLTBPT -1
|
||||||
} lwpstatus_t;
|
} lwpstatus_t;
|
||||||
|
@ -55,13 +55,6 @@ __FBSDID("$FreeBSD$");
|
|||||||
#error "Add support for your architecture"
|
#error "Add support for your architecture"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static void
|
|
||||||
proc_cont(struct proc_handle *phdl)
|
|
||||||
{
|
|
||||||
|
|
||||||
ptrace(PT_CONTINUE, proc_getpid(phdl), (caddr_t)1, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
proc_stop(struct proc_handle *phdl)
|
proc_stop(struct proc_handle *phdl)
|
||||||
{
|
{
|
||||||
@ -87,7 +80,7 @@ proc_bkptset(struct proc_handle *phdl, uintptr_t address,
|
|||||||
{
|
{
|
||||||
struct ptrace_io_desc piod;
|
struct ptrace_io_desc piod;
|
||||||
unsigned long paddr, caddr;
|
unsigned long paddr, caddr;
|
||||||
int ret = 0;
|
int ret = 0, stopped;
|
||||||
|
|
||||||
*saved = 0;
|
*saved = 0;
|
||||||
if (phdl->status == PS_DEAD || phdl->status == PS_UNDEAD ||
|
if (phdl->status == PS_DEAD || phdl->status == PS_UNDEAD ||
|
||||||
@ -98,9 +91,12 @@ proc_bkptset(struct proc_handle *phdl, uintptr_t address,
|
|||||||
|
|
||||||
DPRINTFX("adding breakpoint at 0x%lx", address);
|
DPRINTFX("adding breakpoint at 0x%lx", address);
|
||||||
|
|
||||||
if (phdl->status != PS_STOP)
|
stopped = 0;
|
||||||
|
if (phdl->status != PS_STOP) {
|
||||||
if (proc_stop(phdl) != 0)
|
if (proc_stop(phdl) != 0)
|
||||||
return (-1);
|
return (-1);
|
||||||
|
stopped = 1;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Read the original instruction.
|
* Read the original instruction.
|
||||||
@ -135,9 +131,9 @@ proc_bkptset(struct proc_handle *phdl, uintptr_t address,
|
|||||||
}
|
}
|
||||||
|
|
||||||
done:
|
done:
|
||||||
if (phdl->status != PS_STOP)
|
if (stopped)
|
||||||
/* Restart the process if we had to stop it. */
|
/* Restart the process if we had to stop it. */
|
||||||
proc_cont(phdl);
|
proc_continue(phdl);
|
||||||
|
|
||||||
return (ret);
|
return (ret);
|
||||||
}
|
}
|
||||||
@ -148,7 +144,7 @@ proc_bkptdel(struct proc_handle *phdl, uintptr_t address,
|
|||||||
{
|
{
|
||||||
struct ptrace_io_desc piod;
|
struct ptrace_io_desc piod;
|
||||||
unsigned long paddr, caddr;
|
unsigned long paddr, caddr;
|
||||||
int ret = 0;
|
int ret = 0, stopped;
|
||||||
|
|
||||||
if (phdl->status == PS_DEAD || phdl->status == PS_UNDEAD ||
|
if (phdl->status == PS_DEAD || phdl->status == PS_UNDEAD ||
|
||||||
phdl->status == PS_IDLE) {
|
phdl->status == PS_IDLE) {
|
||||||
@ -158,9 +154,12 @@ proc_bkptdel(struct proc_handle *phdl, uintptr_t address,
|
|||||||
|
|
||||||
DPRINTFX("removing breakpoint at 0x%lx", address);
|
DPRINTFX("removing breakpoint at 0x%lx", address);
|
||||||
|
|
||||||
if (phdl->status != PS_STOP)
|
stopped = 0;
|
||||||
|
if (phdl->status != PS_STOP) {
|
||||||
if (proc_stop(phdl) != 0)
|
if (proc_stop(phdl) != 0)
|
||||||
return (-1);
|
return (-1);
|
||||||
|
stopped = 1;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Overwrite the breakpoint instruction that we setup previously.
|
* Overwrite the breakpoint instruction that we setup previously.
|
||||||
@ -177,9 +176,9 @@ proc_bkptdel(struct proc_handle *phdl, uintptr_t address,
|
|||||||
ret = -1;
|
ret = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (phdl->status != PS_STOP)
|
if (stopped)
|
||||||
/* Restart the process if we had to stop it. */
|
/* Restart the process if we had to stop it. */
|
||||||
proc_cont(phdl);
|
proc_continue(phdl);
|
||||||
|
|
||||||
return (ret);
|
return (ret);
|
||||||
}
|
}
|
||||||
|
@ -35,10 +35,9 @@
|
|||||||
#include <sys/wait.h>
|
#include <sys/wait.h>
|
||||||
#include <err.h>
|
#include <err.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <unistd.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <unistd.h>
|
||||||
#include "_libproc.h"
|
#include "_libproc.h"
|
||||||
|
|
||||||
int
|
int
|
||||||
@ -59,11 +58,14 @@ proc_clearflags(struct proc_handle *phdl, int mask)
|
|||||||
int
|
int
|
||||||
proc_continue(struct proc_handle *phdl)
|
proc_continue(struct proc_handle *phdl)
|
||||||
{
|
{
|
||||||
|
int pending = 0;
|
||||||
|
|
||||||
if (phdl == NULL)
|
if (phdl == NULL)
|
||||||
return (-1);
|
return (-1);
|
||||||
|
|
||||||
if (ptrace(PT_CONTINUE, phdl->pid, (caddr_t)(uintptr_t) 1, 0) != 0)
|
if (phdl->status == PS_STOP && WSTOPSIG(phdl->wstat) != SIGTRAP)
|
||||||
|
pending = WSTOPSIG(phdl->wstat);
|
||||||
|
if (ptrace(PT_CONTINUE, phdl->pid, (caddr_t)(uintptr_t)1, pending) != 0)
|
||||||
return (-1);
|
return (-1);
|
||||||
|
|
||||||
phdl->status = PS_RUN;
|
phdl->status = PS_RUN;
|
||||||
@ -208,12 +210,16 @@ proc_getlwpstatus(struct proc_handle *phdl)
|
|||||||
return (NULL);
|
return (NULL);
|
||||||
siginfo = &lwpinfo.pl_siginfo;
|
siginfo = &lwpinfo.pl_siginfo;
|
||||||
if (lwpinfo.pl_event == PL_EVENT_SIGNAL &&
|
if (lwpinfo.pl_event == PL_EVENT_SIGNAL &&
|
||||||
(lwpinfo.pl_flags & PL_FLAG_SI) &&
|
(lwpinfo.pl_flags & PL_FLAG_SI) != 0) {
|
||||||
siginfo->si_signo == SIGTRAP &&
|
if (siginfo->si_signo == SIGTRAP &&
|
||||||
(siginfo->si_code == TRAP_BRKPT ||
|
(siginfo->si_code == TRAP_BRKPT ||
|
||||||
siginfo->si_code == TRAP_TRACE)) {
|
siginfo->si_code == TRAP_TRACE)) {
|
||||||
psp->pr_why = PR_FAULTED;
|
psp->pr_why = PR_FAULTED;
|
||||||
psp->pr_what = FLTBPT;
|
psp->pr_what = FLTBPT;
|
||||||
|
} else {
|
||||||
|
psp->pr_why = PR_SIGNALLED;
|
||||||
|
psp->pr_what = siginfo->si_signo;
|
||||||
|
}
|
||||||
} else if (lwpinfo.pl_flags & PL_FLAG_SCE) {
|
} else if (lwpinfo.pl_flags & PL_FLAG_SCE) {
|
||||||
psp->pr_why = PR_SYSENTRY;
|
psp->pr_why = PR_SYSENTRY;
|
||||||
} else if (lwpinfo.pl_flags & PL_FLAG_SCX) {
|
} else if (lwpinfo.pl_flags & PL_FLAG_SCX) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user