blob: 67b88f1b31c4f26dfbf698c652f7b7056fdfe2a1 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
#if HAVE_CONFIG_H
#include "config.h"
#endif
#include <sys/types.h>
#include <string.h>
#include <stdio.h>
#include <errno.h>
#include <stdlib.h>
#include "ltrace.h"
#include "options.h"
#include "elf.h"
struct process *
open_program(char * filename) {
struct process * proc;
proc = malloc(sizeof(struct process));
if (!proc) {
perror("malloc");
exit(1);
}
memset(proc, 0, sizeof(struct process));
proc->filename = filename;
proc->pid = 0;
proc->breakpoints = NULL;
proc->breakpoints_enabled = -1;
proc->callstack_depth = 0;
proc->breakpoint_being_enabled = NULL;
breakpoints_init(proc);
proc->next = NULL;
proc->next = list_of_processes;
list_of_processes = proc;
return proc;
}
void
open_pid(pid_t pid, int verbose) {
struct process * proc;
char * filename;
if (trace_pid(pid)<0) {
fprintf(stderr, "Cannot attach to pid %u: %s\n", pid, strerror(errno));
return;
}
filename = pid2name(pid);
#if 0
if (!filename) {
if (verbose) {
fprintf(stderr, "Cannot trace pid %u: %s\n", pid, strerror(errno));
}
return;
}
#endif
proc = open_program(filename);
proc->pid = pid;
}
|