+#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
+#include <string.h>
/* Advice functions should be externally visible. */
#define ADVICE_FUNC __attribute__((visibility("default")))
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)
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;
+ }
}