From 6418800de0a7d64b67cfbd88bea09d7d9e6dc438 Mon Sep 17 00:00:00 2001 From: compudj Date: Wed, 10 Oct 2007 18:21:41 +0000 Subject: [PATCH] fix trace_find_hook git-svn-id: http://ltt.polymtl.ca/svn@2623 04897980-b3bd-0310-b5e0-8ef037075253 --- ltt/branches/poly/lttv/lttv/state.c | 52 ++++++++++----------- ltt/branches/poly/lttv/lttv/tracecontext.c | 53 +++++++++------------- ltt/branches/poly/lttv/lttv/tracecontext.h | 9 ++-- 3 files changed, 51 insertions(+), 63 deletions(-) diff --git a/ltt/branches/poly/lttv/lttv/state.c b/ltt/branches/poly/lttv/lttv/state.c index 792f9cef..4c1d67bf 100644 --- a/ltt/branches/poly/lttv/lttv/state.c +++ b/ltt/branches/poly/lttv/lttv/state.c @@ -1616,31 +1616,31 @@ create_name_tables(LttvTraceState *tcs) { int i; - LttvTraceHook th; - GString *fe_name = g_string_new(""); LttvNameTables *name_tables = g_new(LttvNameTables, 1); LttvAttributeValue v; + GArray *hooks; + lttv_attribute_find(tcs->parent.t_a, LTTV_STATE_NAME_TABLES, LTTV_POINTER, &v); g_assert(*(v.v_pointer) == NULL); *(v.v_pointer) = name_tables; + hooks = g_array_sized_new(FALSE, FALSE, sizeof(LttvTraceHook), 1); + if(!lttv_trace_find_hook(tcs->parent.t, LTT_EVENT_SYSCALL_ENTRY, FIELD_ARRAY(LTT_FIELD_SYSCALL_ID), - NULL, NULL)) { + NULL, NULL, &hooks)) { // th = lttv_trace_hook_get_first(&th); // // t = ltt_field_type(th->f1); // nb = ltt_type_element_number(t); // - lttv_trace_hook_destroy(&th); -// // name_tables->syscall_names = g_new(GQuark, nb); // name_tables->nb_syscalls = nb; // @@ -1663,19 +1663,18 @@ create_name_tables(LttvTraceState *tcs) name_tables->syscall_names = NULL; name_tables->nb_syscalls = 0; } + lttv_trace_hook_destroy(&hooks); if(!lttv_trace_find_hook(tcs->parent.t, LTT_EVENT_TRAP_ENTRY, - LTT_FIELD_TRAP_ID, 0, 0, - NULL, NULL, &th)) { + FIELD_ARRAY(LTT_FIELD_TRAP_ID), + NULL, NULL, &hooks)) { // th = lttv_trace_hook_get_first(&th); // // t = ltt_field_type(th->f1); // //nb = ltt_type_element_number(t); // - lttv_trace_hook_destroy(&th); - // name_tables->trap_names = g_new(GQuark, nb); // for(i = 0 ; i < nb ; i++) { // name_tables->trap_names[i] = g_quark_from_string( @@ -1692,14 +1691,13 @@ create_name_tables(LttvTraceState *tcs) name_tables->trap_names = NULL; name_tables->nb_traps = 0; } + lttv_trace_hook_destroy(&hooks); if(!lttv_trace_find_hook(tcs->parent.t, LTT_EVENT_IRQ_ENTRY, - LTT_FIELD_IRQ_ID, 0, 0, - NULL, NULL, &th)) { + FIELD_ARRAY(LTT_FIELD_IRQ_ID), + NULL, NULL, &hooks)) { - lttv_trace_hook_destroy(&th); - /* name_tables->irq_names = g_new(GQuark, nb); for(i = 0 ; i < nb ; i++) { @@ -1717,6 +1715,7 @@ create_name_tables(LttvTraceState *tcs) name_tables->nb_irqs = 0; name_tables->irq_names = NULL; } + lttv_trace_hook_destroy(&hooks); /* name_tables->soft_irq_names = g_new(GQuark, nb); for(i = 0 ; i < nb ; i++) { @@ -1730,7 +1729,7 @@ create_name_tables(LttvTraceState *tcs) g_string_printf(fe_name, "softirq %d", i); name_tables->soft_irq_names[i] = g_quark_from_string(fe_name->str); } - + g_array_free(hooks, TRUE); g_string_free(fe_name, TRUE); } @@ -3033,26 +3032,23 @@ void lttv_state_add_event_hooks(LttvTracesetState *self) associated by id hooks. */ hooks = g_array_sized_new(FALSE, FALSE, sizeof(LttvTraceHook), 19); - hooks = g_array_set_size(hooks, 19); // Max possible number of hooks. - hn = 0; + //hooks = g_array_set_size(hooks, 19); // Max possible number of hooks. + //hn = 0; - ret = lttv_trace_find_hook(ts->parent.t, + lttv_trace_find_hook(ts->parent.t, LTT_EVENT_SYSCALL_ENTRY, - LTT_FIELD_SYSCALL_ID, 0, 0, - syscall_entry, NULL, &g_array_index(hooks, LttvTraceHook, hn++)); - if(ret) hn--; + FIELD_ARRAY(LTT_FIELD_SYSCALL_ID), + syscall_entry, NULL, &hooks); - ret = lttv_trace_find_hook(ts->parent.t, + lttv_trace_find_hook(ts->parent.t, LTT_EVENT_SYSCALL_EXIT, - 0, 0, 0, - syscall_exit, NULL, &g_array_index(hooks, LttvTraceHook, hn++)); - if(ret) hn--; + FIELD_ARRAY(0), + syscall_exit, NULL, &hooks); - ret = lttv_trace_find_hook(ts->parent.t, + lttv_trace_find_hook(ts->parent.t, LTT_EVENT_TRAP_ENTRY, - LTT_FIELD_TRAP_ID, 0, 0, - trap_entry, NULL, &g_array_index(hooks, LttvTraceHook, hn++)); - if(ret) hn--; + FIELD_ARRAY(LTT_FIELD_TRAP_ID), + trap_entry, NULL, &hooks); ret = lttv_trace_find_hook(ts->parent.t, LTT_EVENT_TRAP_EXIT, diff --git a/ltt/branches/poly/lttv/lttv/tracecontext.c b/ltt/branches/poly/lttv/lttv/tracecontext.c index f2fd4413..39ee2950 100644 --- a/ltt/branches/poly/lttv/lttv/tracecontext.c +++ b/ltt/branches/poly/lttv/lttv/tracecontext.c @@ -969,29 +969,26 @@ struct marker_info *lttv_trace_hook_get_marker(LttTrace *t, LttvTraceHook *th) } -GArray *lttv_trace_find_hook(LttTrace *t, GQuark marker_name, - GQuark fields[], LttvHook h, gpointer hook_data) +int lttv_trace_find_hook(LttTrace *t, GQuark marker_name, + GQuark fields[], LttvHook h, gpointer hook_data, GArray **trace_hooks) { struct marker_info *info; - GQuark *pfieldname; struct marker_field *field; guint16 marker_id; - - GArray * retval; + int init_array_size; info = marker_get_info_from_name(t, marker_name); if(unlikely(info == NULL)) { return NULL; } - retval = g_array_new(FALSE, FALSE, sizeof(LttvTraceHook)); - - + init_array_size = (*trace_hooks)->len; /* for each marker with the requested name */ do { LttvTraceHook tmpth; int found; + GQuark f; marker_id = marker_get_id_from_info(t, info); @@ -1001,52 +998,44 @@ GArray *lttv_trace_find_hook(LttTrace *t, GQuark marker_name, tmpth.fields = g_ptr_array_new(); /* for each field requested */ - found = 0; - for(pfieldname = fields; pfieldname != NULL; pfieldname++) { - for_each_marker_field(field, info) { - if(field->name == *pfieldname) { - + for(f = fields; *f != 0; f++) { + found = 0; + for_each_marker_field(marker_field, info) { + if(marker_fieldfield->name == *f) { found = 1; - g_ptr_array_add(tmpth.fields, field); + g_ptr_array_add(tmpth.fields, marker_field); break; } } if(!found) { /* Did not find the one of the fields in this instance of the - marker. Skip it. */ + marker. Print a warning and skip this marker completely. + Still iterate on other markers with same name. */ g_ptr_array_free(tmpth.fields, TRUE); - goto free_retval; + g_warning("Field %s cannot be found in marker %s", + g_quark_to_string(*f), g_quark_to_string(marker_name)); + goto skip_marker; } } - /* all fields were found: add the tracehook to the array */ - g_array_append_val(retval, tmpth); - + *trace_hooks = g_array_append_val(*trace_hooks, tmpth); +skip_marker: info = info->next; } while(info != NULL); - - if(retval->len) - return retval; - - free_retval: - g_array_free(retval, TRUE); - return NULL; + /* Error if no new trace hook has been added */ + return (init_array_size == (*trace_hooks)->len); } -void lttv_trace_hook_destroy(GArray *th) +void lttv_trace_hook_destroy(GArray **th) { int i; for(i=0; ilen; i++) { g_ptr_array_free(g_array_index(th, LttvTraceHook, i).fields, TRUE); } - - g_array_free(th, TRUE); + *th = g_array_remove_range(*th, 0, th->len); } - - - LttvTracesetContextPosition *lttv_traceset_context_position_new( const LttvTracesetContext *self) { diff --git a/ltt/branches/poly/lttv/lttv/tracecontext.h b/ltt/branches/poly/lttv/lttv/tracecontext.h index eb9e15be..79b3db6c 100644 --- a/ltt/branches/poly/lttv/lttv/tracecontext.h +++ b/ltt/branches/poly/lttv/lttv/tracecontext.h @@ -293,11 +293,14 @@ void lttv_trace_hook_destroy(GArray *th); is useful to find the specific id for an event within a trace, for registering a hook using this structure as event data; it already contains the (up to three) needed fields handles. - Returns an array of LttvTraceHook, or NULL on error. + Returns the modified LttvTraceHook array. + Prints warnings if events or markers are not found. returns 1 on error, + 0 on success. + Adds the hooks to the trace_hooks array. */ -GArray *lttv_trace_find_hook(LttTrace *t, GQuark marker_name, - GQuark fields[], LttvHook h, gpointer hook_data); +int lttv_trace_find_hook(LttTrace *t, GQuark marker_name, + GQuark fields[], LttvHook h, gpointer hook_data, GArray **trace_hooks); LttvTracefileContext *lttv_traceset_context_get_current_tfc( LttvTracesetContext *self); -- 2.34.1