AIX

AIX

Connect with fellow AIX users and experts to gain knowledge, share insights, and solve problems.


#Power
 View Only
  • 1.  Ptrace and SI_UNDEFINED

    Posted Sun June 13, 2010 01:23 PM

    Originally posted by: Manolo123


    Hello everyone!

    I am currently developing an application on IBM Power 5+ system with AIX installed, here is the oslevel -g:
    
    Fileset                                 Actual Level        Maintenance Level ----------------------------------------------------------------------------- bos.rte                                 5.3.11.0            5.3.0.0
    


    I am using ptrace to trace the execution of the child process. Whenever the child stops, a SIGCHLD is sent to the parent, but the si_code part of siginfo_t always has the value of 8, which is SI_UNDEFINED. Here is my program:

    
    #include <sys/user.h> #include <sys/reg.h> #include <sys/ldr.h> #include <string.h>   #include <cstdlib> #include <iostream>   using namespace std;   
    
    void sigchld_act(
    
    int signo, siginfo_t *si, 
    
    void *v) 
    { cout << 
    "Signo: " << signo << endl; cout << 
    "si->code: " << si->si_code << endl; 
    }     
    
    int main(
    
    int argc, char** argv) 
    {   struct sigaction old; struct sigaction act; act.sa_sigaction = sigchld_act; act.sa_flags = SA_SIGINFO; sigemptyset(&act.sa_mask); sigaddset(&act.sa_mask, SIGCHLD);   
    
    if (sigaction(SIGCHLD, &act, &old) < 0) 
    { cout << 
    "SignalHandler:Sigaction SIGCHLD failed." << endl; 
    
    return 
    
    false; 
    }     pid_t child = fork(); 
    
    if (child < 0) 
    { perror(
    "Fork failed\n"); 
    } 
    
    else 
    
    if (child == 0) 
    { ptrace(PT_TRACE_ME, 0, 0, 0, 0); execvp(argv[1], &argv[1]); 
    } 
    
    else 
    { 
    
    while (1) 
    { 
    
    int status; wait(&status); 
    
    if (WIFEXITED(status)) 
    { cout << 
    "Child exited" << endl; 
    
    break; 
    } ptrace(PT_CONTINUE, child, (int*) 1, 0, NULL); 
    } 
    } 
    }
    


    And the result is:

    
    Signo: 20 si->code: 8 Ptrace --- Signo: 20 si->code: 10 Child exited
    


    The SI_UNDEFINED happens always when the SIGCHLD is sent, except for the situation when the child has exited, in this case si_code is CLD_EXITED as expected. But when I am performing single stepping along the instructions (with ptrace ofcourse), it is always 8. Does anyone know a cure for it?
    #AIX-Forum