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/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"
19 using namespace lldb_private;
21 SBInstructionList::SBInstructionList() : m_opaque_sp() {}
23 SBInstructionList::SBInstructionList(const SBInstructionList &rhs)
24 : m_opaque_sp(rhs.m_opaque_sp) {}
26 const SBInstructionList &SBInstructionList::
27 operator=(const SBInstructionList &rhs) {
29 m_opaque_sp = rhs.m_opaque_sp;
33 SBInstructionList::~SBInstructionList() {}
35 bool SBInstructionList::IsValid() const { return m_opaque_sp.get() != NULL; }
37 size_t SBInstructionList::GetSize() {
39 return m_opaque_sp->GetInstructionList().GetSize();
43 SBInstruction SBInstructionList::GetInstructionAtIndex(uint32_t idx) {
45 if (m_opaque_sp && idx < m_opaque_sp->GetInstructionList().GetSize())
48 m_opaque_sp->GetInstructionList().GetInstructionAtIndex(idx));
52 void SBInstructionList::Clear() { m_opaque_sp.reset(); }
54 void SBInstructionList::AppendInstruction(SBInstruction insn) {}
56 void SBInstructionList::SetDisassembler(const lldb::DisassemblerSP &opaque_sp) {
57 m_opaque_sp = opaque_sp;
60 void SBInstructionList::Print(FILE *out) {
65 bool SBInstructionList::GetDescription(lldb::SBStream &description) {
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);
77 SymbolContext prev_sc;
78 for (size_t i = 0; i < num_instructions; ++i) {
80 m_opaque_sp->GetInstructionList().GetInstructionAtIndex(i).get();
84 const Address &addr = inst->GetAddress();
86 ModuleSP module_sp(addr.GetModule());
88 module_sp->ResolveSymbolContextForAddress(
89 addr, eSymbolContextEverything, sc);
92 inst->Dump(&sref, max_opcode_byte_size, true, false, NULL, &sc,
93 &prev_sc, &format, 0);
102 bool SBInstructionList::DumpEmulationForAllInstructions(const char *triple) {
104 size_t len = GetSize();
105 for (size_t i = 0; i < len; ++i) {
106 if (!GetInstructionAtIndex((uint32_t)i).DumpEmulation(triple))