From: Justin Seyster Date: Wed, 8 Sep 2010 02:49:49 +0000 (-0400) Subject: Assign join points also do not instrument advice calls. X-Git-Tag: release-v1.0~44 X-Git-Url: https://git.fsl.cs.stonybrook.edu/?a=commitdiff_plain;h=731f01c854e375d283e4d4afff0784a4eb8aec80;p=interaspect.git Assign join points also do not instrument advice calls. The only time an advice call would appear in an assignment is when it's a distributor function. A modification to duplicate_function_body() was also necessary so that the inserted distributor call is in the advice table. --- diff --git a/src/aop-duplicate.c b/src/aop-duplicate.c index 3cc03e5..57bab19 100644 --- a/src/aop-duplicate.c +++ b/src/aop-duplicate.c @@ -297,17 +297,15 @@ duplicate_function_body (const char *tmpvar_name, gimple call) else { /* insert: tmpvar = distributor_fn(...) */ - /* TODO: No need to copy. */ - gimple distributor_fn = gimple_copy(call); - aop_assert (gimple_code (distributor_fn) == GIMPLE_CALL); + aop_assert (gimple_code (call) == GIMPLE_CALL); /* TODO: Do we need this? */ if (gimple_in_ssa_p (cfun)) { - tmpvar = make_ssa_name (tmpvar, distributor_fn); + tmpvar = make_ssa_name (tmpvar, call); } - gimple_call_set_lhs (distributor_fn, tmpvar); - gsi_insert_before (&gsi, distributor_fn, GSI_SAME_STMT); + gimple_call_set_lhs (call, tmpvar); + gsi_insert_before (&gsi, call, GSI_SAME_STMT); } /* insert: if (tmpvar) goto else goto */ diff --git a/src/aop-pc-assign.c b/src/aop-pc-assign.c index 99673a6..cb5b7e6 100644 --- a/src/aop-pc-assign.c +++ b/src/aop-pc-assign.c @@ -38,6 +38,7 @@ #include "aop-dynval.h" #include "aop-pointcut.h" #include "aop-type.h" +#include "aop-weave.h" /** * \defgroup assign_pc Assignment Pointcut Functions @@ -290,6 +291,11 @@ stmt_matches_pointcut (struct aop_pointcut *pc, gimple stmt) tree lhs = gimple_get_lhs(stmt); tree type = TREE_TYPE (gimple_get_lhs (stmt)); + /* We never want to match a call that is actually one we + inserted! */ + if (is_stmt_advice (stmt)) + return false; + /* Temp variables with matching type only match the pointcut if include_temp_vars is true. */ return does_type_match (type, pc->pc_assign.type) diff --git a/test/plugin-reinst-dup.c b/test/plugin-reinst-dup.c new file mode 100644 index 0000000..63ac3b0 --- /dev/null +++ b/test/plugin-reinst-dup.c @@ -0,0 +1,50 @@ +#include +#include +#include + +AOP_I_AM_GPL_COMPATIBLE(); + +int duplicated = 0; + +static void plugin_join_on_entry(struct aop_joinpoint *jp, void *data) +{ + const char *name; + + name = aop_capture_function_name(jp); + if (name != NULL && strcmp(name, "foo") == 0) { + aop_duplicate(jp, "_distrib", AOP_TERM_ARG); + duplicated = 1; + } + else { + duplicated = 0; + } +} + +static void plugin_join_on_assign(struct aop_joinpoint *jp, void *data) +{ + aop_insert_advice(jp, "_assign_advice", AOP_INSERT_BEFORE, AOP_TERM_ARG); +} + +static unsigned int plugin_reinst_dup() +{ + struct aop_pointcut *pc; + + pc = aop_match_function_entry(); + aop_join_on(pc, plugin_join_on_entry, NULL); + + if (duplicated) { + /* Duplication creates an assignment that we might accidentally + match during a join. (This test is primarily to make sure that + doesn't happen! */ + pc = aop_match_assignment_by_type(aop_t_all_signed()); + aop_filter_include_temps (pc); + aop_join_on(pc, plugin_join_on_assign, NULL); + } + + return 0; +} + +AOP_MAIN_PROTO aop_main() +{ + aop_register_pass("reinst-dup", plugin_reinst_dup); +} diff --git a/test/reinst-dup-hooks.c b/test/reinst-dup-hooks.c new file mode 100644 index 0000000..1d422d6 --- /dev/null +++ b/test/reinst-dup-hooks.c @@ -0,0 +1,11 @@ +#include + +void _distrib() +{ + printf("In distributor.\n"); +} + +void _assign_advice() +{ + printf("In assign advice.\n"); +} diff --git a/test/reinst-dup-target.c b/test/reinst-dup-target.c new file mode 100644 index 0000000..4b413f0 --- /dev/null +++ b/test/reinst-dup-target.c @@ -0,0 +1,13 @@ +#include + +void foo(const char *str, int n) +{ + printf("%d: %s\n", n, str); +} + +int run_test() +{ + foo("A Space Odyssey", 2001); + + return 0; +} diff --git a/test/reinst.xml b/test/reinst.xml index 5429487..3a6f0af 100644 --- a/test/reinst.xml +++ b/test/reinst.xml @@ -9,6 +9,7 @@ + @@ -25,4 +26,11 @@ THX 1138 + + + + In distributor. + 2001: A Space Odyssey + +