- ptrace_detach, SIGINT and trace/breakpoint trap (core dumped)
- void sig_int()
- {
- if (ptrace(PTRACE_DETACH, pid, NULL, NULL) == -1)
- my_perror("ptrace / DETACH", strerror(errno));
- }
- if ((ptrace(PTRACE_SINGLESTEP, pid, NULL, NULL) == -1))
- my_perror("ptrace / SINGLESTEP", strerror(errno));
- if (wait4(pid, &(l->status), 0, 0) == -1)
- my_perror("wait4", strerror(errno));
- if (ptrace(PTRACE_GETREGS, pid, 0, &(l->reg)) == -1)
- my_perror("ptrace / GETREGS", strerror(errno));
- if ((l->opcode = ptrace(PTRACE_PEEKTEXT, pid, l->reg.rip, NULL)) == -1)
- my_perror("ptrace / PEEKTEXT", strerror(errno));
- void int_sig()
- {
- if (stop == 0)
- {
- printf("Interrupting!n");
- ptrace(PTRACE_CONT, pid, NULL, NULL);
- exit(0);
- }
- }
- void do_step(t_list *l)
- {
- if ((ptrace(PTRACE_SINGLESTEP, pid, NULL, NULL) == -1))
- my_perror("ptrace / SINGLESTEP", strerror(errno));
- if (wait4(pid, &(l->status), 0, 0) == -1)
- my_perror("wait4", strerror(errno));
- if (ptrace(PTRACE_GETREGS, pid, 0, &(l->reg)) == -1)
- my_perror("ptrace / GETREGS", strerror(errno));
- if ((l->opcode = ptrace(PTRACE_PEEKTEXT, pid, l->reg.rip, NULL)) == -1)
- my_perror("ptrace / PEEKTEXT", strerror(errno));
- }
- void do_next_step(t_list *l, t_strace *t)
- {
- stop = 1;
- if (ptrace(PTRACE_SINGLESTEP, pid, NULL, NULL) == -1 ||
- (wait4(pid, &(l->status), 0, 0) == -1))
- my_perror("ERROR", strerror(errno));
- if (!WIFSTOPPED(l->status) || WIFEXITED(l->status))
- {
- printf("?n");
- exit(0);
- }
- if (ptrace(PTRACE_GETREGS, pid, 0, &(l->reg)) == -1)
- my_perror("ptrace / GETREGS", strerror(errno));
- if (t->ret == 1)
- printf("%dn", (int)l->reg.rax);
- else
- printf("%#lxn", l->reg.rax);
- stop = 0;
- }