1 //===-- SBInstructionList.cpp -----------------------------------*- C++ -*-===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 10 #include "lldb/API/SBInstructionList.h" 11 #include "lldb/API/SBInstruction.h" 12 #include "lldb/API/SBStream.h" 13 #include "lldb/Core/Disassembler.h" 14 #include "lldb/Core/Module.h" 15 #include "lldb/Core/Stream.h" 16 #include "lldb/Symbol/SymbolContext.h" 17 18 using namespace lldb; 19 using namespace lldb_private; 20 21 SBInstructionList::SBInstructionList() : m_opaque_sp() {} 22 23 SBInstructionList::SBInstructionList(const SBInstructionList &rhs) 24 : m_opaque_sp(rhs.m_opaque_sp) {} 25 26 const SBInstructionList &SBInstructionList:: 27 operator=(const SBInstructionList &rhs) { 28 if (this != &rhs) 29 m_opaque_sp = rhs.m_opaque_sp; 30 return *this; 31 } 32 33 SBInstructionList::~SBInstructionList() {} 34 35 bool SBInstructionList::IsValid() const { return m_opaque_sp.get() != NULL; } 36 37 size_t SBInstructionList::GetSize() { 38 if (m_opaque_sp) 39 return m_opaque_sp->GetInstructionList().GetSize(); 40 return 0; 41 } 42 43 SBInstruction SBInstructionList::GetInstructionAtIndex(uint32_t idx) { 44 SBInstruction inst; 45 if (m_opaque_sp && idx < m_opaque_sp->GetInstructionList().GetSize()) 46 inst.SetOpaque( 47 m_opaque_sp, 48 m_opaque_sp->GetInstructionList().GetInstructionAtIndex(idx)); 49 return inst; 50 } 51 52 void SBInstructionList::Clear() { m_opaque_sp.reset(); } 53 54 void SBInstructionList::AppendInstruction(SBInstruction insn) {} 55 56 void SBInstructionList::SetDisassembler(const lldb::DisassemblerSP &opaque_sp) { 57 m_opaque_sp = opaque_sp; 58 } 59 60 void SBInstructionList::Print(FILE *out) { 61 if (out == NULL) 62 return; 63 } 64 65 bool SBInstructionList::GetDescription(lldb::SBStream &description) { 66 if (m_opaque_sp) { 67 size_t num_instructions = GetSize(); 68 if (num_instructions) { 69 // Call the ref() to make sure a stream is created if one deesn't 70 // exist already inside description... 71 Stream &sref = description.ref(); 72 const uint32_t max_opcode_byte_size = 73 m_opaque_sp->GetInstructionList().GetMaxOpcocdeByteSize(); 74 FormatEntity::Entry format; 75 FormatEntity::Parse("${addr}: ", format); 76 SymbolContext sc; 77 SymbolContext prev_sc; 78 for (size_t i = 0; i < num_instructions; ++i) { 79 Instruction *inst = 80 m_opaque_sp->GetInstructionList().GetInstructionAtIndex(i).get(); 81 if (inst == NULL) 82 break; 83 84 const Address &addr = inst->GetAddress(); 85 prev_sc = sc; 86 ModuleSP module_sp(addr.GetModule()); 87 if (module_sp) { 88 module_sp->ResolveSymbolContextForAddress( 89 addr, eSymbolContextEverything, sc); 90 } 91 92 inst->Dump(&sref, max_opcode_byte_size, true, false, NULL, &sc, 93 &prev_sc, &format, 0); 94 sref.EOL(); 95 } 96 return true; 97 } 98 } 99 return false; 100 } 101 102 bool SBInstructionList::DumpEmulationForAllInstructions(const char *triple) { 103 if (m_opaque_sp) { 104 size_t len = GetSize(); 105 for (size_t i = 0; i < len; ++i) { 106 if (!GetInstructionAtIndex((uint32_t)i).DumpEmulation(triple)) 107 return false; 108 } 109 } 110 return true; 111 } 112