Adds a tracecut example to the workspace directory.
authorJustin Seyster <jseyster@cs.sunysb.edu>
Fri, 8 Apr 2011 20:31:42 +0000 (16:31 -0400)
committerJustin Seyster <jseyster@cs.sunysb.edu>
Fri, 8 Apr 2011 21:29:59 +0000 (17:29 -0400)
src/aop-doxy-main.c
workspace/.gitignore
workspace/fclose_tracecut.c [new file with mode: 0644]

index 7e5cd602109533e9c379860a680b44309816308f..3a99b5c9cd74e5494d1a6e2c602ab2cf187e3954 100644 (file)
  * 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.
+ */
index 6ce0216acc541d05786fc0bded6177449eeca48a..1047021654e7a31e93beaa44d022383f0f2f2d20 100644 (file)
@@ -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 (file)
index 0000000..79cea9e
--- /dev/null
@@ -0,0 +1,29 @@
+#include <aop.h>
+#include <tracecut.h>
+
+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);
+}