Solution to no such file error reported by ptrace on 64-bit centos

Source: Internet
Author: User

First, we will introduce ptrace:

Ptrace provides a way for the parent process to monitor and control other processes. It can also change the registers and kernel images in sub-processes, so that it can implement breakpoint debugging and tracing of system calls.
With ptrace, You can intercept and modify system calls at the user layer)

Take an instance as an example:

#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 ", orig_eax);         ptrace(PTRACE_CONT, child, NULL, NULL);     }     return 0;}

The error message <Linux/user. h> no such file... is returned after running gcc-o xxxx. C.
The cause of the error is that the kernel structure changes from/usr/include/Linux/user. h to/usr/include/sys/Reg. h.
Therefore, you need to change the # include Linux/user. h> statement to # include <sys/Reg. h> during debugging.
Of course, an error will still be reported after modification because the 64-bit register structure is different from that of 32-bit. The solution is to change orig_eax to orig_rax to run successfully.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.