PTrace: linux/user.h: No such file or directory

Nishant Kumar picture Nishant Kumar · Mar 9, 2014 · Viewed 12.8k times · Source

I am using Ubuntu 12.04 with linux-headers-3.2.0-60 on intel 32-bit machine.I am trying to build this simple program to understand PTrace. But getting error during compilation.

#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;
}

I am getting these error:

make all 
Building file: ../src/Test.cpp
Invoking: Cross G++ Compiler
g++ -I/usr/local/include/boost -O0 -g3 -Wall -c -fmessage-length=0  -pthread -MMD -MP -MF"src/Test.d" -MT"src/Test.d" -o "src/Test.o" "../src/Test.cpp"
../src/Test.cpp:6:51: fatal error: linux/user.h: No such file or directory
compilation terminated.
make: *** [src/Test.o] Error 1

I checked my /usr/include/linux folder but there is no file named user.h. I tried with <sys/user.h> but it gave another error.

../src/Test.cpp:18:38: error: ‘ORIG_EAX’ was not declared in this scope

Please help.

Answer

sheeru picture sheeru · Mar 9, 2014

Try including sys/user.h and sys/reg.h ORIG_EAX is defined in reg.h