From 0ed16fd1524890c509f4777e14692b80d39d88db Mon Sep 17 00:00:00 2001 From: Justin Seyster Date: Fri, 8 Apr 2011 16:31:42 -0400 Subject: [PATCH] Adds a tracecut example to the workspace directory. --- src/aop-doxy-main.c | 6 ++++++ workspace/.gitignore | 1 + workspace/fclose_tracecut.c | 29 +++++++++++++++++++++++++++++ 3 files changed, 36 insertions(+) create mode 100644 workspace/fclose_tracecut.c 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); +} -- 2.34.1