Porting strace - compile problem

Marcus Mikolaiczyk marcus.mikolaiczyk at carmedialab.de
Thu Feb 8 13:55:56 UTC 2007


> The compiled binary has a problem in strace.c at about line 2424:
> ...
>  tracing:
>                 if (ptrace(PTRACE_SYSCALL, pid, (char *) 1, 0) < 0) {
>                         perror("trace: ptrace(PTRACE_SYSCALL, ...)");
>                         cleanup();
>                         return -1;
> ...
> This is where it complains.
> bash-2.05a# /mnt/tmp/install/strace echo hello
> trace: ptrace(PTRACE_SYSCALL, ...): No such process

I configured the kernel to give out the ptrace call and its values.
in strace.c I changed
tracing:
           RETVAL=ptrace(PTRACE_SYSCALL, pid, (char *) 1, 0);
           printf("*** tracing: RETVAL=%d , PID=%d \n",TESTVAL,pid);
           /*if (ptrace(PTRACE_SYSCALL, pid, (char *) 1, 0) < 0) {*/
           if ( TESTVAL < 0) {
                   perror("trace: ptrace(PTRACE_SYSCALL, ...)");
                   cleanup();
                   return -1;
           }
With the folowing result:
bash-2.05a# ./strace echo hallo
*** tracing PID=71 : RETVAL=-1
trace: ptrace(PTRACE_SYSCALL, ...): No such process

KernDebug output  PTRACE_SYSCALL=24:
sys_ptrace: req 0, pid 0, addr 00000000 data 00000000
sys_ptrace: req 24, pid 0, addr 00000000 data 00000000

Here it's obivous that the pid is definitely not the one I wanted.

In the kernel (ptrace.c) the sys_ptrace function is of the folowing type:
 asmlinkage int sys_ptrace(long request, long pid, long addr, long data)

Regarding strace.c and specialy defs.h ptrace is kind of:
 extern long ptrace(int, int, char *, long);
or
 extern int ptrace(int, int, char *, int, ...);

I'm not the guru programmer so can this be the cause? Why is the PID
lost but not the "action" (PTRACE_SYSCALL=24). int/long format conversion?


> Question:
> - Can I test/see that strace is able to call a ptrace routine to have
> the confirmation that it can at least communicate with the kernels function?
this is done so far.


> - Must ptrace be an exported symbol (kernel 2.4.19)?
No, because the above one is working.





More information about the Strace-devel mailing list