|
How can get I
get Aprobe actions to happen when my program dumps core?
By default, Aprobe doesn't interfere with the default signal handling
behavior. As such, if your program (or your probe) causes a memory
violation and dumps core, the normal program exit actions associated
with your probes will not be performed. However, here is a simple probe
that you can use with other probes to activate a probe and terminate
other probes normally when handling the signal. You can compile it once
(and call it whatever you want) and put it in $APROBE/ual_lib to use
when you need it.
#include <signal.h>
#include <stdlib.h>
#include <sys/ucontext.h>
static void HandlerFormat(
int *Signal,
ap_AddressT *Address)
{
printf(
"*********************************\n");
printf(
"Detected signal %d at:\n", *Signal);
ap_PrintAddress(*Address);
printf(
"*********************************\n");
}
// This is our handler:
static void MyHandler
(int sig, siginfo_t *sip, void *ucp)
{
ap_AddressT Address =
(ap_AddressT )
((ucontext_t *) ucp)
->uc_mcontext.gregs[REG_PC];
ap_Error(
ap_WarningSev,
"Signal %d detected. "
"Performing thread and program exit "
"actions.",
sig);
log (sig, Address) with HandlerFormat;
ap_EndProgram();
exit(1);
} /* MyHandler */
probe program
{
on_entry
{
// Register our handler
ap_RegisterSignalHandler (
SIGSEGV,
ap_CallBeforeUserAction,
MyHandler);
}
}
probe thread
{
typedef probe
{
on_entry
{
log("Entry to 'sigacthandler()'"
"with signal ", $1);
ap_LogTraceback (99);
}
} SigActHandlerProbe;
// Create instances of the above probe type:
SigActHandlerProbe One
("sigaction.c":"sigacthandler()"
in "libc.so");
SigActHandlerProbe Two
("sigaction.c":"sigacthandler()"
in "libthread.so");
}
|