blob: 1068a8469d389711d87154ecca2a1d70cf2ef645 [file] [log] [blame]
Juan Cespedes5e01f651998-03-08 22:31:44 +01001#include <stdio.h>
Juan Cespedes1fe93d51998-03-13 00:29:21 +01002#include <string.h>
3#include <errno.h>
Juan Cespedes5e01f651998-03-08 22:31:44 +01004#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. */
14int child_p(int sysnum)
15{
16 return (sysnum == __NR_fork || sysnum == __NR_clone);
17}
18
19void trace_me(void)
20{
21 if (ptrace(PTRACE_TRACEME, 0, 1, 0)<0) {
22 perror("PTRACE_TRACEME");
23 exit(1);
24 }
25}
26
Juan Cespedes1fe93d51998-03-13 00:29:21 +010027void trace_pid(pid_t pid)
28{
29 if (ptrace(PTRACE_ATTACH, pid, 1, 0) < 0) {
30 perror("PTRACE_ATTACH");
31 }
32}
33
Juan Cespedes5e01f651998-03-08 22:31:44 +010034void 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
48void continue_process(pid_t pid)
49{
50 continue_after_signal(pid, 0);
51}
52
53void continue_enabling_breakpoint(pid_t pid, struct breakpoint * sbp)
54{
55 insert_breakpoint(pid, sbp);
56 continue_process(pid);
57}