@@ -151,6 +151,11 @@ struct ptxed_options {
151
151
/* Print sideband warnings. */
152
152
uint32_t print_sb_warnings :1 ;
153
153
#endif
154
+
155
+ #if (LIBIPT_VERSION >= 0x202 )
156
+ /* Resync on error. */
157
+ uint32_t resync_on_error :1 ;
158
+ #endif
154
159
};
155
160
156
161
/* A collection of flags selecting which stats to collect/print. */
@@ -248,6 +253,9 @@ static void help(const char *name)
248
253
printf (" --time print the current timestamp.\n" );
249
254
printf (" --raw-insn print the raw bytes of each instruction.\n" );
250
255
printf (" --check perform checks (expensive).\n" );
256
+ #if (LIBIPT_VERSION >= 0x202 )
257
+ printf (" --resync-on-error resync on decode errors more aggressively.\n" );
258
+ #endif
251
259
printf (" --iscache-limit <size> set the image section cache limit to <size> bytes.\n" );
252
260
printf (" --event:time print the tsc for events if available.\n" );
253
261
printf (" --event:ip print the ip of events if available.\n" );
@@ -1532,6 +1540,36 @@ static int drain_events_insn(struct ptxed_decoder *decoder, uint64_t *time,
1532
1540
return status ;
1533
1541
}
1534
1542
1543
+ #if (LIBIPT_VERSION >= 0x202 )
1544
+ static int resync_insn (struct ptxed_decoder * decoder ,
1545
+ const struct ptxed_options * options ,
1546
+ uint64_t * time )
1547
+ {
1548
+ int status ;
1549
+
1550
+ if (!decoder || !options )
1551
+ return - pte_internal ;
1552
+
1553
+ for (;;) {
1554
+ status = pt_insn_resync (decoder -> variant .insn );
1555
+ if (status >= 0 )
1556
+ break ;
1557
+
1558
+ if (status != - pte_event_ignored )
1559
+ return status ;
1560
+
1561
+ status = handle_one_event_insn (decoder , options , time );
1562
+ if (status < 0 )
1563
+ return status ;
1564
+ }
1565
+
1566
+ if ((status & pts_ip_suppressed ) && !options -> quiet )
1567
+ printf ("[disabled]\n" );
1568
+
1569
+ return status ;
1570
+ }
1571
+ #endif /* (LIBIPT_VERSION >= 0x202) */
1572
+
1535
1573
static int decode_one_insn (struct ptxed_decoder * decoder ,
1536
1574
const struct ptxed_options * options ,
1537
1575
struct ptxed_stats * stats , struct pt_insn * insn ,
@@ -1633,31 +1671,49 @@ static void decode_insn(struct ptxed_decoder *decoder,
1633
1671
}
1634
1672
1635
1673
for (;;) {
1636
- status = drain_events_insn (decoder , & time , status ,
1637
- options );
1638
- if (status < 0 )
1639
- break ;
1674
+ for (;;) {
1675
+ status = drain_events_insn (decoder , & time ,
1676
+ status , options );
1677
+ if (status < 0 )
1678
+ break ;
1679
+
1680
+ if (status & pts_eos ) {
1681
+ if (!(status & pts_ip_suppressed ) &&
1682
+ !options -> quiet )
1683
+ printf ("[end of trace]\n" );
1684
+
1685
+ status = - pte_eos ;
1686
+ break ;
1687
+ }
1688
+
1689
+ status = decode_one_insn (decoder , options ,
1690
+ stats , & insn , time );
1691
+ if (status < 0 )
1692
+ break ;
1693
+ }
1694
+
1695
+ /* We're done when we reach the end of the trace
1696
+ * stream.
1697
+ */
1698
+ if (status == - pte_eos )
1699
+ return ;
1640
1700
1641
- if (status & pts_eos ) {
1642
- if (!(status & pts_ip_suppressed ) &&
1643
- !options -> quiet )
1644
- printf ("[end of trace]\n" );
1701
+ diagnose_insn (decoder , "error" , status , & insn );
1645
1702
1646
- status = - pte_eos ;
1703
+ #if (LIBIPT_VERSION >= 0x202 )
1704
+ if (!options -> resync_on_error )
1647
1705
break ;
1648
- }
1649
1706
1650
- status = decode_one_insn (decoder , options , stats ,
1651
- & insn , time );
1652
- if (status < 0 )
1707
+ status = resync_insn (decoder , options , & time );
1708
+ if (status < 0 ) {
1709
+ diagnose_insn (decoder , "resync error" , status ,
1710
+ & insn );
1653
1711
break ;
1654
- }
1655
-
1656
- /* We're done when we reach the end of the trace stream. */
1657
- if (status == - pte_eos )
1712
+ }
1713
+ #else
1658
1714
break ;
1659
-
1660
- diagnose_insn ( decoder , "error" , status , & insn );
1715
+ #endif
1716
+ }
1661
1717
}
1662
1718
}
1663
1719
@@ -1992,6 +2048,36 @@ static int drain_events_block(struct ptxed_decoder *decoder, uint64_t *time,
1992
2048
return status ;
1993
2049
}
1994
2050
2051
+ #if (LIBIPT_VERSION >= 0x202 )
2052
+ static int resync_block (struct ptxed_decoder * decoder ,
2053
+ const struct ptxed_options * options ,
2054
+ uint64_t * time )
2055
+ {
2056
+ int status ;
2057
+
2058
+ if (!decoder || !options )
2059
+ return - pte_internal ;
2060
+
2061
+ for (;;) {
2062
+ status = pt_blk_resync (decoder -> variant .block );
2063
+ if (status >= 0 )
2064
+ break ;
2065
+
2066
+ if (status != - pte_event_ignored )
2067
+ return status ;
2068
+
2069
+ status = handle_one_event_block (decoder , options , time );
2070
+ if (status < 0 )
2071
+ return status ;
2072
+ }
2073
+
2074
+ if ((status & pts_ip_suppressed ) && !options -> quiet )
2075
+ printf ("[disabled]\n" );
2076
+
2077
+ return status ;
2078
+ }
2079
+ #endif /* (LIBIPT_VERSION >= 0x202) */
2080
+
1995
2081
static int decode_one_block (struct ptxed_decoder * decoder ,
1996
2082
const struct ptxed_options * options ,
1997
2083
struct ptxed_stats * stats ,
@@ -2081,31 +2167,49 @@ static void decode_block(struct ptxed_decoder *decoder,
2081
2167
}
2082
2168
2083
2169
for (;;) {
2084
- status = drain_events_block (decoder , & time , status ,
2085
- options );
2086
- if (status < 0 )
2087
- break ;
2170
+ for (;;) {
2171
+ status = drain_events_block (decoder , & time ,
2172
+ status , options );
2173
+ if (status < 0 )
2174
+ break ;
2175
+
2176
+ if (status & pts_eos ) {
2177
+ if (!(status & pts_ip_suppressed ) &&
2178
+ !options -> quiet )
2179
+ printf ("[end of trace]\n" );
2180
+
2181
+ status = - pte_eos ;
2182
+ break ;
2183
+ }
2184
+
2185
+ status = decode_one_block (decoder , options ,
2186
+ stats , & block , time );
2187
+ if (status < 0 )
2188
+ break ;
2189
+ }
2088
2190
2089
- if (status & pts_eos ) {
2090
- if (!(status & pts_ip_suppressed ) &&
2091
- !options -> quiet )
2092
- printf ("[end of trace]\n" );
2191
+ /* We're done when we reach the end of the trace
2192
+ * stream.
2193
+ */
2194
+ if (status == - pte_eos )
2195
+ return ;
2093
2196
2094
- status = - pte_eos ;
2095
- break ;
2096
- }
2197
+ diagnose_block (decoder , "error" , status , & block );
2097
2198
2098
- status = decode_one_block (decoder , options , stats ,
2099
- & block , time );
2100
- if (status < 0 )
2199
+ #if (LIBIPT_VERSION >= 0x202 )
2200
+ if (!options -> resync_on_error )
2101
2201
break ;
2102
- }
2103
2202
2104
- /* We're done when we reach the end of the trace stream. */
2105
- if (status == - pte_eos )
2203
+ status = resync_block (decoder , options , & time );
2204
+ if (status < 0 ) {
2205
+ diagnose_block (decoder , "resync error" , status ,
2206
+ & block );
2207
+ break ;
2208
+ }
2209
+ #else
2106
2210
break ;
2107
-
2108
- diagnose_block ( decoder , "error" , status , & block );
2211
+ #endif
2212
+ }
2109
2213
}
2110
2214
}
2111
2215
@@ -2824,6 +2928,12 @@ extern int main(int argc, char *argv[])
2824
2928
options .check = 1 ;
2825
2929
continue ;
2826
2930
}
2931
+ #if (LIBIPT_VERSION >= 0x202 )
2932
+ if (strcmp (arg , "--resync-on-error" ) == 0 ) {
2933
+ options .resync_on_error = 1 ;
2934
+ continue ;
2935
+ }
2936
+ #endif
2827
2937
if (strcmp (arg , "--iscache-limit" ) == 0 ) {
2828
2938
uint64_t limit ;
2829
2939
0 commit comments