Added duplication example plug-in.
authorJustin Seyster <jseyster@cs.sunysb.edu>
Thu, 28 Oct 2010 19:32:19 +0000 (15:32 -0400)
committerJustin Seyster <jseyster@cs.sunysb.edu>
Thu, 28 Oct 2010 19:32:19 +0000 (15:32 -0400)
src/aop-doxy-main.c
src/aop-weave.c
workspace/.gitignore
workspace/duplicate.c [new file with mode: 0644]

index 84127c6c4a214267ca95fa0d351bae5f92ce822c..b29ea0a7951a4228f60787b0514ff0108fffdd0d 100644 (file)
  * An example of a plug-in that automatically generates a header file
  * with prototypes for advice functions.
  */
+
+/**
+ * \example duplicate.c
+ * A plug-in that duplicates functions so that the program can switch
+ * between two kinds of instrumentation at runtime.
+ */
index ca8fc02a49612c123a57c2162417832cc21f15e9..1fe50bbe42eb9805424135e791a55650fc496c4a 100644 (file)
@@ -494,6 +494,9 @@ insert_stmts_at_entry (VEC(gimple, heap) *stmt_list)
  * aop_duplicate(), even when not specifying any arguments for the
  * advice function.
  *
+ * See the \ref duplicate.c "duplicate.c" sample plug-in for a simple
+ * example of function duplication.
+ *
  * \param jp The function entry join point for the current join point.
  * The distributor advice will be inserted here.  Function entry join
  * points are obtained by joining on an aop_match_function_entry()
index 3260e0164834ba5c5a62bca5e74ac64459121f6b..6ce0216acc541d05786fc0bded6177449eeca48a 100644 (file)
@@ -5,3 +5,4 @@
 # distributed with InterAspect.
 !hello.c
 !advice_header.c
+!duplicate.c
diff --git a/workspace/duplicate.c b/workspace/duplicate.c
new file mode 100644 (file)
index 0000000..fe805b7
--- /dev/null
@@ -0,0 +1,57 @@
+/* This sample plug-in shows how to duplicate a function.  Compile it
+   with:
+
+   make libduplicate.so
+
+   The compiled plug-in will duplicate every function that takes a
+   signed integer parameter, instrumenting the entry with a
+   distributor that has the prototype:
+
+   int _distrib(const char *function_name, int64_t int_param);
+ */
+
+#include <aop.h>
+
+AOP_I_AM_GPL_COMPATIBLE();
+
+static void plugin_join_on_entry(struct aop_joinpoint *jp, void *data)
+{
+  const char *name;
+  struct aop_dynval *param;
+  int *duplicated = (int *)data;
+
+  name = aop_get_function_name();
+  param = aop_capture_in_param(jp, 0);
+  aop_duplicate(jp, "_distrib", AOP_STR_CST(name), AOP_DYNVAL(param),
+               AOP_TERM_ARG);
+  *duplicated = 1;
+}
+
+static void plugin_join_on_exit(struct aop_joinpoint *jp, void *data)
+{
+  aop_insert_advice(jp, "_exit_advice", AOP_INSERT_BEFORE,
+                   AOP_STR_CST((const char *)data), AOP_TERM_ARG);
+}
+
+static unsigned int plugin_duplicate()
+{
+  struct aop_pointcut *pc;
+  int duplicated = 0;
+
+  pc = aop_match_function_entry();
+  aop_filter_by_in_param(pc, 0, aop_t_all_signed());
+  aop_join_on(pc, plugin_join_on_entry, &duplicated);
+
+  if (duplicated) {
+    pc = aop_match_function_exit();
+    aop_join_on_copy(pc, 0, plugin_join_on_exit, "Left");
+    aop_join_on_copy(pc, 1, plugin_join_on_exit, "Right");
+  }
+
+  return 0;
+}
+
+AOP_MAIN_PROTO aop_main()
+{
+  aop_register_pass("duplicate", plugin_duplicate);
+}