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/Stream.h" 15 16 using namespace lldb; 17 using namespace lldb_private; 18 19 20 SBInstructionList::SBInstructionList () : 21 m_opaque_sp() 22 { 23 } 24 25 SBInstructionList::~SBInstructionList () 26 { 27 } 28 29 size_t 30 SBInstructionList::GetSize () 31 { 32 if (m_opaque_sp) 33 return m_opaque_sp->GetInstructionList().GetSize(); 34 return 0; 35 } 36 37 SBInstruction 38 SBInstructionList::GetInstructionAtIndex (uint32_t idx) 39 { 40 SBInstruction inst; 41 if (m_opaque_sp && idx < m_opaque_sp->GetInstructionList().GetSize()) 42 inst.SetOpaque (m_opaque_sp->GetInstructionList().GetInstructionAtIndex (idx)); 43 return inst; 44 } 45 46 void 47 SBInstructionList::Clear () 48 { 49 m_opaque_sp.reset(); 50 } 51 52 void 53 SBInstructionList::AppendInstruction (SBInstruction insn) 54 { 55 } 56 57 void 58 SBInstructionList::SetDisassembler (const lldb::DisassemblerSP &opaque_sp) 59 { 60 m_opaque_sp = opaque_sp; 61 } 62 63 void 64 SBInstructionList::Print (FILE *out) 65 { 66 if (out == NULL) 67 return; 68 } 69 70 71 bool 72 SBInstructionList::GetDescription (lldb::SBStream &description) 73 { 74 if (m_opaque_sp) 75 { 76 size_t num_instructions = GetSize (); 77 if (num_instructions) 78 { 79 // Call the ref() to make sure a stream is created if one deesn't 80 // exist already inside description... 81 Stream &sref = description.ref(); 82 for (size_t i=0; i<num_instructions; ++i) 83 { 84 Instruction *inst = m_opaque_sp->GetInstructionList().GetInstructionAtIndex (i).get(); 85 if (inst == NULL) 86 break; 87 inst->Dump (&sref, true, NULL, 0, NULL, false); 88 sref.EOL(); 89 } 90 return true; 91 } 92 } 93 return false; 94 } 95 96 97