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