Move event-que declarations to sysdeps, new backend interface process_removed
- the reason being that the que-handling was declared on global level, but
was only implemented in one back end. If this is deemed generally useful,
it should all be moved to front end, but as things are it's all the same,
so I'm preferring the less invasive change
diff --git a/ChangeLog b/ChangeLog
index 5fdb95f..a4433b2 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2012-01-07 Petr Machata <pmachata@redhat.com>
+
+ * common.h (enum ecb_status, each_qd_event, enque_event): Move...
+ * sysdeps/linux-gnu/events.h: ... here (new file)
+ * common.h (process_removed): New callback
+ * sysdeps/linux-gnu/events.c: Implement it here
+ * proc.c (remove_process): Call it here
+ (delete_events_for, event_for_proc): Move...
+ * sysdeps/linux-gnu/events.c: ... here
+
2012-01-06 Petr Machata <pmachata@redhat.com>
* printf.c, printf.h: New file with support for functions with
diff --git a/common.h b/common.h
index 2741662..0e7693a 100644
--- a/common.h
+++ b/common.h
@@ -86,17 +86,7 @@
};
/* Events */
-enum ecb_status {
- ecb_cont, /* The iteration should continue. */
- ecb_yield, /* The iteration should stop, yielding this
- * event. */
- ecb_deque, /* Like ecb_stop, but the event should be removed
- * from the queue. */
-};
extern Event * next_event(void);
-extern Event * each_qd_event(enum ecb_status (* cb)(Event * event, void * data),
- void * data);
-extern void enque_event(Event * event);
extern void handle_event(Event * event);
extern pid_t execute_program(const char * command, char ** argv);
@@ -203,4 +193,7 @@
int format_argument(FILE *stream, struct value *value,
struct value_dict *arguments);
+/* Called when process PROC was removed. */
+void process_removed(struct Process *proc);
+
#endif
diff --git a/forward.h b/forward.h
index 1a404f5..286b239 100644
--- a/forward.h
+++ b/forward.h
@@ -1,10 +1,14 @@
/* Important types defined in other header files are declared
here. */
-struct expr_node;
-struct param;
-struct param_enum;
+struct breakpoint;
+struct Event;
struct Process;
struct arg_type_info;
+struct expr_node;
+struct library_symbol;
+struct ltelf;
+struct param;
+struct param_enum;
struct value;
struct value_dict;
struct library_symbol;
diff --git a/proc.c b/proc.c
index cd8f6cd..9a82782 100644
--- a/proc.c
+++ b/proc.c
@@ -570,23 +570,6 @@
return CBS_CONT;
}
-static enum ecb_status
-event_for_proc(Event * event, void * data)
-{
- if (event->proc == data)
- return ecb_deque;
- else
- return ecb_cont;
-}
-
-static void
-delete_events_for(Process * proc)
-{
- Event * event;
- while ((event = each_qd_event(&event_for_proc, proc)) != NULL)
- free(event);
-}
-
void
remove_process(Process *proc)
{
@@ -596,7 +579,7 @@
each_task(proc, NULL, &clear_leader, NULL);
unlist_process(proc);
- delete_events_for(proc);
+ process_removed(proc);
process_destroy(proc);
free(proc);
}
diff --git a/sysdeps/linux-gnu/Makefile.am b/sysdeps/linux-gnu/Makefile.am
index e6fd7ef..e385ea7 100644
--- a/sysdeps/linux-gnu/Makefile.am
+++ b/sysdeps/linux-gnu/Makefile.am
@@ -29,7 +29,8 @@
arch_syscallent.h \
signalent1.h \
syscallent1.h \
- trace.h
+ trace.h \
+ events.h
EXTRA_DIST = \
arch_mksyscallent \
diff --git a/sysdeps/linux-gnu/events.c b/sysdeps/linux-gnu/events.c
index 91d873e..21b327b 100644
--- a/sysdeps/linux-gnu/events.c
+++ b/sysdeps/linux-gnu/events.c
@@ -14,6 +14,7 @@
#include "common.h"
#include "breakpoint.h"
#include "proc.h"
+#include "events.h"
static Event event;
@@ -311,3 +312,20 @@
return &event;
}
+
+static enum ecb_status
+event_for_proc(struct Event *event, void *data)
+{
+ if (event->proc == data)
+ return ecb_deque;
+ else
+ return ecb_cont;
+}
+
+void
+delete_events_for(struct Process *proc)
+{
+ struct Event *event;
+ while ((event = each_qd_event(&event_for_proc, proc)) != NULL)
+ free(event);
+}
diff --git a/sysdeps/linux-gnu/events.h b/sysdeps/linux-gnu/events.h
new file mode 100644
index 0000000..e91caa2
--- /dev/null
+++ b/sysdeps/linux-gnu/events.h
@@ -0,0 +1,21 @@
+#ifndef SYSDEPS_LINUX_GNU_EVENTS_H
+#define SYSDEPS_LINUX_GNU_EVENTS_H
+
+#include "forward.h"
+
+/* Declarations for event que functions. */
+
+enum ecb_status {
+ ecb_cont, /* The iteration should continue. */
+ ecb_yield, /* The iteration should stop, yielding this
+ * event. */
+ ecb_deque, /* Like ecb_stop, but the event should be removed
+ * from the queue. */
+};
+
+struct Event *each_qd_event(enum ecb_status (*cb)(struct Event *event,
+ void *data), void *data);
+void delete_events_for(struct Process * proc);
+void enque_event(struct Event *event);
+
+#endif /* SYSDEPS_LINUX_GNU_EVENTS_H */
diff --git a/sysdeps/linux-gnu/proc.c b/sysdeps/linux-gnu/proc.c
index c5282e4..97969dc 100644
--- a/sysdeps/linux-gnu/proc.c
+++ b/sysdeps/linux-gnu/proc.c
@@ -15,10 +15,12 @@
#include <string.h>
#include <unistd.h>
+#include "config.h"
#include "common.h"
#include "breakpoint.h"
#include "proc.h"
#include "library.h"
+#include "events.h"
/* /proc/pid doesn't exist just after the fork, and sometimes `ltrace'
* couldn't open it to find the executable. So it may be necessary to
@@ -588,3 +590,9 @@
ret = syscall (__NR_tkill, pid, sig);
return ret;
}
+
+void
+process_removed(struct Process *proc)
+{
+ delete_events_for(proc);
+}
diff --git a/sysdeps/linux-gnu/trace.c b/sysdeps/linux-gnu/trace.c
index f25fabc..8407eea 100644
--- a/sysdeps/linux-gnu/trace.c
+++ b/sysdeps/linux-gnu/trace.c
@@ -20,6 +20,7 @@
#include "proc.h"
#include "linux-gnu/trace.h"
#include "type.h"
+#include "events.h"
/* If the system headers did not provide the constants, hard-code the normal
values. */