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