blob: 10fff3e6ca425a4904c4dc9c5df8ab7aa499aac5 [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
Juan Cespedes81690ef1998-03-13 19:31:29 +010011/* Returns 1 if the sysnum may make a new child to be created
12 * (ie, with fork() or clone())
13 * Returns 0 otherwise.
14 */
15int fork_p(int sysnum)
Juan Cespedes5e01f651998-03-08 22:31:44 +010016{
17 return (sysnum == __NR_fork || sysnum == __NR_clone);
18}
19
Juan Cespedes81690ef1998-03-13 19:31:29 +010020/* Returns 1 if the sysnum may make the process exec other program
21 */
22int exec_p(int sysnum)
23{
24 return (sysnum == __NR_execve);
25}
26
Juan Cespedes5e01f651998-03-08 22:31:44 +010027void trace_me(void)
28{
29 if (ptrace(PTRACE_TRACEME, 0, 1, 0)<0) {
30 perror("PTRACE_TRACEME");
31 exit(1);
32 }
33}
34
Juan Cespedes1fe93d51998-03-13 00:29:21 +010035void trace_pid(pid_t pid)
36{
37 if (ptrace(PTRACE_ATTACH, pid, 1, 0) < 0) {
38 perror("PTRACE_ATTACH");
39 }
40}
41
Juan Cespedes5e01f651998-03-08 22:31:44 +010042void continue_after_signal(pid_t pid, int signum)
43{
44 /* We should always trace syscalls to be able to control fork(), clone(), execve()... */
45#if 0
46 if (opt_S) {
47 ptrace(PTRACE_SYSCALL, pid, 1, signum);
48 } else {
49 ptrace(PTRACE_CONT, pid, 1, signum);
50 }
51#else
52 ptrace(PTRACE_SYSCALL, pid, 1, signum);
53#endif
54}
55
56void continue_process(pid_t pid)
57{
58 continue_after_signal(pid, 0);
59}
60
61void continue_enabling_breakpoint(pid_t pid, struct breakpoint * sbp)
62{
63 insert_breakpoint(pid, sbp);
64 continue_process(pid);
65}