From 91f8d488607f78334aee6fda44668b0b4377c2a5 Mon Sep 17 00:00:00 2001 From: compudj Date: Fri, 12 Oct 2007 00:16:22 +0000 Subject: [PATCH] add debug event git-svn-id: http://ltt.polymtl.ca/svn@2661 04897980-b3bd-0310-b5e0-8ef037075253 --- ltt/branches/poly/ltt/trace.h | 3 + ltt/branches/poly/ltt/tracefile.c | 99 ++++++++++++++++++++++++++++++ ltt/branches/poly/lttv/lttv/main.c | 13 ++++ 3 files changed, 115 insertions(+) diff --git a/ltt/branches/poly/ltt/trace.h b/ltt/branches/poly/ltt/trace.h index ca3edd99..05a8133c 100644 --- a/ltt/branches/poly/ltt/trace.h +++ b/ltt/branches/poly/ltt/trace.h @@ -220,4 +220,7 @@ guint64 ltt_get_uint(gboolean reverse_byte_order, gint size, void *data); LttTime ltt_interpolate_time_from_tsc(LttTracefile *tf, guint64 tsc); +/* Set to enable event debugging output */ +void ltt_event_debug(int state); + #endif // TRACE_H diff --git a/ltt/branches/poly/ltt/tracefile.c b/ltt/branches/poly/ltt/tracefile.c index 9ddfaf29..553bed14 100644 --- a/ltt/branches/poly/ltt/tracefile.c +++ b/ltt/branches/poly/ltt/tracefile.c @@ -116,6 +116,15 @@ static gint map_block(LttTracefile * tf, guint block_num); static int ltt_seek_next_event(LttTracefile *tf); static void __attribute__((constructor)) init(void); static void ltt_update_event_size(LttTracefile *tf); + +/* Enable event debugging */ +static int a_event_debug = 0; + +void ltt_event_debug(int state) +{ + a_event_debug = state; +} + //void precompute_offsets(LttFacility *fac, LttEventType *event); #if 0 @@ -1740,6 +1749,38 @@ int ltt_tracefile_read_op(LttTracefile *tf) return 0; } +static void print_debug_event_header(LttEvent *ev, void *start_pos, void *end_pos) +{ + unsigned int offset = 0; + int i, j; + + g_printf("Event header (tracefile %s offset %llx):\n", + g_quark_to_string(ev->tracefile->name), + ((uint64_t)ev->tracefile->buffer.index * ev->tracefile->buf_size) + + (long)start_pos - (long)ev->tracefile->buffer.head); + + while (offset < (long)end_pos - (long)start_pos) { + g_printf("%8lx", (long)start_pos - (long)ev->tracefile->buffer.head + offset); + g_printf(" "); + + for (i = 0; i < 4 ; i++) { + for (j = 0; j < 4; j++) { + if (offset + ((i * 4) + j) < + (long)end_pos - (long)start_pos) + g_printf("%02hhX", + ((char*)ev->tracefile->buffer.head)[ev->offset + offset + ((i * 4) + j)]); + else + g_printf(" "); + g_printf(" "); + } + if (i < 4) + g_printf(" "); + } + offset+=16; + g_printf("\n"); + } +} + /* same as ltt_tracefile_read, but does not seek to the next event nor call * event specific operation. */ @@ -1747,6 +1788,7 @@ int ltt_tracefile_read_update_event(LttTracefile *tf) { void * pos; LttEvent *event; + void *pos_aligned; event = &tf->event; pos = tf->buffer.head + event->offset; @@ -1760,6 +1802,7 @@ int ltt_tracefile_read_update_event(LttTracefile *tf) g_assert(tf->has_heartbeat); pos += ltt_align((size_t)pos, sizeof(uint32_t), tf->alignment); } + pos_aligned = pos; if(tf->has_heartbeat) { event->timestamp = ltt_get_uint32(LTT_GET_BO(tf), @@ -1835,6 +1878,10 @@ int ltt_tracefile_read_update_event(LttTracefile *tf) } else { /* Compact event */ } + + if (a_event_debug) + print_debug_event_header(event, pos_aligned, pos); + /* Align the head */ if(!tf->compact) pos += ltt_align((size_t)pos, tf->trace->arch_size, tf->alignment); @@ -1982,6 +2029,54 @@ map_error: } +static void print_debug_event_data(LttEvent *ev) +{ + unsigned int offset = 0; + int i, j; + + if (!max(ev->event_size, ev->data_size)) + return; + + g_printf("Event data (tracefile %s offset %llx):\n", + g_quark_to_string(ev->tracefile->name), + ((uint64_t)ev->tracefile->buffer.index * ev->tracefile->buf_size) + + (long)ev->data - (long)ev->tracefile->buffer.head); + + while (offset < max(ev->event_size, ev->data_size)) { + g_printf("%8lx", (long)ev->data + offset + - (long)ev->tracefile->buffer.head); + g_printf(" "); + + for (i = 0; i < 4 ; i++) { + for (j = 0; j < 4; j++) { + if (offset + ((i * 4) + j) < max(ev->event_size, ev->data_size)) + g_printf("%02hhX", ((char*)ev->data)[offset + ((i * 4) + j)]); + else + g_printf(" "); + g_printf(" "); + } + if (i < 4) + g_printf(" "); + } + + g_printf(" "); + + for (i = 0; i < 4; i++) { + for (j = 0; j < 4; j++) { + if (offset + ((i * 4) + j) < max(ev->event_size, ev->data_size)) { + if (isprint(((char*)ev->data)[offset + ((i * 4) + j)])) + g_printf("%c", ((char*)ev->data)[offset + ((i * 4) + j)]); + else + g_printf("."); + } else + g_printf(" "); + } + } + offset+=16; + g_printf("\n"); + } +} + /* It will update the fields offsets too */ void ltt_update_event_size(LttTracefile *tf) { @@ -2042,6 +2137,10 @@ void ltt_update_event_size(LttTracefile *tf) /* Event size too big to fit in the event size field */ tf->event.event_size = tf->event.data_size; } + + if (a_event_debug) + print_debug_event_data(&tf->event); + if (tf->event.data_size != tf->event.event_size) { struct marker_info *info = marker_get_info_from_id(tf->trace, tf->event.event_id); diff --git a/ltt/branches/poly/lttv/lttv/main.c b/ltt/branches/poly/lttv/lttv/main.c index 4e306c6d..9765d3f3 100644 --- a/ltt/branches/poly/lttv/lttv/main.c +++ b/ltt/branches/poly/lttv/lttv/main.c @@ -67,6 +67,8 @@ static void lttv_verbose(void *hook_data); static void lttv_debug(void *hook_data); +static void lttv_event_debug(void *hook_data); + static void lttv_fatal(void *hook_data); static void lttv_help(void *hook_data); @@ -183,6 +185,11 @@ int main(int argc, char **argv) lttv_option_add("debug",'d', "print debugging messages", "none", LTTV_OPT_NONE, NULL, lttv_debug, NULL); + /* use -edebug, -e conflicts with filter. Problem with option parsing when we + * reparse the options with different number of arguments. */ + lttv_option_add("edebug",'e', "print event debugging", "none", + LTTV_OPT_NONE, NULL, lttv_event_debug, NULL); + a_fatal = FALSE; lttv_option_add("fatal",'f', "make critical messages fatal", "none", @@ -265,6 +272,12 @@ void lttv_debug(void *hook_data) g_info("Logging set to include DEBUG level messages"); } +void lttv_event_debug(void *hook_data) +{ + ltt_event_debug(1); + g_info("Output event detailed debug"); +} + void lttv_fatal(void *hook_data) { g_log_set_always_fatal(G_LOG_LEVEL_WARNING | G_LOG_LEVEL_CRITICAL); -- 2.34.1