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