@@ -221,37 +221,47 @@ fn normalize(symbol: &str) -> String {
221
221
///
222
222
/// This asserts that the function at `fnptr` contains the instruction
223
223
/// `expected` provided.
224
- pub fn assert ( fnptr : usize , expected : & str ) {
224
+ pub fn assert ( fnptr : usize , fnname : & str , expected : & str ) {
225
225
// Translate this function pointer to a symbolic name that we'd have found
226
226
// in the disassembly.
227
227
let mut sym = None ;
228
228
backtrace:: resolve ( fnptr as * mut _ , |name| {
229
229
sym = name. name ( ) . and_then ( |s| s. as_str ( ) ) . map ( normalize) ;
230
230
} ) ;
231
- let sym = match sym {
231
+
232
+ let functions = match sym. as_ref ( ) . and_then ( |s| DISASSEMBLY . get ( s) ) {
232
233
Some ( s) => s,
233
- None => panic ! ( "failed to get symbol of function pointer: {}" , fnptr) ,
234
+ None => {
235
+ if let Some ( sym) = sym {
236
+ println ! ( "assumed symbol name: `{}`" , sym) ;
237
+ }
238
+ println ! ( "maybe related functions" ) ;
239
+ for f in DISASSEMBLY . keys ( ) . filter ( |k| k. contains ( fnname) ) {
240
+ println ! ( "\t - {}" , f) ;
241
+ }
242
+ panic ! ( "failed to find disassembly of {:#x} ({})" , fnptr, fnname) ;
243
+ }
234
244
} ;
235
245
236
- // Find our function in the list of all disassembled functions
237
- let functions = & DISASSEMBLY . get ( & sym)
238
- . expect ( & format ! ( "failed to find disassembly of {}" , sym) ) ;
239
246
assert_eq ! ( functions. len( ) , 1 ) ;
240
247
let function = & functions[ 0 ] ;
241
248
242
249
// Look for `expected` as the first part of any instruction in this
243
250
// function, returning if we do indeed find it.
244
251
for instr in function. instrs . iter ( ) {
252
+ // Gets the first instruction, e.g. tzcntl in tzcntl %rax,%rax
245
253
if let Some ( part) = instr. parts . get ( 0 ) {
246
- if part == expected {
254
+ // Truncates the instruction with the length of the expected
255
+ // instruction: tzcntl => tzcnt and compares that.
256
+ if part. starts_with ( expected) {
247
257
return
248
258
}
249
259
}
250
260
}
251
261
252
262
// Help debug by printing out the found disassembly, and then panic as we
253
263
// didn't find the instruction.
254
- println ! ( "disassembly for {}: " , sym) ;
264
+ println ! ( "disassembly for {}: " , sym. as_ref ( ) . unwrap ( ) ) ;
255
265
for ( i, instr) in function. instrs . iter ( ) . enumerate ( ) {
256
266
print ! ( "\t {:2}: " , i) ;
257
267
for part in instr. parts . iter ( ) {
@@ -261,4 +271,3 @@ pub fn assert(fnptr: usize, expected: &str) {
261
271
}
262
272
panic ! ( "failed to find instruction `{}` in the disassembly" , expected) ;
263
273
}
264
-
0 commit comments