# HG changeset patch # User Michael Spacefalcon # Date 1385151360 0 # Node ID 2f214bd03119924bc5ae228f9bf7953251bc43ce # Parent 3256dc6e84ae4e521ec706be0aebc794c931718a rvtdump: heuristic decoding of G23 traces implemented, works with Pirelli's trace output diff -r 3256dc6e84ae -r 2f214bd03119 rvinterf/lowlevel/Makefile --- a/rvinterf/lowlevel/Makefile Fri Nov 22 07:41:31 2013 +0000 +++ b/rvinterf/lowlevel/Makefile Fri Nov 22 20:16:00 2013 +0000 @@ -3,7 +3,7 @@ PROGS= rvtdump INSTBIN=/usr/local/bin -RVTDUMP_OBJS= format.o openport.o output.o packetrx.o rvtdump.o +RVTDUMP_OBJS= format.o format_g23.o openport.o output.o packetrx.o rvtdump.o all: ${PROGS} diff -r 3256dc6e84ae -r 2f214bd03119 rvinterf/lowlevel/format.c --- a/rvinterf/lowlevel/format.c Fri Nov 22 07:41:31 2013 +0000 +++ b/rvinterf/lowlevel/format.c Fri Nov 22 20:16:00 2013 +0000 @@ -96,24 +96,6 @@ } void -print_g23_trace() -{ - char buf[MAX_PKT_FROM_TARGET*3+2]; - int i; - char *dp; - - dp = buf; - strcpy(dp, "G23:"); - dp += 4; - for (i = 1; i < rxpkt_len; i++) { - sprintf(dp, " %02X", rxpkt[i]); - dp += 3; - } - *dp = '\0'; - output_line(buf); -} - -void print_etm_output_raw() { char buf[MAX_PKT_FROM_TARGET*3+2]; diff -r 3256dc6e84ae -r 2f214bd03119 rvinterf/lowlevel/format_g23.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/rvinterf/lowlevel/format_g23.c Fri Nov 22 20:16:00 2013 +0000 @@ -0,0 +1,111 @@ +/* + * This module implements the decoding of G23 trace packets into + * human-readable form. Because I have not yet reached the point + * of integrating the target-side code that generates these packets, + * I do not yet have the proper understanding of their format. + * Therefore, the current decoding logic implemented here is based + * on a heuristic examination of what the packets look like to an + * uninitiated eye. + */ + +#include +#include +#include +#include +#include "../pktmux.h" +#include "../limits.h" + +extern u_char rxpkt[]; +extern size_t rxpkt_len; + +static int +is_well_formed() +{ + int i, c; + + if (rxpkt_len < 17) + return(0); + for (i = 8; i < 16; i++) { + c = rxpkt[i]; + if (c < ' ' || c > '~') + return(0); + } + return(1); +} + +static void +print_well_formed() +{ + char buf[MAX_PKT_FROM_TARGET*4]; + int i, c; + char *dp; + + dp = buf; + strcpy(dp, "G23:"); + dp += 4; + for (i = 1; i <= 7; i++) { + sprintf(dp, " %02X", rxpkt[i]); + dp += 3; + } + sprintf(dp, " \"%.4s\" \"%.4s\" ", rxpkt+8, rxpkt+12); + dp += 15; + i = 16; + if (rxpkt[i] < 0x20) { + sprintf(dp, "%02X ", rxpkt[i]); + dp += 3; + i++; + } + if (rxpkt_len - i == 5 && rxpkt[i] == '%' && + !rxpkt[i+3] && !rxpkt[i+4]) { + sprintf(dp, "%d", rxpkt[i+2] << 8 | rxpkt[i+1]); + output_line(buf); + return; + } + *dp++ = '\"'; + for (; i < rxpkt_len; i++) { + c = rxpkt[i]; + if (c & 0x80) { + *dp++ = 'M'; + *dp++ = '-'; + c &= 0x7F; + } + if (c < 0x20) { + *dp++ = '^'; + *dp++ = c + '@'; + } else if (c == 0x7F) { + *dp++ = '^'; + *dp++ = '?'; + } else + *dp++ = c; + } + *dp++ = '\"'; + *dp = '\0'; + output_line(buf); +} + +static void +print_malformed() +{ + char buf[MAX_PKT_FROM_TARGET*3+6]; + int i; + char *dp; + + dp = buf; + strcpy(dp, "G23 UNK:"); + dp += 8; + for (i = 1; i < rxpkt_len; i++) { + sprintf(dp, " %02X", rxpkt[i]); + dp += 3; + } + *dp = '\0'; + output_line(buf); +} + +void +print_g23_trace() +{ + if (is_well_formed()) + print_well_formed(); + else + print_malformed(); +}