Collects event params.
authorJustin Seyster <jseyster@cs.sunysb.edu>
Fri, 11 Feb 2011 21:44:32 +0000 (16:44 -0500)
committerJustin Seyster <jseyster@cs.sunysb.edu>
Fri, 11 Feb 2011 21:44:32 +0000 (16:44 -0500)
src/tracecut-advice.c

index 04688fd75b59058ab1013b76f3b2e03bd4951641..c93304380f61f44f645a0c30cd3524e77b6b92df 100644 (file)
@@ -1,5 +1,7 @@
+#include <stdint.h>
 #include <stdio.h>
 #include <stdlib.h>
+#include <string.h>
 
 /* Advice functions should be externally visible. */
 #define ADVICE_FUNC __attribute__((visibility("default")))
@@ -11,7 +13,30 @@ struct tracecut {
   int num_symbols;
 
   const char **symbol_names;
-} *tracecut_array = NULL;
+};
+
+static struct tracecut *tracecut_array = NULL;
+
+struct param_val {
+  enum {
+    PV_VACANT = 0,
+    PV_POINTER,
+  } kind;
+
+  uintptr_t value;
+};
+
+struct event {
+  int symbol_index;
+
+  int tc_index;
+  struct tracecut *tracecut;
+
+  int num_params;
+  struct param_val param_vals[];
+};
+
+static struct event *current_event = NULL;
 
 static void
 fatal_tracecut_error(const char *error)
@@ -95,20 +120,74 @@ _tc_name_symbol (int tc_index, int symbol_index, const char *symbol_name)
 ADVICE_FUNC void
 _tc_compile_tracecut (int tc_index)
 {
+  struct tracecut *tc;
+
+  tc = get_tracecut (tc_index);
+  if (tc == NULL)
+    return;
 }
 
 ADVICE_FUNC void
 _tc_event_begin (int tc_index)
 {
+  struct tracecut *tc;
+  size_t event_size;
+
+  tc = get_tracecut (tc_index);
+  if (tc == NULL)
+    return;
+
+  /* We're going to start seeing calls to _tc_capture_*_param()
+     functions.  We need to create a new event object, so that we
+     store those params with the event. */
+  event_size = sizeof (struct event)
+    + tc->num_params * sizeof (struct param_val);
+  current_event = malloc (event_size);
+  if (current_event != NULL)
+    {
+      memset (current_event, 0, event_size);
+      current_event->tc_index = tc_index;
+      current_event->tracecut = tc;
+      current_event->num_params = tc->num_params;
+    }
+  else
+    {
+      fatal_tracecut_error ("Out of memory");
+    }
 }
 
 ADVICE_FUNC void
-_tc_capture_pointer_param (int tc_index, int symbol, int param_index,
+_tc_capture_pointer_param (int tc_index, int symbol_index, int param_index,
                           void *param_val)
 {
+  if (current_event == NULL)
+    {
+      return;
+    }
+  else if (current_event->tc_index != tc_index)
+    {
+      fatal_tracecut_error ("Misplaced param value.");
+      return;
+    }
+  else if (param_index < 0 || param_index >= current_event->num_params)
+    {
+      fatal_tracecut_error ("Out-of-bounds param value.");
+    }
+
+  current_event->param_vals[param_index].kind = PV_POINTER;
+  current_event->param_vals[param_index].value = (uintptr_t)param_val;
 }
 
 ADVICE_FUNC void
-_tc_event_transition (int tc_index, int symbol)
+_tc_event_transition (int tc_index, int symbol_index)
 {
+  if (current_event == NULL)
+    {
+      return;
+    }
+  else if (current_event->tc_index != tc_index)
+    {
+      fatal_tracecut_error ("Misplaced event transition.");
+      return;
+    }
 }