From: Justin Seyster Date: Wed, 7 Jul 2010 23:55:34 +0000 (-0400) Subject: Added a Hello World example plug-in. X-Git-Tag: release-v1.0~74^2~4 X-Git-Url: https://git.fsl.cs.stonybrook.edu/?a=commitdiff_plain;h=c0bddfd7755fdbf40703978e0910ae0f5520d575;p=interaspect.git Added a Hello World example plug-in. --- diff --git a/workspace/.gitignore b/workspace/.gitignore index 385fbbf..24bec0f 100644 --- a/workspace/.gitignore +++ b/workspace/.gitignore @@ -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 index 0000000..bd765ee --- /dev/null +++ b/workspace/hello.c @@ -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 +#include /* 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); +}