Juan Cespedes | 5e01f65 | 1998-03-08 22:31:44 +0100 | [diff] [blame] | 1 | #include <stdio.h> |
| 2 | #include <sys/types.h> |
| 3 | #include <sys/ptrace.h> |
| 4 | #include <asm/unistd.h> |
| 5 | |
| 6 | #include "ltrace.h" |
| 7 | #include "options.h" |
| 8 | |
| 9 | /* Returns 1 if a new child is about to be created |
| 10 | (ie, with fork() or clone()) |
| 11 | Returns 0 otherwise. */ |
| 12 | int child_p(int sysnum) |
| 13 | { |
| 14 | return (sysnum == __NR_fork || sysnum == __NR_clone); |
| 15 | } |
| 16 | |
| 17 | void trace_me(void) |
| 18 | { |
| 19 | if (ptrace(PTRACE_TRACEME, 0, 1, 0)<0) { |
| 20 | perror("PTRACE_TRACEME"); |
| 21 | exit(1); |
| 22 | } |
| 23 | } |
| 24 | |
| 25 | void continue_after_signal(pid_t pid, int signum) |
| 26 | { |
| 27 | /* We should always trace syscalls to be able to control fork(), clone(), execve()... */ |
| 28 | #if 0 |
| 29 | if (opt_S) { |
| 30 | ptrace(PTRACE_SYSCALL, pid, 1, signum); |
| 31 | } else { |
| 32 | ptrace(PTRACE_CONT, pid, 1, signum); |
| 33 | } |
| 34 | #else |
| 35 | ptrace(PTRACE_SYSCALL, pid, 1, signum); |
| 36 | #endif |
| 37 | } |
| 38 | |
| 39 | void continue_process(pid_t pid) |
| 40 | { |
| 41 | continue_after_signal(pid, 0); |
| 42 | } |
| 43 | |
| 44 | void continue_enabling_breakpoint(pid_t pid, struct breakpoint * sbp) |
| 45 | { |
| 46 | insert_breakpoint(pid, sbp); |
| 47 | continue_process(pid); |
| 48 | } |