我正在使用 Ubuntu 12.04 操作系统,在一台32位的Intel机器上安装了linux-headers-3.2.0-60。我尝试编译这个简单的程序来理解PTrace,但在编译过程中出现错误。
#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;
}
我遇到了以下错误:
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
我检查了/usr/include/linux
文件夹,但是没有名为user.h
的文件。我尝试使用<sys/user.h>
,但是它产生了另一个错误。
../src/Test.cpp:18:38: error: ‘ORIG_EAX’ was not declared in this scope
请帮忙。