![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Programmer
Join Date: May 2006
Location: Cambridge, UK
Posts: 88
Rep Power: 3
![]() |
Problems with signals and ptrace on Linux
I'm trying to use the PTRACE_GETSIGINFO and PTRACE_SETSIGINFO, but I'm running into problems.
This is the code of my "debuggee" #include <signal.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
static int globalValue;
void
my_INT_handler(int i, siginfo_t *si, void *uc)
{
++globalValue;
}
int
main(int argc, char **argv)
{
struct sigaction sa;
memset(&sa, 0, sizeof(sigaction));
sa.sa_sigaction = &my_INT_handler;
sa.sa_flags = SA_SIGINFO;
sigaction(SIGINT, &sa, NULL);
globalValue = 0;
while(1)
{
sleep(2);
printf("Value: %i\n", globalValue);
}
return(0);
}and this is the code of my "debugger" #include <signal.h>
#include <stdio.h>
#include <string.h>
#include <sys/ptrace.h>
#include <linux/ptrace.h>
int
main(int argc, char **argv)
{
int traced_process = atoi(argv[1]);
ptrace(PTRACE_ATTACH, traced_process, NULL, NULL);
while(1)
{
siginfo_t si;
memset(&si, 0, sizeof(siginfo_t));
wait(NULL);
printf("Received signal from child\n");
ptrace(PTRACE_GETSIGINFO, traced_process, NULL, &si);
printf("signo: %i errno: %i code: %i\n", si.si_signo, si.si_errno,
si.si_code);
ptrace(PTRACE_SETSIGINFO, traced_process, NULL, &si);
ptrace(PTRACE_CONT, traced_process, NULL, NULL);
}
return(0);
}If I run the debuggee on its own it works fine. It catches SIGINT and the global variable is increased as expected. When I attach the debugger SIGINTs get caught by the debugger, as expected. However, passing them on using PTRACE_SETSIGINFO doesn't work; the debuggee doesn't receive the signal at all. Anyone know what am I doing wrong here?
__________________
Don't comment bad code - rewrite it. - The Elements of Programming Style (Kernighan & Plaugher) |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|