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 22 SBInstructionList::SBInstructionList () : 23 m_opaque_sp() 24 { 25 } 26 27 SBInstructionList::SBInstructionList(const SBInstructionList &rhs) : 28 m_opaque_sp (rhs.m_opaque_sp) 29 { 30 } 31 32 const SBInstructionList & 33 SBInstructionList::operator = (const SBInstructionList &rhs) 34 { 35 if (this != &rhs) 36 m_opaque_sp = rhs.m_opaque_sp; 37 return *this; 38 } 39 40 41 SBInstructionList::~SBInstructionList () 42 { 43 } 44 45 bool 46 SBInstructionList::IsValid () const 47 { 48 return m_opaque_sp.get() != NULL; 49 } 50 51 size_t 52 SBInstructionList::GetSize () 53 { 54 if (m_opaque_sp) 55 return m_opaque_sp->GetInstructionList().GetSize(); 56 return 0; 57 } 58 59 SBInstruction 60 SBInstructionList::GetInstructionAtIndex (uint32_t idx) 61 { 62 SBInstruction inst; 63 if (m_opaque_sp && idx < m_opaque_sp->GetInstructionList().GetSize()) 64 inst.SetOpaque (m_opaque_sp->GetInstructionList().GetInstructionAtIndex (idx)); 65 return inst; 66 } 67 68 void 69 SBInstructionList::Clear () 70 { 71 m_opaque_sp.reset(); 72 } 73 74 void 75 SBInstructionList::AppendInstruction (SBInstruction insn) 76 { 77 } 78 79 void 80 SBInstructionList::SetDisassembler (const lldb::DisassemblerSP &opaque_sp) 81 { 82 m_opaque_sp = opaque_sp; 83 } 84 85 void 86 SBInstructionList::Print (FILE *out) 87 { 88 if (out == NULL) 89 return; 90 } 91 92 93 bool 94 SBInstructionList::GetDescription (lldb::SBStream &description) 95 { 96 if (m_opaque_sp) 97 { 98 size_t num_instructions = GetSize (); 99 if (num_instructions) 100 { 101 // Call the ref() to make sure a stream is created if one deesn't 102 // exist already inside description... 103 Stream &sref = description.ref(); 104 const uint32_t max_opcode_byte_size = m_opaque_sp->GetInstructionList().GetMaxOpcocdeByteSize(); 105 const char *disassemble_format = "${addr-file-or-load}: "; 106 SymbolContext sc; 107 SymbolContext prev_sc; 108 for (size_t i=0; i<num_instructions; ++i) 109 { 110 Instruction *inst = m_opaque_sp->GetInstructionList().GetInstructionAtIndex (i).get(); 111 if (inst == NULL) 112 break; 113 114 const Address &addr = inst->GetAddress(); 115 prev_sc = sc; 116 ModuleSP module_sp (addr.GetModule()); 117 if (module_sp) 118 { 119 module_sp->ResolveSymbolContextForAddress(addr, eSymbolContextEverything, sc); 120 } 121 122 inst->Dump (&sref, max_opcode_byte_size, true, false, NULL, &sc, &prev_sc, disassemble_format); 123 sref.EOL(); 124 } 125 return true; 126 } 127 } 128 return false; 129 } 130 131 132 bool 133 SBInstructionList::DumpEmulationForAllInstructions (const char *triple) 134 { 135 if (m_opaque_sp) 136 { 137 size_t len = GetSize(); 138 for (size_t i = 0; i < len; ++i) 139 { 140 if (!GetInstructionAtIndex((uint32_t) i).DumpEmulation (triple)) 141 return false; 142 } 143 } 144 return true; 145 } 146 147