Chris Lattner | 30fdc8d | 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 | 1d27316 | 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 | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 15 | |
| 16 | using namespace lldb; |
Greg Clayton | 1d27316 | 2010-10-06 03:09:58 +0000 | [diff] [blame] | 17 | using namespace lldb_private; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 18 | |
| 19 | |
Greg Clayton | 1d27316 | 2010-10-06 03:09:58 +0000 | [diff] [blame] | 20 | SBInstructionList::SBInstructionList () : |
| 21 | m_opaque_sp() |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 22 | { |
| 23 | } |
| 24 | |
Greg Clayton | efabb12 | 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 | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 39 | SBInstructionList::~SBInstructionList () |
| 40 | { |
| 41 | } |
| 42 | |
| 43 | size_t |
| 44 | SBInstructionList::GetSize () |
| 45 | { |
Greg Clayton | 1d27316 | 2010-10-06 03:09:58 +0000 | [diff] [blame] | 46 | if (m_opaque_sp) |
| 47 | return m_opaque_sp->GetInstructionList().GetSize(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 48 | return 0; |
| 49 | } |
| 50 | |
| 51 | SBInstruction |
| 52 | SBInstructionList::GetInstructionAtIndex (uint32_t idx) |
| 53 | { |
| 54 | SBInstruction inst; |
Greg Clayton | 1d27316 | 2010-10-06 03:09:58 +0000 | [diff] [blame] | 55 | if (m_opaque_sp && idx < m_opaque_sp->GetInstructionList().GetSize()) |
| 56 | inst.SetOpaque (m_opaque_sp->GetInstructionList().GetInstructionAtIndex (idx)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 57 | return inst; |
| 58 | } |
| 59 | |
| 60 | void |
| 61 | SBInstructionList::Clear () |
| 62 | { |
Greg Clayton | 1d27316 | 2010-10-06 03:09:58 +0000 | [diff] [blame] | 63 | m_opaque_sp.reset(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 64 | } |
| 65 | |
| 66 | void |
| 67 | SBInstructionList::AppendInstruction (SBInstruction insn) |
| 68 | { |
| 69 | } |
| 70 | |
| 71 | void |
Greg Clayton | 1d27316 | 2010-10-06 03:09:58 +0000 | [diff] [blame] | 72 | SBInstructionList::SetDisassembler (const lldb::DisassemblerSP &opaque_sp) |
| 73 | { |
| 74 | m_opaque_sp = opaque_sp; |
| 75 | } |
| 76 | |
| 77 | void |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 78 | SBInstructionList::Print (FILE *out) |
| 79 | { |
| 80 | if (out == NULL) |
| 81 | return; |
| 82 | } |
| 83 | |
Greg Clayton | 1d27316 | 2010-10-06 03:09:58 +0000 | [diff] [blame] | 84 | |
| 85 | bool |
| 86 | SBInstructionList::GetDescription (lldb::SBStream &description) |
| 87 | { |
| 88 | if (m_opaque_sp) |
| 89 | { |
| 90 | size_t num_instructions = GetSize (); |
| 91 | if (num_instructions) |
| 92 | { |
| 93 | // Call the ref() to make sure a stream is created if one deesn't |
| 94 | // exist already inside description... |
| 95 | Stream &sref = description.ref(); |
Greg Clayton | 357132e | 2011-03-26 19:14:58 +0000 | [diff] [blame] | 96 | const uint32_t max_opcode_byte_size = m_opaque_sp->GetInstructionList().GetMaxOpcocdeByteSize(); |
Greg Clayton | 1d27316 | 2010-10-06 03:09:58 +0000 | [diff] [blame] | 97 | for (size_t i=0; i<num_instructions; ++i) |
| 98 | { |
| 99 | Instruction *inst = m_opaque_sp->GetInstructionList().GetInstructionAtIndex (i).get(); |
| 100 | if (inst == NULL) |
| 101 | break; |
Greg Clayton | 357132e | 2011-03-26 19:14:58 +0000 | [diff] [blame] | 102 | inst->Dump (&sref, max_opcode_byte_size, true, false, NULL, false); |
Greg Clayton | 1d27316 | 2010-10-06 03:09:58 +0000 | [diff] [blame] | 103 | sref.EOL(); |
| 104 | } |
| 105 | return true; |
| 106 | } |
| 107 | } |
| 108 | return false; |
| 109 | } |
| 110 | |
| 111 | |
Caroline Tice | 7c9dd3c | 2011-04-05 23:22:54 +0000 | [diff] [blame^] | 112 | bool |
| 113 | SBInstructionList::DumpEmulationForAllInstructions (const char *triple) |
| 114 | { |
| 115 | if (m_opaque_sp) |
| 116 | { |
| 117 | size_t len = GetSize(); |
| 118 | for (size_t i = 0; i < len; ++i) |
| 119 | { |
| 120 | if (!GetInstructionAtIndex((uint32_t) i).DumpEmulation (triple)) |
| 121 | return false; |
| 122 | } |
| 123 | } |
| 124 | return true; |
| 125 | } |
| 126 | |