Added a Hello World example plug-in.
authorJustin Seyster <jseyster@cs.sunysb.edu>
Wed, 7 Jul 2010 23:55:34 +0000 (19:55 -0400)
committerJustin Seyster <jseyster@cs.sunysb.edu>
Wed, 7 Jul 2010 23:55:34 +0000 (19:55 -0400)
workspace/.gitignore
workspace/hello.c [new file with mode: 0644]

index 385fbbfabb64bb7ddead714dd41e653edbad2853..24bec0f6406e546a10d121412c085fd7c36edd5e 100644 (file)
@@ -1,3 +1,10 @@
+*.c
+*.so
+
 # The Makefile in this directory is hand-written, not generated by
 # Automake
 !Makefile
+
+# There is one C file included as an example that should be
+# distributed with InterAspect.
+!hello.c
diff --git a/workspace/hello.c b/workspace/hello.c
new file mode 100644 (file)
index 0000000..bd765ee
--- /dev/null
@@ -0,0 +1,55 @@
+/* This sample plug-in is designed as a "Hello World" example to get
+   you started with InterAspect!  Compile it with:
+
+   make libhello.so
+
+   The compiled plug-in will instrument every function's entry point
+   with a call to:
+
+   void __hello_advice(const char *function_name);
+*/
+
+#include <aop.h>
+#include <string.h>  /* For strcmp. */
+
+/* Every InterAspect plug-in must include this macro.  If you intend
+   to distribute your plug-in, make sure to read the implications of
+   this macro in the API documentation. */
+AOP_I_AM_GPL_COMPATIBLE();
+
+#define ADVICE_NAME "__hello_advice"
+
+/* This is the function entry callback.  It gets called once for each
+   function entry join point. */
+static void join_on_entry(struct aop_joinpoint *jp, void *data)
+{
+  const char *name;
+
+  name = aop_capture_function_name(jp);
+
+  /* Don't instrument the advice function itself! */
+  if (strcmp(name, ADVICE_NAME) == 0)
+    return;
+
+  aop_insert_advice(jp, ADVICE_NAME, AOP_INSERT_AFTER, AOP_STR_CST(name),
+                   AOP_TERM_ARG);
+}
+
+/* This is the plug-in pass.  It runs once per instrumented
+   fuction. */
+static unsigned int hello_pass()
+{
+  struct aop_pointcut *pc;
+
+  pc = aop_match_function_entry();
+  aop_join_on(pc, join_on_entry, NULL);
+
+  return 0;
+}
+
+/* This is what your main function should look like.  Most plug-ins
+   only need to define on pass in their main function. */
+AOP_MAIN_PROTO aop_main()
+{
+  aop_register_pass("hello-world", hello_pass);
+}