summaryrefslogtreecommitdiff
path: root/proc.c
diff options
context:
space:
mode:
authorAnas Nashif <anas.nashif@intel.com>2012-11-13 07:28:12 -0800
committerAnas Nashif <anas.nashif@intel.com>2012-11-13 07:28:12 -0800
commit59749d048d9e452f049f9151735b5256756919c3 (patch)
tree9b0935c93a3b028fd1dd35a2c632510743e7826f /proc.c
downloadltrace-59749d048d9e452f049f9151735b5256756919c3.tar.gz
ltrace-59749d048d9e452f049f9151735b5256756919c3.tar.bz2
ltrace-59749d048d9e452f049f9151735b5256756919c3.zip
Imported Upstream version 0.5.3upstream/0.5.3
Diffstat (limited to 'proc.c')
-rw-r--r--proc.c65
1 files changed, 65 insertions, 0 deletions
diff --git a/proc.c b/proc.c
new file mode 100644
index 0000000..bfc6e41
--- /dev/null
+++ b/proc.c
@@ -0,0 +1,65 @@
+#include <sys/types.h>
+#include <string.h>
+#include <stdio.h>
+#include <errno.h>
+#include <stdlib.h>
+
+#include "common.h"
+
+Process *
+open_program(char *filename, pid_t pid) {
+ Process *proc;
+ proc = calloc(sizeof(Process), 1);
+ if (!proc) {
+ perror("malloc");
+ exit(1);
+ }
+ proc->filename = strdup(filename);
+ proc->breakpoints_enabled = -1;
+ if (pid) {
+ proc->pid = pid;
+ }
+ breakpoints_init(proc);
+
+ proc->next = list_of_processes;
+ list_of_processes = proc;
+ return proc;
+}
+
+void
+open_pid(pid_t pid) {
+ 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 (!filename) {
+ fprintf(stderr, "Cannot trace pid %u: %s\n", pid,
+ strerror(errno));
+ return;
+ }
+
+ proc = open_program(filename, pid);
+ continue_process(pid);
+ proc->breakpoints_enabled = 1;
+}
+
+Process *
+pid2proc(pid_t pid) {
+ Process *tmp;
+
+ tmp = list_of_processes;
+ while (tmp) {
+ if (pid == tmp->pid) {
+ return tmp;
+ }
+ tmp = tmp->next;
+ }
+ return NULL;
+}