proc.c revision 504a385858a49352bcfceca444ba4f1a7bfd20cd
1#if HAVE_CONFIG_H 2#include "config.h" 3#endif 4 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 15struct process * 16open_program(char * filename) { 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 = NULL; 26 proc->breakpoints_enabled = -1; 27 proc->callstack_depth = 0; 28 proc->breakpoint_being_enabled = NULL; 29 breakpoints_init(proc); 30 proc->next = NULL; 31 32 proc->next = list_of_processes; 33 list_of_processes = proc; 34 return proc; 35} 36 37void 38open_pid(pid_t pid, int verbose) { 39 struct process * proc; 40 char * filename; 41 42 if (trace_pid(pid)<0) { 43 fprintf(stderr, "Cannot attach to pid %u: %s\n", pid, strerror(errno)); 44 return; 45 } 46 47 filename = pid2name(pid); 48 49#if 0 50 if (!filename) { 51 if (verbose) { 52 fprintf(stderr, "Cannot trace pid %u: %s\n", pid, strerror(errno)); 53 } 54 return; 55 } 56#endif 57 58 proc = open_program(filename); 59 proc->pid = pid; 60} 61