diff options
author | Greg Clayton <gclayton@apple.com> | 2010-10-06 03:09:58 +0000 |
---|---|---|
committer | Greg Clayton <gclayton@apple.com> | 2010-10-06 03:09:58 +0000 |
commit | 1d273166064c5163a1ca2be9a8e65cb628fc3524 (patch) | |
tree | 1471372d3bfb657f1e6820d0bc5aa13e33d13684 /lldb/source/Core/Disassembler.cpp | |
parent | 32c4085ba2d259ff9a4365b1962362248de2c655 (diff) | |
download | bcm5719-llvm-1d273166064c5163a1ca2be9a8e65cb628fc3524.tar.gz bcm5719-llvm-1d273166064c5163a1ca2be9a8e65cb628fc3524.zip |
Added the ability to get the disassembly instructions from the function and
symbol.
llvm-svn: 115734
Diffstat (limited to 'lldb/source/Core/Disassembler.cpp')
-rw-r--r-- | lldb/source/Core/Disassembler.cpp | 77 |
1 files changed, 48 insertions, 29 deletions
diff --git a/lldb/source/Core/Disassembler.cpp b/lldb/source/Core/Disassembler.cpp index c2d36ef5b16..65380493082 100644 --- a/lldb/source/Core/Disassembler.cpp +++ b/lldb/source/Core/Disassembler.cpp @@ -135,6 +135,32 @@ Disassembler::Disassemble return false; } + +lldb::DisassemblerSP +Disassembler::DisassembleRange +( + const ArchSpec &arch, + const ExecutionContext &exe_ctx, + const AddressRange &range +) +{ + lldb::DisassemblerSP disasm_sp; + if (range.GetByteSize() > 0 && range.GetBaseAddress().IsValid()) + { + disasm_sp.reset (Disassembler::FindPlugin(arch)); + + if (disasm_sp) + { + DataExtractor data; + size_t bytes_disassembled = disasm_sp->ParseInstructions (&exe_ctx, range, data); + if (bytes_disassembled == 0) + disasm_sp.reset(); + } + } + return disasm_sp; +} + + bool Disassembler::Disassemble ( @@ -149,9 +175,9 @@ Disassembler::Disassemble { if (disasm_range.GetByteSize()) { - Disassembler *disassembler = Disassembler::FindPlugin(arch); + std::auto_ptr<Disassembler> disasm_ap (Disassembler::FindPlugin(arch)); - if (disassembler) + if (disasm_ap.get()) { AddressRange range(disasm_range); @@ -175,7 +201,7 @@ Disassembler::Disassemble } DataExtractor data; - size_t bytes_disassembled = disassembler->ParseInstructions (&exe_ctx, range, data); + size_t bytes_disassembled = disasm_ap->ParseInstructions (&exe_ctx, range, data); if (bytes_disassembled == 0) { return false; @@ -183,7 +209,7 @@ Disassembler::Disassemble else { // We got some things disassembled... - size_t num_instructions = disassembler->GetInstructionList().GetSize(); + size_t num_instructions = disasm_ap->GetInstructionList().GetSize(); uint32_t offset = 0; SymbolContext sc; SymbolContext prev_sc; @@ -201,7 +227,7 @@ Disassembler::Disassemble for (size_t i=0; i<num_instructions; ++i) { - Disassembler::Instruction *inst = disassembler->GetInstructionList().GetInstructionAtIndex (i); + Instruction *inst = disasm_ap->GetInstructionList().GetInstructionAtIndex (i).get(); if (inst) { addr_t file_addr = addr.GetFileAddress(); @@ -270,7 +296,7 @@ Disassembler::Disassemble strm.IndentMore (); strm.Indent(); size_t inst_byte_size = inst->GetByteSize(); - inst->Dump(&strm, &addr, show_bytes ? &data : NULL, offset, exe_ctx, show_bytes); + inst->Dump(&strm, true, show_bytes ? &data : NULL, offset, &exe_ctx, show_bytes); strm.EOL(); offset += inst_byte_size; @@ -330,55 +356,49 @@ Disassembler::Disassemble return Disassemble(debugger, arch, exe_ctx, range, num_mixed_context_lines, show_bytes, strm); } -Disassembler::Instruction::Instruction() +Instruction::Instruction(const Address &addr) : + m_addr (addr) { } -Disassembler::Instruction::~Instruction() +Instruction::~Instruction() { } -Disassembler::InstructionList::InstructionList() : +InstructionList::InstructionList() : m_instructions() { } -Disassembler::InstructionList::~InstructionList() +InstructionList::~InstructionList() { } size_t -Disassembler::InstructionList::GetSize() const +InstructionList::GetSize() const { return m_instructions.size(); } -Disassembler::Instruction * -Disassembler::InstructionList::GetInstructionAtIndex (uint32_t idx) +InstructionSP +InstructionList::GetInstructionAtIndex (uint32_t idx) const { + InstructionSP inst_sp; if (idx < m_instructions.size()) - return m_instructions[idx].get(); - return NULL; -} - -const Disassembler::Instruction * -Disassembler::InstructionList::GetInstructionAtIndex (uint32_t idx) const -{ - if (idx < m_instructions.size()) - return m_instructions[idx].get(); - return NULL; + inst_sp = m_instructions[idx]; + return inst_sp; } void -Disassembler::InstructionList::Clear() +InstructionList::Clear() { m_instructions.clear(); } void -Disassembler::InstructionList::AppendInstruction (Instruction::shared_ptr &inst_sp) +InstructionList::Append (lldb::InstructionSP &inst_sp) { if (inst_sp) m_instructions.push_back(inst_sp); @@ -394,7 +414,6 @@ Disassembler::ParseInstructions ) { Target *target = exe_ctx->target; - const addr_t byte_size = range.GetByteSize(); if (target == NULL || byte_size == 0 || !range.GetBaseAddress().IsValid()) return 0; @@ -421,7 +440,7 @@ Disassembler::ParseInstructions data.SetByteOrder(target->GetArchitecture().GetDefaultEndian()); data.SetAddressByteSize(target->GetArchitecture().GetAddressByteSize()); } - return DecodeInstructions (data, 0, UINT32_MAX); + return DecodeInstructions (range.GetBaseAddress(), data, 0, UINT32_MAX); } return 0; @@ -445,13 +464,13 @@ Disassembler::~Disassembler() { } -Disassembler::InstructionList & +InstructionList & Disassembler::GetInstructionList () { return m_instruction_list; } -const Disassembler::InstructionList & +const InstructionList & Disassembler::GetInstructionList () const { return m_instruction_list; |