From 988c4f1de84ec3130ee329ae90a488ad3966bb48 Mon Sep 17 00:00:00 2001 From: Ryan Houdek Date: Fri, 7 Aug 2015 02:43:54 -0500 Subject: [PATCH] Have the disassembler show the PC next to host instructions. --- Source/Core/UICommon/Disassembler.cpp | 15 +++++++++------ Source/Core/UICommon/Disassembler.h | 2 +- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/Source/Core/UICommon/Disassembler.cpp b/Source/Core/UICommon/Disassembler.cpp index 479aebcb8a..22865a366e 100644 --- a/Source/Core/UICommon/Disassembler.cpp +++ b/Source/Core/UICommon/Disassembler.cpp @@ -24,7 +24,7 @@ public: private: disassembler m_disasm; - std::string DisassembleHostBlock(const u8* code_start, const u32 code_size, u32* host_instructions_count) override; + std::string DisassembleHostBlock(const u8* code_start, const u32 code_size, u32* host_instructions_count, u64 starting_pc) override; }; #if defined(HAS_LLVM) @@ -43,7 +43,7 @@ private: LLVMDisasmContextRef m_llvm_context; int m_instruction_size; - std::string DisassembleHostBlock(const u8* code_start, const u32 code_size, u32* host_instructions_count) override; + std::string DisassembleHostBlock(const u8* code_start, const u32 code_size, u32* host_instructions_count, u64 starting_pc) override; }; HostDisassemblerLLVM::HostDisassemblerLLVM(const std::string& host_disasm, int inst_size, const std::string& cpu) @@ -66,7 +66,7 @@ HostDisassemblerLLVM::HostDisassemblerLLVM(const std::string& host_disasm, int i m_can_disasm = true; } -std::string HostDisassemblerLLVM::DisassembleHostBlock(const u8* code_start, const u32 code_size, u32 *host_instructions_count) +std::string HostDisassemblerLLVM::DisassembleHostBlock(const u8* code_start, const u32 code_size, u32 *host_instructions_count, u64 starting_pc) { if (!m_can_disasm) return "(No LLVM context)"; @@ -78,7 +78,9 @@ std::string HostDisassemblerLLVM::DisassembleHostBlock(const u8* code_start, con while ((u8*)disasmPtr < end) { char inst_disasm[256]; - size_t inst_size = LLVMDisasmInstruction(m_llvm_context, disasmPtr, (u64)(end - disasmPtr), (u64)disasmPtr, inst_disasm, 256); + size_t inst_size = LLVMDisasmInstruction(m_llvm_context, disasmPtr, (u64)(end - disasmPtr), starting_pc, inst_disasm, 256); + + x86_disasm << "0x" << std::hex << starting_pc << "\t"; if (!inst_size) { x86_disasm << "Invalid inst:"; @@ -110,6 +112,7 @@ std::string HostDisassemblerLLVM::DisassembleHostBlock(const u8* code_start, con { x86_disasm << inst_disasm << std::endl; disasmPtr += inst_size; + starting_pc += inst_size; } (*host_instructions_count)++; @@ -124,7 +127,7 @@ HostDisassemblerX86::HostDisassemblerX86() m_disasm.set_syntax_intel(); } -std::string HostDisassemblerX86::DisassembleHostBlock(const u8* code_start, const u32 code_size, u32* host_instructions_count) +std::string HostDisassemblerX86::DisassembleHostBlock(const u8* code_start, const u32 code_size, u32* host_instructions_count, u64 starting_pc) { u64 disasmPtr = (u64)code_start; const u8* end = code_start + code_size; @@ -172,5 +175,5 @@ std::string DisassembleBlock(HostDisassembler* disasm, u32* address, u32* host_i host_instructions_count = 0; return "(No translation)"; } - return disasm->DisassembleHostBlock(code, *code_size, host_instructions_count); + return disasm->DisassembleHostBlock(code, *code_size, host_instructions_count, (u64)code); } diff --git a/Source/Core/UICommon/Disassembler.h b/Source/Core/UICommon/Disassembler.h index af3cf6f388..2dcb9757d2 100644 --- a/Source/Core/UICommon/Disassembler.h +++ b/Source/Core/UICommon/Disassembler.h @@ -10,7 +10,7 @@ class HostDisassembler { public: virtual ~HostDisassembler() {} - virtual std::string DisassembleHostBlock(const u8* code_start, const u32 code_size, u32* host_instructions_count) { return "(No disassembler)"; } + virtual std::string DisassembleHostBlock(const u8* code_start, const u32 code_size, u32* host_instructions_count, u64 starting_pc) { return "(No disassembler)"; } }; HostDisassembler* GetNewDisassembler(const std::string& arch);