Adds a tracecut runtime library.
authorJustin Seyster <jseyster@cs.sunysb.edu>
Fri, 11 Feb 2011 01:10:12 +0000 (20:10 -0500)
committerJustin Seyster <jseyster@cs.sunysb.edu>
Fri, 11 Feb 2011 01:10:12 +0000 (20:10 -0500)
src/Makefile.am
src/tracecut-advice.c [new file with mode: 0644]

index 377553ed616fe00c0b078c4658b39a900f45032f..feb9275774558cf8a4f6eba0278fad40c5334ca0 100644 (file)
@@ -1,7 +1,10 @@
-lib_LTLIBRARIES = libinteraspect.la
+lib_LTLIBRARIES = libinteraspect.la libtracecut.la
 libinteraspect_la_SOURCES = aop-pc-assign.c aop-main.c aop-type.c aop-weave.c \
        aop-pc-entry.c aop-pc-exit.c aop-pc-fun-call.c aop-header.c \
        aop-pointcut.c aop-duplicate.c tracecut.c
 libinteraspect_la_CFLAGS = -Wall -Werror -fvisibility=hidden -prefer-pic
 libinteraspect_la_LDFLAGS = -static -prefer-pic -version-info 1:0:0
 libinteraspect_la_CPPFLAGS = -DHAVE_CONFIG_H -DIN_GCC -I$(gcc_includes)
+
+libtracecut_la_SOURCES = tracecut-advice.c
+libtracecut_la_CFLAGS = -Wall -Werror -fvisibility=hidden
diff --git a/src/tracecut-advice.c b/src/tracecut-advice.c
new file mode 100644 (file)
index 0000000..04688fd
--- /dev/null
@@ -0,0 +1,114 @@
+#include <stdio.h>
+#include <stdlib.h>
+
+/* Advice functions should be externally visible. */
+#define ADVICE_FUNC __attribute__((visibility("default")))
+
+static int num_tracecuts = -1;
+
+struct tracecut {
+  int num_params;
+  int num_symbols;
+
+  const char **symbol_names;
+} *tracecut_array = NULL;
+
+static void
+fatal_tracecut_error(const char *error)
+{
+  /* Setting num_tracecuts to -1 will stop completely disable the
+     tracecut runtime. */
+  num_tracecuts = -1;
+
+  fprintf (stderr, "Fatal tracecut error: %s\n", error);
+}
+
+static struct tracecut *
+get_tracecut (int tc_index)
+{
+  if (num_tracecuts < 0)
+    {
+      /* The tracecut library hasn't been initialized yet, so tracecut
+        functions should silently do nothing. */
+      return NULL;
+    }
+  else if (tc_index >= 0 && tc_index < num_tracecuts)
+    {
+      /* The normal case. */
+      return &tracecut_array[tc_index];
+    }
+  else
+    {
+      /* Some error occured in initialization.  Abort. */
+      fatal_tracecut_error ("Attempt to initialize bad tracecut");
+      return NULL;
+    }
+}
+
+ADVICE_FUNC void
+_tc_init (int _num_tracecuts)
+{
+  num_tracecuts = _num_tracecuts;
+  tracecut_array = calloc (num_tracecuts, sizeof (struct tracecut));
+  if (tracecut_array == NULL)
+    fatal_tracecut_error ("Out of memory");
+}
+
+ADVICE_FUNC void
+_tc_new_tracecut (int tc_index, int num_params, int num_symbols)
+{
+  struct tracecut *tc;
+
+  tc = get_tracecut (tc_index);
+  if (tc == NULL)
+    return;
+
+  tc->num_params = num_params;
+  tc->num_symbols = num_symbols;
+
+  if (tc->num_symbols > 0)
+    {
+      tc->symbol_names = calloc (num_symbols, sizeof (const char *));
+      if (tc->symbol_names == NULL)
+       fatal_tracecut_error ("Out of memory");
+    }
+}
+
+ADVICE_FUNC void
+_tc_name_symbol (int tc_index, int symbol_index, const char *symbol_name)
+{
+  struct tracecut *tc;
+
+  tc = get_tracecut (tc_index);
+  if (tc == NULL)
+    return;
+
+  if (symbol_index < 0 || symbol_index >= tc->num_symbols)
+    {
+      fatal_tracecut_error ("Bad symbol index at initialization.");
+      return;
+    }
+
+  tc->symbol_names[symbol_index] = symbol_name;
+}
+
+ADVICE_FUNC void
+_tc_compile_tracecut (int tc_index)
+{
+}
+
+ADVICE_FUNC void
+_tc_event_begin (int tc_index)
+{
+}
+
+ADVICE_FUNC void
+_tc_capture_pointer_param (int tc_index, int symbol, int param_index,
+                          void *param_val)
+{
+}
+
+ADVICE_FUNC void
+_tc_event_transition (int tc_index, int symbol)
+{
+}