Skip to content

Use --no-show-raw-insn to make disassemble parser simple. #948

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 6, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 3 additions & 9 deletions crates/stdarch-test/src/disassembly.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ pub(crate) fn disassemble_myself() -> HashSet<Function> {
let objdump = env::var("OBJDUMP").unwrap_or_else(|_| "objdump".to_string());
let output = Command::new(objdump.clone())
.arg("--disassemble")
.arg("--no-show-raw-insn")
.arg(&me)
.output()
.unwrap_or_else(|_| panic!("failed to execute objdump. OBJDUMP={}", objdump));
Expand Down Expand Up @@ -156,20 +157,13 @@ fn parse(output: &str) -> HashSet<Function> {
.skip_while(|s| *s == "lock") // skip x86-specific prefix
.collect::<Vec<String>>()
} else {
// objdump
// objdump with --no-show-raw-insn
// Each line of instructions should look like:
//
// $rel_offset: ab cd ef 00 $instruction...
let expected_len = if cfg!(target_arch = "arm") || cfg!(target_arch = "aarch64") {
8
} else {
2
};

// $rel_offset: $instruction...
instruction
.split_whitespace()
.skip(1)
.skip_while(|s| s.len() == expected_len && usize::from_str_radix(s, 16).is_ok())
.skip_while(|s| *s == "lock") // skip x86-specific prefix
.map(std::string::ToString::to_string)
.collect::<Vec<String>>()
Expand Down