From ffaa514e6128722ca7dc33582b46bb7973260aa1 Mon Sep 17 00:00:00 2001 From: Justin Seyster Date: Thu, 28 Oct 2010 15:32:19 -0400 Subject: [PATCH] Added duplication example plug-in. --- src/aop-doxy-main.c | 6 +++++ src/aop-weave.c | 3 +++ workspace/.gitignore | 1 + workspace/duplicate.c | 57 +++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 67 insertions(+) create mode 100644 workspace/duplicate.c diff --git a/src/aop-doxy-main.c b/src/aop-doxy-main.c index 84127c6..b29ea0a 100644 --- a/src/aop-doxy-main.c +++ b/src/aop-doxy-main.c @@ -263,3 +263,9 @@ * 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. + */ diff --git a/src/aop-weave.c b/src/aop-weave.c index ca8fc02..1fe50bb 100644 --- a/src/aop-weave.c +++ b/src/aop-weave.c @@ -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() diff --git a/workspace/.gitignore b/workspace/.gitignore index 3260e01..6ce0216 100644 --- a/workspace/.gitignore +++ b/workspace/.gitignore @@ -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 index 0000000..fe805b7 --- /dev/null +++ b/workspace/duplicate.c @@ -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_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); +} -- 2.34.1