Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Dec 9th, 2006, 6:22 PM   #1
magnus.therning
Programmer
 
magnus.therning's Avatar
 
Join Date: May 2006
Location: Cambridge, UK
Posts: 88
Rep Power: 3 magnus.therning is on a distinguished road
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)
magnus.therning is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 5:59 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC