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 | |
| 15 | struct process * open_program(char * filename) |
| 16 | { |
| 17 | struct process * proc; |
| 18 | proc = malloc(sizeof(struct process)); |
| 19 | if (!proc) { |
| 20 | perror("malloc"); |
| 21 | exit(1); |
| 22 | } |
| 23 | proc->filename = filename; |
| 24 | proc->pid = 0; |
| 25 | proc->breakpoints_enabled = -1; |
| 26 | proc->current_syscall = -1; |
| 27 | proc->current_symbol = NULL; |
| 28 | proc->breakpoint_being_enabled = NULL; |
| 29 | proc->next = NULL; |
Juan Cespedes | 35d7063 | 1998-03-15 14:05:40 +0100 | [diff] [blame] | 30 | if (opt_L && filename) { |
Juan Cespedes | 273ea6d | 1998-03-14 23:02:40 +0100 | [diff] [blame] | 31 | proc->list_of_symbols = read_elf(filename); |
Juan Cespedes | ac3db29 | 1998-04-25 14:31:58 +0200 | [diff] [blame] | 32 | if (opt_e) { |
| 33 | struct library_symbol ** tmp1 = &(proc->list_of_symbols); |
| 34 | while(*tmp1) { |
| 35 | struct opt_e_t * tmp2 = opt_e; |
| 36 | int keep = !opt_e_enable; |
| 37 | |
| 38 | while(tmp2) { |
| 39 | if (!strcmp((*tmp1)->name, tmp2->name)) { |
| 40 | keep = opt_e_enable; |
| 41 | } |
| 42 | tmp2 = tmp2->next; |
| 43 | } |
| 44 | if (!keep) { |
| 45 | *tmp1 = (*tmp1)->next; |
| 46 | } else { |
| 47 | tmp1 = &((*tmp1)->next); |
| 48 | } |
| 49 | } |
| 50 | } |
Juan Cespedes | 273ea6d | 1998-03-14 23:02:40 +0100 | [diff] [blame] | 51 | } else { |
| 52 | proc->list_of_symbols = NULL; |
| 53 | } |
| 54 | |
| 55 | proc->next = list_of_processes; |
| 56 | list_of_processes = proc; |
| 57 | return proc; |
| 58 | } |
| 59 | |
| 60 | void open_pid(pid_t pid, int verbose) |
| 61 | { |
| 62 | struct process * proc; |
| 63 | char * filename; |
| 64 | |
Juan Cespedes | 35d7063 | 1998-03-15 14:05:40 +0100 | [diff] [blame] | 65 | if (trace_pid(pid)<0) { |
| 66 | #if 0 |
| 67 | if (verbose) { |
| 68 | #endif |
| 69 | fprintf(stderr, "Cannot attach to pid %u: %s\n", pid, strerror(errno)); |
| 70 | #if 0 |
| 71 | } |
| 72 | #endif |
| 73 | return; |
| 74 | } |
| 75 | |
Juan Cespedes | 273ea6d | 1998-03-14 23:02:40 +0100 | [diff] [blame] | 76 | filename = pid2name(pid); |
| 77 | |
Juan Cespedes | 35d7063 | 1998-03-15 14:05:40 +0100 | [diff] [blame] | 78 | #if 0 |
Juan Cespedes | 273ea6d | 1998-03-14 23:02:40 +0100 | [diff] [blame] | 79 | if (!filename) { |
| 80 | if (verbose) { |
| 81 | fprintf(stderr, "Cannot trace pid %u: %s\n", pid, strerror(errno)); |
| 82 | } |
| 83 | return; |
| 84 | } |
Juan Cespedes | 35d7063 | 1998-03-15 14:05:40 +0100 | [diff] [blame] | 85 | #endif |
Juan Cespedes | 273ea6d | 1998-03-14 23:02:40 +0100 | [diff] [blame] | 86 | |
| 87 | proc = open_program(filename); |
| 88 | proc->pid = pid; |
| 89 | } |