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