Linux 3.5.4 Ptrace (series Nine) __linux

Source: Internet
Author: User

This paper mainly analyzes the single step debugging function of Ptrace

The meaning of Single-step debugging I believe that we have been very clear, ptrace_singlestep parameters can be tracked by the program to step.

Ptrace_singlestep Restarts the stopped program so that it executes an instruction and then stops. We use the following code to verify this.

list11.c

#include "ptrace.h"
void main (int argc,char *argv[])
{
  pid_t child;
  int status,data;
  int trace_process;
  Trace_process=atoi (argv[1]);
  Track the target process, attach to stop the tracked process (stopped)
  Ptrace (ptrace_attach,trace_process,0,0);
  Wait (&status);
  Prints the signal information
  if (wifstopped (status) {
    printf ("The stopped by the attach!\n") that causes the trace process to stop;
    fprintf (stderr, "%s\n", Strsignal (Wstopsig (status));
  }
  Wakes the tracked process in Single-step mode, after the trace process executes an instruction and stops.
    Ptrace (ptrace_singlestep,trace_process,0,0);
    while (1) {
    //printf ("Just to-1!\n");
    When the tracked process is single-step, the trace process stops, and the wait is awakened by wait
    (&status);
    Out of Loop
    if (wifexited (status) {
      fprintf (stderr, "%s", Strsignal (Wexitstatus (status)) when the process is being tracked to exit;
      printf ("The Child is Exit!\n");
      break;
    else{
    Step, know i=10 this statement, and then replace I with 245.
     Data=ptrace (ptrace_peekdata,trace_process,0x08049764,0);
     if (data==10) {
        printf ("The data now is%d\n", data);
        data=245;
        Ptrace (ptrace_pokedata,trace_process,0x08049764,data);
        Ptrace (ptrace_cont,trace_process,0,0);
        break;
      }
    }
   Ptrace (ptrace_singlestep,trace_process,0,0);
  }
The wait wakes at the end of the child process. Wait
  (&status);
  if (wifexited (status)) {
    printf ("The" "the" is over!\n);
  }
}

#include "ptrace.h"
int i;
void Main ()
{sleep
  ();
  printf ("The Child is Start!\n");
  i=10;
  printf ("child5:i=%d\n", I);
}


1. Compiling two source files

2, in a terminal running CHILD5.O

3, in another terminal running LIST11.O (also can be on the same terminal)

The results of the operation are as follows

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.