Obtains the assembly text for a given symbol diff, suitable for copying to clipboard.
(
obj: &Object,
symbol_diff: &SymbolDiff,
symbol_idx: usize,
diff_config: &DiffObjConfig,
)
| 72 | |
| 73 | /// Obtains the assembly text for a given symbol diff, suitable for copying to clipboard. |
| 74 | fn get_asm_text( |
| 75 | obj: &Object, |
| 76 | symbol_diff: &SymbolDiff, |
| 77 | symbol_idx: usize, |
| 78 | diff_config: &DiffObjConfig, |
| 79 | ) -> String { |
| 80 | let mut asm_text = String::new(); |
| 81 | |
| 82 | for ins_row in &symbol_diff.instruction_rows { |
| 83 | let mut line = String::new(); |
| 84 | let result = display_row(obj, symbol_idx, ins_row, diff_config, |segment| { |
| 85 | let text = match segment.text { |
| 86 | DiffText::Basic(text) => text.to_string(), |
| 87 | DiffText::Line(num) => format!("{num} "), |
| 88 | DiffText::Address(addr) => format!("{addr:x}:"), |
| 89 | DiffText::Opcode(mnemonic, _op) => format!("{mnemonic} "), |
| 90 | DiffText::Argument(arg) => match arg { |
| 91 | InstructionArgValue::Signed(v) => format!("{:#x}", ReallySigned(v)), |
| 92 | InstructionArgValue::Unsigned(v) => format!("{v:#x}"), |
| 93 | InstructionArgValue::Opaque(v) => v.into_owned(), |
| 94 | }, |
| 95 | DiffText::BranchDest(addr) => format!("{addr:x}"), |
| 96 | DiffText::BranchArrow(_) => " ~> ".to_string(), |
| 97 | DiffText::Symbol(sym) => sym.demangled_name.as_ref().unwrap_or(&sym.name).clone(), |
| 98 | DiffText::Addend(addend) => match addend.cmp(&0i64) { |
| 99 | Ordering::Greater => format!("+{addend:#x}"), |
| 100 | Ordering::Less => format!("-{:#x}", -addend), |
| 101 | _ => String::new(), |
| 102 | }, |
| 103 | DiffText::Spacing(n) => " ".repeat(n.into()), |
| 104 | DiffText::Eol => "\n".to_string(), |
| 105 | }; |
| 106 | line.push_str(&text); |
| 107 | Ok(()) |
| 108 | }); |
| 109 | |
| 110 | if result.is_ok() { |
| 111 | asm_text.push_str(line.trim_end()); |
| 112 | asm_text.push('\n'); |
| 113 | } |
| 114 | } |
| 115 | |
| 116 | asm_text |
| 117 | } |
| 118 | |
| 119 | #[must_use] |
| 120 | pub fn diff_view_ui( |
no test coverage detected