From: Justin Seyster Date: Fri, 8 Apr 2011 20:31:42 +0000 (-0400) Subject: Adds a tracecut example to the workspace directory. X-Git-Tag: release-v1.1~9^2~2 X-Git-Url: https://git.fsl.cs.stonybrook.edu/?a=commitdiff_plain;h=0ed16fd1524890c509f4777e14692b80d39d88db;p=interaspect.git Adds a tracecut example to the workspace directory. --- diff --git a/src/aop-doxy-main.c b/src/aop-doxy-main.c index 7e5cd60..3a99b5c 100644 --- a/src/aop-doxy-main.c +++ b/src/aop-doxy-main.c @@ -281,3 +281,9 @@ * A plug-in that duplicates functions so that the program can switch * between two kinds of instrumentation at runtime. */ + +/** + * \example fclose_tracecut.c + * A tracecut that triggers on an attempt to read a file after closing + * it. + */ diff --git a/workspace/.gitignore b/workspace/.gitignore index 6ce0216..1047021 100644 --- a/workspace/.gitignore +++ b/workspace/.gitignore @@ -6,3 +6,4 @@ !hello.c !advice_header.c !duplicate.c +!fclose_tracecut.c diff --git a/workspace/fclose_tracecut.c b/workspace/fclose_tracecut.c new file mode 100644 index 0000000..79cea9e --- /dev/null +++ b/workspace/fclose_tracecut.c @@ -0,0 +1,29 @@ +#include +#include + +AOP_I_AM_GPL_COMPATIBLE(); + +static struct tc_tracecut *tc; + +AOP_MAIN_PROTO aop_main() +{ + tc = tc_create_tracecut(); + + tc_add_param(tc, "file", aop_t_all_pointer()); + tc_declare_call_symbol(tc, "open", "(file)fopen()", AOP_INSERT_AFTER); + tc_declare_call_symbol(tc, "read", "fread(?, ?, ?, file)", AOP_INSERT_AFTER); + tc_declare_call_symbol(tc, "read_char", "fgetc(file)", AOP_INSERT_BEFORE); + tc_declare_call_symbol(tc, "close", "fclose(file)", AOP_INSERT_BEFORE); + + tc_add_rule(tc, "open (read | read_char)* close (read | read_char)"); + + aop_assert (tc_error_code(tc) == TC_SUCCESS); + + tc_set_main_function("main"); + tc_register_tracecut_pass(); +} + +void aop_finish() +{ + tc_free_tracecut(tc); +}