blob: c97753526d28d5bbab727f442be49ae457318792 [file] [log] [blame]
Juan Cespedes273ea6d1998-03-14 23:02:40 +01001#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) {
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 filename = pid2name(pid);
43
44 if (!filename) {
45 if (verbose) {
46 fprintf(stderr, "Cannot trace pid %u: %s\n", pid, strerror(errno));
47 }
48 return;
49 }
50
51 if (trace_pid(pid)<0) {
52 if (verbose) {
53 fprintf(stderr, "Cannot attach to pid %u: %s\n", pid, strerror(errno));
54 }
55 return;
56 }
57
58 proc = open_program(filename);
59 proc->pid = pid;
60}