调试原理
void run_target(const char* programname)
{
/* Allow tracing of this process */
if (ptrace(PTRACE_TRACEME, 0, 0, 0) < 0) {
perror("ptrace");
return;
}
/* Replace this process's image with the given program */
execl(programname, programname, 0);
}
main:
child_pid = fork();
if (child_pid == 0)
run_target(argv[1]);
else if (child_pid > 0)
{
wait(&wait_status);
check_SIG(WIFSTOPPED(wait_status));
do_debug(pid_t child_pid);
}
else {
perror("fork");
return -1;
}Last updated