Debugging ptrace

Jul 17, 2012 at 7:23pm
Hi,
2 Questions!

1.
I am relatively new to coding on linux, I have a requirement to understand 'ptrace' code. Can somebody suggest how I could get the source code for this?

I am using Linux Mint, and tried an apt-get source ptrace, but get the following error,

E: Unable to find a source package for ptrace



2.
I also tried running the following code from the linuxjournal.com

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#include <sys/ptrace.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
#include <linux/user.h>   /* For constants
                                   ORIG_EAX etc */
int main()
{   pid_t child;
    long orig_eax;
    child = fork();
    if(child == 0) {
        ptrace(PTRACE_TRACEME, 0, NULL, NULL);
        execl("/bin/ls", "ls", NULL);
    }
    else {
        wait(NULL);
        orig_eax = ptrace(PTRACE_PEEKUSER,
                          child, 4 * ORIG_EAX,
                          NULL);
        printf("The child made a "
               "system call %ld\n", orig_eax);
        ptrace(PTRACE_CONT, child, NULL, NULL);
    }
    return 0;
}


but get the following error when compiling

gcc samp_ptrace.c -o samp_ptrace.o
samp_ptrace.c:6:51: fatal error: linux/user.h: No such file or directory
compilation terminated.


Can someone help me in resolving this?
Last edited on Jul 17, 2012 at 7:36pm
Jul 18, 2012 at 4:05am
Can somebody suggest how I could get the source code for this?
ptrace() is part of the kernel. So, basically, just grab a Linux source tarball.

I don't know about linux/user.h, but this is the first Google hit:
Date: Mon, 16 Nov 2009 22:12:45 -0800

[gccgo] Don't use <linux/user.h>

Newer kernel versions don't provide <linux/user.h>. This patch
changes the libgo build to not try to use it, but to use
<sys/user.h>. I was using <linux/user.h> because it gives more useful
values for cs, ds, etc., so this patch also changes the sed script to
get those back.
Jul 18, 2012 at 10:59am
Thanks!
Topic archived. No new replies allowed.