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 | |
Juan Cespedes | 8cc1b9d | 2002-03-01 19:54:23 +0100 | [diff] [blame] | 15 | struct process * |
| 16 | open_program(char * filename) { |
Juan Cespedes | 273ea6d | 1998-03-14 23:02:40 +0100 | [diff] [blame] | 17 | struct process * proc; |
| 18 | proc = malloc(sizeof(struct process)); |
| 19 | if (!proc) { |
| 20 | perror("malloc"); |
| 21 | exit(1); |
| 22 | } |
Juan Cespedes | 5c3fe06 | 2004-06-14 18:08:37 +0200 | [diff] [blame^] | 23 | memset(proc, 0, sizeof(struct process)); |
Juan Cespedes | 273ea6d | 1998-03-14 23:02:40 +0100 | [diff] [blame] | 24 | proc->filename = filename; |
| 25 | proc->pid = 0; |
Juan Cespedes | cac15c3 | 2003-01-31 18:58:58 +0100 | [diff] [blame] | 26 | proc->breakpoints = NULL; |
Juan Cespedes | 273ea6d | 1998-03-14 23:02:40 +0100 | [diff] [blame] | 27 | proc->breakpoints_enabled = -1; |
Juan Cespedes | 5b3ffdf | 2001-07-02 00:52:45 +0200 | [diff] [blame] | 28 | proc->callstack_depth = 0; |
Juan Cespedes | 273ea6d | 1998-03-14 23:02:40 +0100 | [diff] [blame] | 29 | proc->breakpoint_being_enabled = NULL; |
Juan Cespedes | 7186e2a | 2003-01-31 19:56:34 +0100 | [diff] [blame] | 30 | breakpoints_init(proc); |
Juan Cespedes | 273ea6d | 1998-03-14 23:02:40 +0100 | [diff] [blame] | 31 | proc->next = NULL; |
Juan Cespedes | 273ea6d | 1998-03-14 23:02:40 +0100 | [diff] [blame] | 32 | |
| 33 | proc->next = list_of_processes; |
| 34 | list_of_processes = proc; |
| 35 | return proc; |
| 36 | } |
| 37 | |
Juan Cespedes | 8cc1b9d | 2002-03-01 19:54:23 +0100 | [diff] [blame] | 38 | void |
| 39 | open_pid(pid_t pid, int verbose) { |
Juan Cespedes | 273ea6d | 1998-03-14 23:02:40 +0100 | [diff] [blame] | 40 | struct process * proc; |
| 41 | char * filename; |
| 42 | |
Juan Cespedes | 35d7063 | 1998-03-15 14:05:40 +0100 | [diff] [blame] | 43 | if (trace_pid(pid)<0) { |
Juan Cespedes | 8cc1b9d | 2002-03-01 19:54:23 +0100 | [diff] [blame] | 44 | fprintf(stderr, "Cannot attach to pid %u: %s\n", pid, strerror(errno)); |
Juan Cespedes | 35d7063 | 1998-03-15 14:05:40 +0100 | [diff] [blame] | 45 | return; |
| 46 | } |
| 47 | |
Juan Cespedes | 273ea6d | 1998-03-14 23:02:40 +0100 | [diff] [blame] | 48 | filename = pid2name(pid); |
| 49 | |
Juan Cespedes | 35d7063 | 1998-03-15 14:05:40 +0100 | [diff] [blame] | 50 | #if 0 |
Juan Cespedes | 273ea6d | 1998-03-14 23:02:40 +0100 | [diff] [blame] | 51 | if (!filename) { |
| 52 | if (verbose) { |
| 53 | fprintf(stderr, "Cannot trace pid %u: %s\n", pid, strerror(errno)); |
| 54 | } |
| 55 | return; |
| 56 | } |
Juan Cespedes | 35d7063 | 1998-03-15 14:05:40 +0100 | [diff] [blame] | 57 | #endif |
Juan Cespedes | 273ea6d | 1998-03-14 23:02:40 +0100 | [diff] [blame] | 58 | |
| 59 | proc = open_program(filename); |
| 60 | proc->pid = pid; |
| 61 | } |