Skip to content

Commit d116aea

Browse files
committed
Help debug missing assembly
1 parent 2285f74 commit d116aea

File tree

3 files changed

+18
-10
lines changed

3 files changed

+18
-10
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ debug = true
1515
opt-level = 3
1616

1717
[profile.bench]
18-
debug = 1
18+
debug = true
1919
opt-level = 3
2020

2121
[dev-dependencies]

assert-instr/assert-instr-macro/src/lib.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,9 @@ pub fn assert_instr(attr: TokenStream, item: TokenStream) -> TokenStream {
4444
#[allow(non_snake_case)]
4545
{ignore}
4646
fn assert_instr_{name}() {{
47-
::assert_instr::assert({name} as usize, \"{instr}\");
47+
::assert_instr::assert({name} as usize,
48+
\"{name}\",
49+
\"{instr}\");
4850
}}
4951
", name = name.as_str(), instr = instr.as_str(), ignore = ignore);
5052
let test: TokenStream = test.parse().unwrap();

assert-instr/src/lib.rs

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -221,21 +221,28 @@ fn normalize(symbol: &str) -> String {
221221
///
222222
/// This asserts that the function at `fnptr` contains the instruction
223223
/// `expected` provided.
224-
pub fn assert(fnptr: usize, expected: &str) {
224+
pub fn assert(fnptr: usize, fnname: &str, expected: &str) {
225225
// Translate this function pointer to a symbolic name that we'd have found
226226
// in the disassembly.
227227
let mut sym = None;
228228
backtrace::resolve(fnptr as *mut _, |name| {
229229
sym = name.name().and_then(|s| s.as_str()).map(normalize);
230230
});
231-
let sym = match sym {
231+
232+
let functions = match sym.as_ref().and_then(|s| DISASSEMBLY.get(s)) {
232233
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+
}
234244
};
235245

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));
239246
assert_eq!(functions.len(), 1);
240247
let function = &functions[0];
241248

@@ -254,7 +261,7 @@ pub fn assert(fnptr: usize, expected: &str) {
254261

255262
// Help debug by printing out the found disassembly, and then panic as we
256263
// didn't find the instruction.
257-
println!("disassembly for {}: ", sym);
264+
println!("disassembly for {}: ", sym.as_ref().unwrap());
258265
for (i, instr) in function.instrs.iter().enumerate() {
259266
print!("\t{:2}: ", i);
260267
for part in instr.parts.iter() {
@@ -264,4 +271,3 @@ pub fn assert(fnptr: usize, expected: &str) {
264271
}
265272
panic!("failed to find instruction `{}` in the disassembly", expected);
266273
}
267-

0 commit comments

Comments
 (0)