Juan Cespedes | d44c6b8 | 1998-09-25 14:48:42 +0200 | [diff] [blame] | 1 | #if HAVE_CONFIG_H |
| 2 | #include "config.h" |
| 3 | #endif |
| 4 | |
Juan Cespedes | 273ea6d | 1998-03-14 23:02:40 +0100 | [diff] [blame] | 5 | #include <sys/types.h> |
| 6 | #include <string.h> |
| 7 | #include <stdio.h> |
| 8 | #include <errno.h> |
| 9 | #include <stdlib.h> |
| 10 | |
| 11 | #include "ltrace.h" |
| 12 | #include "options.h" |
| 13 | #include "elf.h" |
| 14 | |
Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 15 | struct process *open_program(char *filename, pid_t pid) |
| 16 | { |
| 17 | struct process *proc; |
Ian Wienand | 9a2ad35 | 2006-02-20 22:44:45 +0100 | [diff] [blame] | 18 | proc = calloc(sizeof(struct process), 1); |
Juan Cespedes | 273ea6d | 1998-03-14 23:02:40 +0100 | [diff] [blame] | 19 | if (!proc) { |
| 20 | perror("malloc"); |
| 21 | exit(1); |
| 22 | } |
| 23 | proc->filename = filename; |
Juan Cespedes | 273ea6d | 1998-03-14 23:02:40 +0100 | [diff] [blame] | 24 | proc->breakpoints_enabled = -1; |
Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 25 | if (pid) { |
| 26 | proc->pid = pid; |
| 27 | } |
Juan Cespedes | 7186e2a | 2003-01-31 19:56:34 +0100 | [diff] [blame] | 28 | breakpoints_init(proc); |
Juan Cespedes | 273ea6d | 1998-03-14 23:02:40 +0100 | [diff] [blame] | 29 | |
| 30 | proc->next = list_of_processes; |
| 31 | list_of_processes = proc; |
| 32 | return proc; |
| 33 | } |
| 34 | |
Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 35 | void open_pid(pid_t pid, int verbose) |
| 36 | { |
| 37 | struct process *proc; |
| 38 | char *filename; |
Juan Cespedes | 273ea6d | 1998-03-14 23:02:40 +0100 | [diff] [blame] | 39 | |
Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 40 | if (trace_pid(pid) < 0) { |
| 41 | fprintf(stderr, "Cannot attach to pid %u: %s\n", pid, |
| 42 | strerror(errno)); |
Juan Cespedes | 35d7063 | 1998-03-15 14:05:40 +0100 | [diff] [blame] | 43 | return; |
| 44 | } |
| 45 | |
Juan Cespedes | 273ea6d | 1998-03-14 23:02:40 +0100 | [diff] [blame] | 46 | filename = pid2name(pid); |
| 47 | |
Juan Cespedes | 35d7063 | 1998-03-15 14:05:40 +0100 | [diff] [blame] | 48 | #if 0 |
Juan Cespedes | 273ea6d | 1998-03-14 23:02:40 +0100 | [diff] [blame] | 49 | if (!filename) { |
| 50 | if (verbose) { |
Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 51 | fprintf(stderr, "Cannot trace pid %u: %s\n", pid, |
| 52 | strerror(errno)); |
Juan Cespedes | 273ea6d | 1998-03-14 23:02:40 +0100 | [diff] [blame] | 53 | } |
| 54 | return; |
| 55 | } |
Juan Cespedes | 35d7063 | 1998-03-15 14:05:40 +0100 | [diff] [blame] | 56 | #endif |
Juan Cespedes | 273ea6d | 1998-03-14 23:02:40 +0100 | [diff] [blame] | 57 | |
Ian Wienand | 9a2ad35 | 2006-02-20 22:44:45 +0100 | [diff] [blame] | 58 | proc = open_program(filename, pid); |
Juan Cespedes | aee0931 | 2007-08-31 18:49:48 +0200 | [diff] [blame^] | 59 | continue_process(pid); |
Ian Wienand | 9a2ad35 | 2006-02-20 22:44:45 +0100 | [diff] [blame] | 60 | proc->breakpoints_enabled = 1; |
Juan Cespedes | 273ea6d | 1998-03-14 23:02:40 +0100 | [diff] [blame] | 61 | } |