Skip to content

Commit 1c26db0

Browse files
committed
Change search from CTRL-S to CTRL-F & fix off by one errors in data submission
1 parent 4e8fe9d commit 1c26db0

File tree

9 files changed

+127
-53
lines changed

9 files changed

+127
-53
lines changed

Inc/etmDecoder.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ enum ETMchanges
7373
// Messages out of the decoder
7474
// ============================================================================
7575
enum ETMDecoderMsgType { ETMDEC_MSG_NONE, ETM_BRANCH, ETMDEC_MSG_NUM_MSGS };
76-
enum Mode { ETM_ADDRMODE_ARM, ETM_ADDRMODE_THUMB, ETM_ADDRMODE_JAZELLE };
76+
enum Mode { ETM_ADDRMODE_THUMB, ETM_ADDRMODE_ARM, ETM_ADDRMODE_JAZELLE };
7777
enum Reason { ETM_REASON_PERIODIC, ETM_REASON_TRACEON, ETM_REASON_TRACEOVF, ETM_REASON_EXITDBG };
7878

7979
/* ETM Decoder statistics */
@@ -156,11 +156,12 @@ void ETMDecoderForceSync( struct ETMDecoder *i, bool isSynced );
156156
void ETMDecoderZeroStats( struct ETMDecoder *i );
157157
bool ETMDecoderIsSynced( struct ETMDecoder *i );
158158

159-
inline struct ETMCPUState *ETMCPUState( struct ETMDecoder *i )
159+
ALWAYS_INLINE struct ETMCPUState *ETMCPUState( struct ETMDecoder *i )
160160
{
161161
return &i->cpu;
162162
}
163-
inline bool ETMStateChanged( struct ETMDecoder *i, enum ETMchanges c )
163+
164+
ALWAYS_INLINE bool ETMStateChanged( struct ETMDecoder *i, enum ETMchanges c )
164165
{
165166
bool r = ( i->cpu.changeRecord & ( 1 << c ) ) != 0;
166167
i->cpu.changeRecord &= ~( 1 << c );

Inc/generics.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ extern "C" {
5959
#define C_WHITE "\033[1;37m"
6060
#define C_MONO ""
6161

62+
#define ALWAYS_INLINE inline __attribute__((always_inline))
6263
// ====================================================================================================
6364
enum verbLevel {V_ERROR, V_WARN, V_INFO, V_DEBUG, V_MAX_VERBLEVEL};
6465

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,8 @@ For `orbuculum`, the specific command line options of note are;
279279

280280
`-m`: Monitor interval (in mS) for reporting on state of the link. If baudrate is specified (using `-a`) and is greater than 100bps then the percentage link occupancy is also reported.
281281

282+
`-o [filename]`: Record trace data locally. This is unfettered data directly from the source device, can be useful for replay purposes or other tool testing.
283+
282284
`-p [serialPort]`: to use. If not specified then the program defaults to Blackmagic probe.
283285

284286
`-s [address]:[port]`: Set address for explicit TCP Source connection, (default none:2332).
@@ -513,7 +515,7 @@ configured to stream parallel trace info (clue; the `startETM` option).
513515

514516
The command line options of note are;
515517

516-
`-a`: Use alternate address encoding. Select this if decodes don't seem to arrive correctly. You can discover if you need this option by using the `describeETM` command inside the debugger.
518+
`-a`: Don't use alternate address encoding. Select this if decodes don't seem to arrive correctly. You can discover if you need this option by using the `describeETM` command inside the debugger.
517519

518520
`-b [Length]`: Set length of post-mortem buffer, in KBytes (Default 32 KBytes)
519521

Src/etmDecoder.c

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -76,19 +76,16 @@ static void _ETMDecoderPumpAction( struct ETMDecoder *i, uint8_t c, etmDecodeCB
7676
break;
7777

7878
// -----------------------------------------------------
79+
7980
case ETM_IDLE:
8081

8182
// *************************************************
8283
// ************** BRANCH PACKET ********************
8384
// *************************************************
8485
if ( c & 0b1 )
8586
{
86-
if ( report )
87-
{
88-
report( V_DEBUG, "BRANCH " );
89-
}
90-
9187
/* The lowest order 6 bits of address info... */
88+
9289
switch ( cpu->addrMode )
9390
{
9491
case ETM_ADDRMODE_ARM:
@@ -105,7 +102,7 @@ static void _ETMDecoderPumpAction( struct ETMDecoder *i, uint8_t c, etmDecodeCB
105102
}
106103

107104
i->byteCount = 1;
108-
C = c & 0x80;
105+
C = ( c & 0x80 ) != 0;
109106
X = false;
110107
_stateChange( i, EV_CH_ADDRESS );
111108

@@ -312,7 +309,7 @@ static void _ETMDecoderPumpAction( struct ETMDecoder *i, uint8_t c, etmDecodeCB
312309

313310
if ( report )
314311
{
315-
report( V_DEBUG, "PHdr FMT1 (E=%d, N=%d)" EOL, cpu->eatoms, cpu->natoms );
312+
report( V_DEBUG, "PHdr FMT1 (%02x E=%d, N=%d)" EOL, c, cpu->eatoms, cpu->natoms );
316313
}
317314

318315
break;
@@ -466,10 +463,10 @@ static void _ETMDecoderPumpAction( struct ETMDecoder *i, uint8_t c, etmDecodeCB
466463
C = c & 0x80;
467464
/* This is a proper mess. Mask and collect bits according to address mode in use and */
468465
/* if it's the last byte of the sequence */
469-
470466
mask = C ? 0x7f : 0x3f;
471467
ofs = ( cpu->addrMode == ETM_ADDRMODE_ARM ) ? 1 : ( cpu->addrMode == ETM_ADDRMODE_THUMB ) ? 0 : -1;
472468

469+
473470
i->addrConstruct = ( i->addrConstruct & ~( mask << ( 7 * i->byteCount + ofs ) ) )
474471
| ( ( c & mask ) << ( 7 * i->byteCount + ofs ) );
475472
/* There is exception information only if no continuation and bit 6 set */
@@ -488,6 +485,10 @@ static void _ETMDecoderPumpAction( struct ETMDecoder *i, uint8_t c, etmDecodeCB
488485
X = ( i->byteCount == 5 ) && C;
489486
goto terminateAddrByte;
490487

488+
// -----------------------------------------------------
489+
490+
/* For all cases, see if the address is complete, and process if so */
491+
/* this is a continuation of ETM_COLLECT_BA_???_FORMAT. */
491492
terminateAddrByte:
492493

493494
/* Check to see if this packet is complete, and encode to return if so */
@@ -849,7 +850,8 @@ static void _ETMDecoderPumpAction( struct ETMDecoder *i, uint8_t c, etmDecodeCB
849850
if ( i->addrConstruct & ( 1 << 0 ) )
850851
{
851852
cpu->addrMode = ETM_ADDRMODE_THUMB;
852-
cpu->addr = i->addrConstruct & 0xFFFFFFFE;
853+
i->addrConstruct &= ~( 1 << 0 );
854+
cpu->addr = i->addrConstruct;
853855
}
854856
else
855857
{
@@ -986,7 +988,7 @@ void ETMDecoderPump( struct ETMDecoder *i, uint8_t *buf, int len, etmDecodeCB cb
986988
{
987989
while ( len-- )
988990
{
989-
_ETMDecoderPumpAction( i, *buf++, cb, report, d );
991+
_ETMDecoderPumpAction( i, *( buf++ ), cb, report, d );
990992
}
991993
}
992994
// ====================================================================================================

Src/nwclient.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
#include <arpa/inet.h>
1616
#include <assert.h>
1717
#include <strings.h>
18+
#include <stdio.h>
19+
#include <linux/tcp.h>
1820
#include "generics.h"
1921
#include "nwclient.h"
2022

@@ -315,8 +317,6 @@ void nwclientShutdown( struct nwclientsHandle *h )
315317
return;
316318
}
317319

318-
struct nwClient *c = h->firstClient;
319-
320320
/* Flag that we're ending */
321321
h->finish = true;
322322

@@ -325,6 +325,8 @@ void nwclientShutdown( struct nwclientsHandle *h )
325325
genericsExit( -1, "Failed to acquire mutex" EOL );
326326
}
327327

328+
struct nwClient *c = h->firstClient;
329+
328330
/* Tell all the clients to terminate */
329331
while ( c )
330332
{

Src/orbmortem.c

Lines changed: 48 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ struct Options
5454
int channel; /* When TPIU is in use, which channel to decode? */
5555
int port; /* Source information */
5656
char *server;
57-
bool altAddr; /* Should alternate addressing be used? */
57+
bool noAltAddr; /* Flag to *not* use alternate addressing */
5858
char *openFileCL; /* Command line for opening refernced file */
5959

6060
} _options =
@@ -92,8 +92,11 @@ struct RunTime
9292
struct SymbolSet *s; /* Symbols read from elf */
9393
bool ending; /* Flag indicating app is terminating */
9494
bool singleShot; /* Flag indicating take a single buffer then stop */
95-
uint64_t intervalBytes; /* Number of bytes transferred in current interval */
96-
uint64_t oldintervalBytes; /* Number of bytes transferred previously */
95+
uint64_t newTotalBytes; /* Number of bytes of real data transferred in total */
96+
uint64_t oldTotalBytes; /* Old number of bytes of real data transferred in total */
97+
uint64_t oldTotalIntervalBytes; /* Number of bytes transferred in previous interval */
98+
uint64_t oldTotalHangBytes; /* Number of bytes transferred in previous hang interval */
99+
97100
uint8_t *pmBuffer; /* The post-mortem buffer */
98101
int wp; /* Index pointers for ring buffer */
99102
int rp;
@@ -149,7 +152,7 @@ static void _printHelp( struct RunTime *r )
149152

150153
{
151154
genericsPrintf( "Usage: %s [options]" EOL, r->progName );
152-
genericsPrintf( " -a: Use alternate address encoding" EOL );
155+
genericsPrintf( " -a: Do not use alternate address encoding" EOL );
153156
genericsPrintf( " -b: <Length> Length of post-mortem buffer, in KBytes (Default %d KBytes)" EOL, DEFAULT_PM_BUFLEN_K );
154157
genericsPrintf( " -c: <command> Command line for external editor (%f = filename, %l = line)" EOL );
155158
genericsPrintf( " -D: Switch off C++ symbol demangling" EOL );
@@ -177,7 +180,7 @@ static int _processOptions( int argc, char *argv[], struct RunTime *r )
177180
{
178181
// ------------------------------------
179182
case 'a':
180-
r->options->altAddr = true;
183+
r->options->noAltAddr = true;
181184
break;
182185

183186
// ------------------------------------
@@ -309,9 +312,6 @@ static void _processBlock( struct RunTime *r )
309312

310313
genericsReport( V_DEBUG, "RXED Packet of %d bytes" EOL, y );
311314

312-
/* Account for this reception */
313-
r->intervalBytes += y;
314-
315315
if ( y )
316316
{
317317
#ifdef DUMP_BLOCK
@@ -351,6 +351,7 @@ static void _processBlock( struct RunTime *r )
351351
if ( r->options->channel == p.packet[g].s )
352352
{
353353
r->pmBuffer[r->wp] = p.packet[g].d;
354+
r->newTotalBytes++;
354355
uint32_t nwp = ( r->wp + 1 ) % r->options->buflen;
355356

356357
if ( nwp == r->rp )
@@ -375,6 +376,8 @@ static void _processBlock( struct RunTime *r )
375376
}
376377
else
377378
{
379+
r->newTotalBytes += y;
380+
378381
while ( y-- )
379382
{
380383
r->pmBuffer[r->wp] = *c++;
@@ -498,6 +501,12 @@ static void _etmCB( void *d )
498501
/* Deal with changes introduced by this event ========================= */
499502
if ( ETMStateChanged( &r->i, EV_CH_ADDRESS ) )
500503
{
504+
/* Make debug report if calculated and reported addresses differ. This is most useful for testing when exhaustive */
505+
/* address reporting is switched on. It will give 'false positives' for uncalculable instructions (e.g. bx lr) but */
506+
/* it's a decent safety net to be sure the jump decoder is working correctly. */
507+
_appendToOPBuffer( r, r->op.currentLine, LT_DEBUG, "%sCommanded CPU Address change (Was:0x%08x Commanded:0x%08x)" EOL,
508+
( r->op.workingAddr == cpu->addr ) ? "" : "***INCONSISTENT*** ", r->op.workingAddr, cpu->addr );
509+
501510
r->op.workingAddr = cpu->addr;
502511
}
503512

@@ -666,6 +675,7 @@ static void _etmCB( void *d )
666675
else
667676
{
668677
/* We didn't have a symbol for this address, so let's just assume a short instruction */
678+
_appendRefToOPBuffer( r, r->op.currentLine, LT_DEBUG, "*** No Symbol found ***" EOL );
669679
r->op.workingAddr += 2;
670680
}
671681

@@ -705,8 +715,8 @@ static void _dumpBuffer( struct RunTime *r )
705715
if ( ( bytesAvailable + r->rp ) > r->options->buflen )
706716
{
707717
/* Buffer is wrapped - submit both parts */
708-
ETMDecoderPump( &r->i, &r->pmBuffer[r->rp], r->options->buflen - r->rp - 1, _etmCB, _etmReport, r );
709-
ETMDecoderPump( &r->i, &r->pmBuffer[0], r->rp, _etmCB, _etmReport, r );
718+
ETMDecoderPump( &r->i, &r->pmBuffer[r->rp], r->options->buflen - r->rp, _etmCB, _etmReport, r );
719+
ETMDecoderPump( &r->i, &r->pmBuffer[0], r->wp, _etmCB, _etmReport, r );
710720
}
711721
else
712722
{
@@ -1034,7 +1044,7 @@ int main( int argc, char *argv[] )
10341044
struct hostent *server;
10351045
int flag = 1;
10361046

1037-
int32_t lastTime, lastTTime, lastTSTime;
1047+
int32_t lastTTime, lastTSTime, lastHTime;
10381048
int r;
10391049
struct timeval tv;
10401050
fd_set readfds;
@@ -1055,7 +1065,7 @@ int main( int argc, char *argv[] )
10551065
_r.sio = SIOsetup( _r.progName, _r.options->elffile, ( _r.options->file != NULL ) );
10561066

10571067
/* Fill in a time to start from */
1058-
lastTime = lastTTime = lastTSTime = genericsTimestampmS();
1068+
lastHTime = lastTTime = lastTSTime = genericsTimestampmS();
10591069

10601070
/* This ensures the atexit gets called */
10611071
if ( SIG_ERR == signal( SIGINT, _intHandler ) )
@@ -1072,7 +1082,7 @@ int main( int argc, char *argv[] )
10721082
/* Create the buffer memory */
10731083
_r.pmBuffer = ( uint8_t * )calloc( 1, _r.options->buflen );
10741084

1075-
ETMDecoderInit( &_r.i, &_r.options->altAddr );
1085+
ETMDecoderInit( &_r.i, !( _r.options->noAltAddr ) );
10761086

10771087
if ( _r.options->useTPIU )
10781088
{
@@ -1108,7 +1118,7 @@ int main( int argc, char *argv[] )
11081118

11091119
if ( !server )
11101120
{
1111-
perror( "Cannot find host" );
1121+
perror( "Cannot find host" EOL );
11121122
return -EIO;
11131123
}
11141124

@@ -1120,7 +1130,7 @@ int main( int argc, char *argv[] )
11201130

11211131
if ( connect( sourcefd, ( struct sockaddr * ) &serv_addr, sizeof( serv_addr ) ) < 0 )
11221132
{
1123-
perror( "Could not connect" );
1133+
/* This can happen when the feeder has gone missing... */
11241134
close( sourcefd );
11251135
usleep( 1000000 );
11261136
continue;
@@ -1135,7 +1145,7 @@ int main( int argc, char *argv[] )
11351145
}
11361146
}
11371147

1138-
FD_ZERO( &readfds );
1148+
FD_ZERO( &readfds );
11391149

11401150
/* ----------------------------------------------------------------------------- */
11411151
/* This is the main active loop...only break out of this when ending or on error */
@@ -1177,12 +1187,11 @@ int main( int argc, char *argv[] )
11771187
{
11781188
/* Pump all of the data through the protocol handler */
11791189
_processBlock( &_r );
1180-
lastTime = genericsTimestampmS();
11811190
}
11821191
}
11831192

11841193
/* Update the outputs and deal with any keys that made it up this high */
1185-
switch ( SIOHandler( _r.sio, ( genericsTimestampmS() - lastTTime ) > TICK_TIME_MS, _r.oldintervalBytes ) )
1194+
switch ( SIOHandler( _r.sio, ( genericsTimestampmS() - lastTTime ) > TICK_TIME_MS, _r.oldTotalIntervalBytes ) )
11861195
{
11871196
case SIO_EV_HOLD:
11881197
if ( !_r.options->file )
@@ -1239,15 +1248,15 @@ int main( int argc, char *argv[] )
12391248
break;
12401249
}
12411250

1242-
/* Update the various timers that are running */
1243-
if ( ( genericsTimestampmS() - lastTTime ) > TICK_TIME_MS )
1244-
{
1245-
lastTTime = genericsTimestampmS();
1246-
}
1251+
/* Deal with possible timeout on sampling, or if this is a read-from-file that is finished */
1252+
if ( ( !_r.numLines ) &&
1253+
(
1254+
( _r.options->file && !sourcefd ) ||
12471255

1248-
/* Deal with possible timeout on sampling, or if this is a read-from-file */
1249-
if ( ( !_r.numLines ) &&
1250-
( _r.options->file || ( ( ( genericsTimestampmS() - lastTime ) > HANG_TIME_MS ) && ( _r.wp != _r.rp ) ) )
1256+
( ( ( genericsTimestampmS() - lastHTime ) > HANG_TIME_MS ) &&
1257+
( _r.newTotalBytes - _r.oldTotalHangBytes == 0 ) &&
1258+
( _r.wp != _r.rp ) )
1259+
)
12511260
)
12521261
{
12531262
_dumpBuffer( &_r );
@@ -1256,10 +1265,21 @@ int main( int argc, char *argv[] )
12561265
}
12571266

12581267
/* Update the intervals */
1268+
if ( ( genericsTimestampmS() - lastHTime ) > HANG_TIME_MS )
1269+
{
1270+
_r.oldTotalHangBytes = _r.newTotalBytes;
1271+
lastHTime = genericsTimestampmS();
1272+
}
1273+
1274+
if ( ( genericsTimestampmS() - lastTTime ) > TICK_TIME_MS )
1275+
{
1276+
lastTTime = genericsTimestampmS();
1277+
}
1278+
12591279
if ( ( genericsTimestampmS() - lastTSTime ) > INTERVAL_TIME_MS )
12601280
{
1261-
_r.oldintervalBytes = _r.intervalBytes;
1262-
_r.intervalBytes = 0;
1281+
_r.oldTotalIntervalBytes = _r.newTotalBytes - _r.oldTotalBytes;
1282+
_r.oldTotalBytes = _r.newTotalBytes;
12631283
lastTSTime = genericsTimestampmS();
12641284
}
12651285
}

0 commit comments

Comments
 (0)