From 021003c707fdb585f4a9aa2e37bce142f0083e33 Mon Sep 17 00:00:00 2001 From: Justin Seyster Date: Fri, 11 Feb 2011 16:44:32 -0500 Subject: [PATCH] Collects event params. --- src/tracecut-advice.c | 85 +++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 82 insertions(+), 3 deletions(-) diff --git a/src/tracecut-advice.c b/src/tracecut-advice.c index 04688fd..c933043 100644 --- a/src/tracecut-advice.c +++ b/src/tracecut-advice.c @@ -1,5 +1,7 @@ +#include #include #include +#include /* 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; + } } -- 2.34.1