proc.c revision 35d70634aacdf85a3cdf85792ce68989e27bc9c2
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 11struct 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; 26 if (opt_L && filename) { 27 proc->list_of_symbols = read_elf(filename); 28 } else { 29 proc->list_of_symbols = NULL; 30 } 31 32 proc->next = list_of_processes; 33 list_of_processes = proc; 34 return proc; 35} 36 37void open_pid(pid_t pid, int verbose) 38{ 39 struct process * proc; 40 char * filename; 41 42 if (trace_pid(pid)<0) { 43#if 0 44 if (verbose) { 45#endif 46 fprintf(stderr, "Cannot attach to pid %u: %s\n", pid, strerror(errno)); 47#if 0 48 } 49#endif 50 return; 51 } 52 53 filename = pid2name(pid); 54 55#if 0 56 if (!filename) { 57 if (verbose) { 58 fprintf(stderr, "Cannot trace pid %u: %s\n", pid, strerror(errno)); 59 } 60 return; 61 } 62#endif 63 64 proc = open_program(filename); 65 proc->pid = pid; 66} 67