@@ -54,7 +54,7 @@ struct Options
54
54
int channel ; /* When TPIU is in use, which channel to decode? */
55
55
int port ; /* Source information */
56
56
char * server ;
57
- bool altAddr ; /* Should alternate addressing be used? */
57
+ bool noAltAddr ; /* Flag to *not* use alternate addressing */
58
58
char * openFileCL ; /* Command line for opening refernced file */
59
59
60
60
} _options =
@@ -92,8 +92,11 @@ struct RunTime
92
92
struct SymbolSet * s ; /* Symbols read from elf */
93
93
bool ending ; /* Flag indicating app is terminating */
94
94
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
+
97
100
uint8_t * pmBuffer ; /* The post-mortem buffer */
98
101
int wp ; /* Index pointers for ring buffer */
99
102
int rp ;
@@ -149,7 +152,7 @@ static void _printHelp( struct RunTime *r )
149
152
150
153
{
151
154
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 );
153
156
genericsPrintf ( " -b: <Length> Length of post-mortem buffer, in KBytes (Default %d KBytes)" EOL , DEFAULT_PM_BUFLEN_K );
154
157
genericsPrintf ( " -c: <command> Command line for external editor (%f = filename, %l = line)" EOL );
155
158
genericsPrintf ( " -D: Switch off C++ symbol demangling" EOL );
@@ -177,7 +180,7 @@ static int _processOptions( int argc, char *argv[], struct RunTime *r )
177
180
{
178
181
// ------------------------------------
179
182
case 'a' :
180
- r -> options -> altAddr = true;
183
+ r -> options -> noAltAddr = true;
181
184
break ;
182
185
183
186
// ------------------------------------
@@ -309,9 +312,6 @@ static void _processBlock( struct RunTime *r )
309
312
310
313
genericsReport ( V_DEBUG , "RXED Packet of %d bytes" EOL , y );
311
314
312
- /* Account for this reception */
313
- r -> intervalBytes += y ;
314
-
315
315
if ( y )
316
316
{
317
317
#ifdef DUMP_BLOCK
@@ -351,6 +351,7 @@ static void _processBlock( struct RunTime *r )
351
351
if ( r -> options -> channel == p .packet [g ].s )
352
352
{
353
353
r -> pmBuffer [r -> wp ] = p .packet [g ].d ;
354
+ r -> newTotalBytes ++ ;
354
355
uint32_t nwp = ( r -> wp + 1 ) % r -> options -> buflen ;
355
356
356
357
if ( nwp == r -> rp )
@@ -375,6 +376,8 @@ static void _processBlock( struct RunTime *r )
375
376
}
376
377
else
377
378
{
379
+ r -> newTotalBytes += y ;
380
+
378
381
while ( y -- )
379
382
{
380
383
r -> pmBuffer [r -> wp ] = * c ++ ;
@@ -498,6 +501,12 @@ static void _etmCB( void *d )
498
501
/* Deal with changes introduced by this event ========================= */
499
502
if ( ETMStateChanged ( & r -> i , EV_CH_ADDRESS ) )
500
503
{
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
+
501
510
r -> op .workingAddr = cpu -> addr ;
502
511
}
503
512
@@ -666,6 +675,7 @@ static void _etmCB( void *d )
666
675
else
667
676
{
668
677
/* 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 );
669
679
r -> op .workingAddr += 2 ;
670
680
}
671
681
@@ -705,8 +715,8 @@ static void _dumpBuffer( struct RunTime *r )
705
715
if ( ( bytesAvailable + r -> rp ) > r -> options -> buflen )
706
716
{
707
717
/* 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 );
710
720
}
711
721
else
712
722
{
@@ -1034,7 +1044,7 @@ int main( int argc, char *argv[] )
1034
1044
struct hostent * server ;
1035
1045
int flag = 1 ;
1036
1046
1037
- int32_t lastTime , lastTTime , lastTSTime ;
1047
+ int32_t lastTTime , lastTSTime , lastHTime ;
1038
1048
int r ;
1039
1049
struct timeval tv ;
1040
1050
fd_set readfds ;
@@ -1055,7 +1065,7 @@ int main( int argc, char *argv[] )
1055
1065
_r .sio = SIOsetup ( _r .progName , _r .options -> elffile , ( _r .options -> file != NULL ) );
1056
1066
1057
1067
/* Fill in a time to start from */
1058
- lastTime = lastTTime = lastTSTime = genericsTimestampmS ();
1068
+ lastHTime = lastTTime = lastTSTime = genericsTimestampmS ();
1059
1069
1060
1070
/* This ensures the atexit gets called */
1061
1071
if ( SIG_ERR == signal ( SIGINT , _intHandler ) )
@@ -1072,7 +1082,7 @@ int main( int argc, char *argv[] )
1072
1082
/* Create the buffer memory */
1073
1083
_r .pmBuffer = ( uint8_t * )calloc ( 1 , _r .options -> buflen );
1074
1084
1075
- ETMDecoderInit ( & _r .i , & _r .options -> altAddr );
1085
+ ETMDecoderInit ( & _r .i , !( _r .options -> noAltAddr ) );
1076
1086
1077
1087
if ( _r .options -> useTPIU )
1078
1088
{
@@ -1108,7 +1118,7 @@ int main( int argc, char *argv[] )
1108
1118
1109
1119
if ( !server )
1110
1120
{
1111
- perror ( "Cannot find host" );
1121
+ perror ( "Cannot find host" EOL );
1112
1122
return - EIO ;
1113
1123
}
1114
1124
@@ -1120,7 +1130,7 @@ int main( int argc, char *argv[] )
1120
1130
1121
1131
if ( connect ( sourcefd , ( struct sockaddr * ) & serv_addr , sizeof ( serv_addr ) ) < 0 )
1122
1132
{
1123
- perror ( "Could not connect" );
1133
+ /* This can happen when the feeder has gone missing... */
1124
1134
close ( sourcefd );
1125
1135
usleep ( 1000000 );
1126
1136
continue ;
@@ -1135,7 +1145,7 @@ int main( int argc, char *argv[] )
1135
1145
}
1136
1146
}
1137
1147
1138
- FD_ZERO ( & readfds );
1148
+ FD_ZERO ( & readfds );
1139
1149
1140
1150
/* ----------------------------------------------------------------------------- */
1141
1151
/* 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[] )
1177
1187
{
1178
1188
/* Pump all of the data through the protocol handler */
1179
1189
_processBlock ( & _r );
1180
- lastTime = genericsTimestampmS ();
1181
1190
}
1182
1191
}
1183
1192
1184
1193
/* 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 ) )
1186
1195
{
1187
1196
case SIO_EV_HOLD :
1188
1197
if ( !_r .options -> file )
@@ -1239,15 +1248,15 @@ int main( int argc, char *argv[] )
1239
1248
break ;
1240
1249
}
1241
1250
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 ) ||
1247
1255
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
+ )
1251
1260
)
1252
1261
{
1253
1262
_dumpBuffer ( & _r );
@@ -1256,10 +1265,21 @@ int main( int argc, char *argv[] )
1256
1265
}
1257
1266
1258
1267
/* 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
+
1259
1279
if ( ( genericsTimestampmS () - lastTSTime ) > INTERVAL_TIME_MS )
1260
1280
{
1261
- _r .oldintervalBytes = _r .intervalBytes ;
1262
- _r .intervalBytes = 0 ;
1281
+ _r .oldTotalIntervalBytes = _r .newTotalBytes - _r . oldTotalBytes ;
1282
+ _r .oldTotalBytes = _r . newTotalBytes ;
1263
1283
lastTSTime = genericsTimestampmS ();
1264
1284
}
1265
1285
}
0 commit comments