@@ -103,14 +103,7 @@ where
103
103
match self . decoder . resync ( ) {
104
104
Ok ( s) => {
105
105
self . status = s;
106
- if self . status . eos ( ) {
107
- return Ok ( ( ) ) ;
108
- }
109
-
110
- // If exclude_hv is set and we are in root VMX operation, continue resyncing
111
- if self . exclude_hv || matches ! ( self . vmx_non_root, Some ( true ) ) {
112
- return Ok ( ( ) ) ;
113
- }
106
+ return Ok ( ( ) ) ;
114
107
}
115
108
Err ( e) => match e. code ( ) {
116
109
PtErrorCode :: Eos => return Ok ( ( ) ) ,
@@ -149,39 +142,62 @@ where
149
142
self . handle_event ( ) ?;
150
143
}
151
144
152
- // If exclude_hv is set and we are in root VMX operation, bail out
153
- if self . exclude_hv && matches ! ( self . vmx_non_root, Some ( false ) ) {
154
- return Ok ( ( ) ) ;
145
+ let offset = self . decoder . offset ( ) . map_err ( error_from_pt_error) ?;
146
+ if self . should_ignore_vmx_root ( ) || offset <= self . trace_skip {
147
+ self . ignore_block ( ) ?;
148
+ } else {
149
+ self . decode_block ( ) ?;
155
150
}
156
151
157
- match self . decoder . decode_next ( ) {
158
- Ok ( ( b, s) ) => {
159
- self . status = s;
160
- let offset = self . decoder . offset ( ) . map_err ( error_from_pt_error) ?;
161
- if b. ninsn ( ) > 0 && self . trace_skip < offset {
162
- let id = hash_64_fast ( self . previous_block_end_ip ) ^ hash_64_fast ( b. ip ( ) ) ;
163
- // SAFETY: the index is < map_len since the modulo operation is applied
164
- unsafe {
165
- let map_loc = self . map_ptr . add ( id as usize % self . map_len ) ;
166
- * map_loc = ( * map_loc) . saturating_add ( & 1u8 . into ( ) ) ;
167
- }
168
- self . previous_block_end_ip = b. end_ip ( ) ;
169
- }
152
+ if self . status . eos ( ) {
153
+ return Ok ( ( ) ) ;
154
+ }
155
+ }
156
+ }
170
157
171
- if self . status . eos ( ) {
172
- return Ok ( ( ) ) ;
158
+ fn decode_block ( & mut self ) -> Result < ( ) , Error > {
159
+ match self . decoder . decode_next ( ) {
160
+ Ok ( ( b, s) ) => {
161
+ self . status = s;
162
+ if b. ninsn ( ) > 0 {
163
+ let id = hash_64_fast ( self . previous_block_end_ip ) ^ hash_64_fast ( b. ip ( ) ) ;
164
+ // SAFETY: the index is < map_len since the modulo operation is applied
165
+ unsafe {
166
+ let map_loc = self . map_ptr . add ( id as usize % self . map_len ) ;
167
+ * map_loc = ( * map_loc) . saturating_add ( & 1u8 . into ( ) ) ;
173
168
}
169
+ self . previous_block_end_ip = b. end_ip ( ) ;
174
170
}
175
- Err ( e) => {
176
- if e. code ( ) != PtErrorCode :: Eos {
177
- let offset = self . decoder . offset ( ) . map_err ( error_from_pt_error) ?;
178
- log:: info!(
179
- "PT error in block next {e:?} trace offset {offset:x} last decoded block end {:x}" ,
180
- self . previous_block_end_ip
181
- ) ;
182
- }
183
- return Err ( error_from_pt_error ( e) ) ;
171
+ Ok ( ( ) )
172
+ }
173
+ Err ( e) => {
174
+ if e. code ( ) != PtErrorCode :: Eos {
175
+ let offset = self . decoder . offset ( ) . map_err ( error_from_pt_error) ?;
176
+ log:: info!(
177
+ "PT error in block next {e:?} trace offset {offset:x} last decoded block end {:x}" ,
178
+ self . previous_block_end_ip
179
+ ) ;
180
+ }
181
+ Err ( error_from_pt_error ( e) )
182
+ }
183
+ }
184
+ }
185
+
186
+ fn ignore_block ( & mut self ) -> Result < ( ) , Error > {
187
+ match self . decoder . decode_next ( ) {
188
+ Ok ( ( _, s) ) => {
189
+ self . status = s;
190
+ Ok ( ( ) )
191
+ }
192
+ Err ( e) => {
193
+ if e. code ( ) != PtErrorCode :: Eos {
194
+ let offset = self . decoder . offset ( ) . map_err ( error_from_pt_error) ?;
195
+ log:: trace!(
196
+ "PT error in ignore block {e:?} trace offset {offset:x} last decoded block end {:x}" ,
197
+ self . previous_block_end_ip
198
+ ) ;
184
199
}
200
+ Err ( error_from_pt_error ( e) )
185
201
}
186
202
}
187
203
}
@@ -200,4 +216,9 @@ where
200
216
Err ( e) => Err ( Error :: illegal_state ( format ! ( "PT error in event {e:?}" ) ) ) ,
201
217
}
202
218
}
219
+
220
+ /// Returns true if `exclude_hv` is set and we are in root VMX operation
221
+ fn should_ignore_vmx_root ( & self ) -> bool {
222
+ self . exclude_hv && matches ! ( self . vmx_non_root, Some ( false ) )
223
+ }
203
224
}
0 commit comments