Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 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" |
Greg Clayton | 5c4c746 | 2010-10-06 03:09:58 +0000 | [diff] [blame] | 12 | #include "lldb/API/SBStream.h" |
| 13 | #include "lldb/Core/Disassembler.h" |
| 14 | #include "lldb/Core/Stream.h" |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 15 | |
| 16 | using namespace lldb; |
Greg Clayton | 5c4c746 | 2010-10-06 03:09:58 +0000 | [diff] [blame] | 17 | using namespace lldb_private; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 18 | |
| 19 | |
Greg Clayton | 5c4c746 | 2010-10-06 03:09:58 +0000 | [diff] [blame] | 20 | SBInstructionList::SBInstructionList () : |
| 21 | m_opaque_sp() |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 22 | { |
| 23 | } |
| 24 | |
Greg Clayton | 538eb82 | 2010-11-05 23:17:00 +0000 | [diff] [blame] | 25 | SBInstructionList::SBInstructionList(const SBInstructionList &rhs) : |
| 26 | m_opaque_sp (rhs.m_opaque_sp) |
| 27 | { |
| 28 | } |
| 29 | |
| 30 | const SBInstructionList & |
| 31 | SBInstructionList::operator = (const SBInstructionList &rhs) |
| 32 | { |
| 33 | if (this != &rhs) |
| 34 | m_opaque_sp = rhs.m_opaque_sp; |
| 35 | return *this; |
| 36 | } |
| 37 | |
| 38 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 39 | SBInstructionList::~SBInstructionList () |
| 40 | { |
| 41 | } |
| 42 | |
Johnny Chen | d2554b5 | 2011-06-20 22:30:48 +0000 | [diff] [blame] | 43 | bool |
| 44 | SBInstructionList::IsValid () const |
| 45 | { |
| 46 | return m_opaque_sp.get() != NULL; |
| 47 | } |
| 48 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 49 | size_t |
| 50 | SBInstructionList::GetSize () |
| 51 | { |
Greg Clayton | 5c4c746 | 2010-10-06 03:09:58 +0000 | [diff] [blame] | 52 | if (m_opaque_sp) |
| 53 | return m_opaque_sp->GetInstructionList().GetSize(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 54 | return 0; |
| 55 | } |
| 56 | |
| 57 | SBInstruction |
| 58 | SBInstructionList::GetInstructionAtIndex (uint32_t idx) |
| 59 | { |
| 60 | SBInstruction inst; |
Greg Clayton | 5c4c746 | 2010-10-06 03:09:58 +0000 | [diff] [blame] | 61 | if (m_opaque_sp && idx < m_opaque_sp->GetInstructionList().GetSize()) |
| 62 | inst.SetOpaque (m_opaque_sp->GetInstructionList().GetInstructionAtIndex (idx)); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 63 | return inst; |
| 64 | } |
| 65 | |
| 66 | void |
| 67 | SBInstructionList::Clear () |
| 68 | { |
Greg Clayton | 5c4c746 | 2010-10-06 03:09:58 +0000 | [diff] [blame] | 69 | m_opaque_sp.reset(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 70 | } |
| 71 | |
| 72 | void |
| 73 | SBInstructionList::AppendInstruction (SBInstruction insn) |
| 74 | { |
| 75 | } |
| 76 | |
| 77 | void |
Greg Clayton | 5c4c746 | 2010-10-06 03:09:58 +0000 | [diff] [blame] | 78 | SBInstructionList::SetDisassembler (const lldb::DisassemblerSP &opaque_sp) |
| 79 | { |
| 80 | m_opaque_sp = opaque_sp; |
| 81 | } |
| 82 | |
| 83 | void |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 84 | SBInstructionList::Print (FILE *out) |
| 85 | { |
| 86 | if (out == NULL) |
| 87 | return; |
| 88 | } |
| 89 | |
Greg Clayton | 5c4c746 | 2010-10-06 03:09:58 +0000 | [diff] [blame] | 90 | |
| 91 | bool |
| 92 | SBInstructionList::GetDescription (lldb::SBStream &description) |
| 93 | { |
| 94 | if (m_opaque_sp) |
| 95 | { |
| 96 | size_t num_instructions = GetSize (); |
| 97 | if (num_instructions) |
| 98 | { |
| 99 | // Call the ref() to make sure a stream is created if one deesn't |
| 100 | // exist already inside description... |
| 101 | Stream &sref = description.ref(); |
Greg Clayton | 889fbd0 | 2011-03-26 19:14:58 +0000 | [diff] [blame] | 102 | const uint32_t max_opcode_byte_size = m_opaque_sp->GetInstructionList().GetMaxOpcocdeByteSize(); |
Greg Clayton | 5c4c746 | 2010-10-06 03:09:58 +0000 | [diff] [blame] | 103 | for (size_t i=0; i<num_instructions; ++i) |
| 104 | { |
| 105 | Instruction *inst = m_opaque_sp->GetInstructionList().GetInstructionAtIndex (i).get(); |
| 106 | if (inst == NULL) |
| 107 | break; |
Greg Clayton | 0fef968 | 2012-05-10 02:52:23 +0000 | [diff] [blame] | 108 | inst->Dump (&sref, max_opcode_byte_size, true, false, NULL); |
Greg Clayton | 5c4c746 | 2010-10-06 03:09:58 +0000 | [diff] [blame] | 109 | sref.EOL(); |
| 110 | } |
| 111 | return true; |
| 112 | } |
| 113 | } |
| 114 | return false; |
| 115 | } |
| 116 | |
| 117 | |
Caroline Tice | af59180 | 2011-04-05 23:22:54 +0000 | [diff] [blame] | 118 | bool |
| 119 | SBInstructionList::DumpEmulationForAllInstructions (const char *triple) |
| 120 | { |
| 121 | if (m_opaque_sp) |
| 122 | { |
| 123 | size_t len = GetSize(); |
| 124 | for (size_t i = 0; i < len; ++i) |
| 125 | { |
| 126 | if (!GetInstructionAtIndex((uint32_t) i).DumpEmulation (triple)) |
| 127 | return false; |
| 128 | } |
| 129 | } |
| 130 | return true; |
| 131 | } |
| 132 | |