1 //===-- SBInstructionList.cpp -----------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "lldb/API/SBInstructionList.h"
11 #include "lldb/API/SBInstruction.h"
12 #include "lldb/API/SBAddress.h"
13 #include "lldb/API/SBStream.h"
14 #include "lldb/Core/Disassembler.h"
15 #include "lldb/Core/Module.h"
16 #include "lldb/Symbol/SymbolContext.h"
17 #include "lldb/Utility/Stream.h"
20 using namespace lldb_private;
22 SBInstructionList::SBInstructionList() : m_opaque_sp() {}
24 SBInstructionList::SBInstructionList(const SBInstructionList &rhs)
25 : m_opaque_sp(rhs.m_opaque_sp) {}
27 const SBInstructionList &SBInstructionList::
28 operator=(const SBInstructionList &rhs) {
30 m_opaque_sp = rhs.m_opaque_sp;
34 SBInstructionList::~SBInstructionList() {}
36 bool SBInstructionList::IsValid() const { return m_opaque_sp.get() != NULL; }
38 size_t SBInstructionList::GetSize() {
40 return m_opaque_sp->GetInstructionList().GetSize();
44 SBInstruction SBInstructionList::GetInstructionAtIndex(uint32_t idx) {
46 if (m_opaque_sp && idx < m_opaque_sp->GetInstructionList().GetSize())
49 m_opaque_sp->GetInstructionList().GetInstructionAtIndex(idx));
53 size_t SBInstructionList::GetInstructionsCount(const SBAddress &start,
55 bool canSetBreakpoint) {
56 size_t num_instructions = GetSize();
59 size_t lower_index = 0;
60 size_t upper_index = 0;
61 size_t instructions_to_skip = 0;
62 for (i = 0; i < num_instructions; ++i) {
63 addr = GetInstructionAtIndex(i).GetAddress();
70 for (i = lower_index; i <= upper_index; ++i) {
71 SBInstruction insn = GetInstructionAtIndex(i);
72 if (!insn.CanSetBreakpoint())
73 ++instructions_to_skip;
75 return upper_index - lower_index - instructions_to_skip;
78 void SBInstructionList::Clear() { m_opaque_sp.reset(); }
80 void SBInstructionList::AppendInstruction(SBInstruction insn) {}
82 void SBInstructionList::SetDisassembler(const lldb::DisassemblerSP &opaque_sp) {
83 m_opaque_sp = opaque_sp;
86 void SBInstructionList::Print(FILE *out) {
91 bool SBInstructionList::GetDescription(lldb::SBStream &description) {
93 size_t num_instructions = GetSize();
94 if (num_instructions) {
95 // Call the ref() to make sure a stream is created if one deesn't
96 // exist already inside description...
97 Stream &sref = description.ref();
98 const uint32_t max_opcode_byte_size =
99 m_opaque_sp->GetInstructionList().GetMaxOpcocdeByteSize();
100 FormatEntity::Entry format;
101 FormatEntity::Parse("${addr}: ", format);
103 SymbolContext prev_sc;
104 for (size_t i = 0; i < num_instructions; ++i) {
106 m_opaque_sp->GetInstructionList().GetInstructionAtIndex(i).get();
110 const Address &addr = inst->GetAddress();
112 ModuleSP module_sp(addr.GetModule());
114 module_sp->ResolveSymbolContextForAddress(
115 addr, eSymbolContextEverything, sc);
118 inst->Dump(&sref, max_opcode_byte_size, true, false, NULL, &sc,
119 &prev_sc, &format, 0);
128 bool SBInstructionList::DumpEmulationForAllInstructions(const char *triple) {
130 size_t len = GetSize();
131 for (size_t i = 0; i < len; ++i) {
132 if (!GetInstructionAtIndex((uint32_t)i).DumpEmulation(triple))