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