Disassembler.h revision aa3e3e1f0f3be95c79f902c5331e11878f66b365
1//===-- Disassembler.h ------------------------------------------*- 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#ifndef liblldb_Disassembler_h_ 11#define liblldb_Disassembler_h_ 12 13// C Includes 14// C++ Includes 15#include <vector> 16 17// Other libraries and framework includes 18// Project includes 19#include "lldb/lldb-private.h" 20#include "lldb/Core/Address.h" 21#include "lldb/Core/ArchSpec.h" 22#include "lldb/Core/PluginInterface.h" 23 24namespace lldb_private { 25 26class Instruction 27{ 28public: 29 Instruction (const Address &addr); 30 31 virtual 32 ~Instruction(); 33 34 const Address & 35 GetAddress () const 36 { 37 return m_addr; 38 } 39 40 void 41 SetAddress (const Address &addr) 42 { 43 m_addr = addr; 44 } 45 46 virtual size_t 47 GetByteSize() const = 0; 48 49 50 virtual void 51 Dump (Stream *s, 52 bool show_address, 53 const DataExtractor *bytes, 54 uint32_t bytes_offset, 55 const ExecutionContext *exe_ctx, 56 bool raw) = 0; 57 58 virtual bool 59 DoesBranch () const = 0; 60 61 virtual size_t 62 Extract (const DataExtractor& data, uint32_t data_offset) = 0; 63 64protected: 65 Address m_addr; // The section offset address of this instruction 66}; 67 68 69class InstructionList 70{ 71public: 72 InstructionList(); 73 ~InstructionList(); 74 75 size_t 76 GetSize() const; 77 78 lldb::InstructionSP 79 GetInstructionAtIndex (uint32_t idx) const; 80 81 void 82 Clear(); 83 84 void 85 Append (lldb::InstructionSP &inst_sp); 86 87private: 88 typedef std::vector<lldb::InstructionSP> collection; 89 typedef collection::iterator iterator; 90 typedef collection::const_iterator const_iterator; 91 92 collection m_instructions; 93}; 94 95class Disassembler : 96 public PluginInterface 97{ 98public: 99 100 101 static Disassembler* 102 FindPlugin (const ArchSpec &arch); 103 104 static lldb::DisassemblerSP 105 DisassembleRange (const ArchSpec &arch, 106 const ExecutionContext &exe_ctx, 107 const AddressRange &disasm_range); 108 109 static bool 110 Disassemble (Debugger &debugger, 111 const ArchSpec &arch, 112 const ExecutionContext &exe_ctx, 113 const AddressRange &range, 114 uint32_t num_instructions, 115 uint32_t num_mixed_context_lines, 116 bool show_bytes, 117 bool raw, 118 Stream &strm); 119 120 static bool 121 Disassemble (Debugger &debugger, 122 const ArchSpec &arch, 123 const ExecutionContext &exe_ctx, 124 const Address &start, 125 uint32_t num_instructions, 126 uint32_t num_mixed_context_lines, 127 bool show_bytes, 128 bool raw, 129 Stream &strm); 130 131 static size_t 132 Disassemble (Debugger &debugger, 133 const ArchSpec &arch, 134 const ExecutionContext &exe_ctx, 135 SymbolContextList &sc_list, 136 uint32_t num_instructions, 137 uint32_t num_mixed_context_lines, 138 bool show_bytes, 139 bool raw, 140 Stream &strm); 141 142 static bool 143 Disassemble (Debugger &debugger, 144 const ArchSpec &arch, 145 const ExecutionContext &exe_ctx, 146 const ConstString &name, 147 Module *module, 148 uint32_t num_instructions, 149 uint32_t num_mixed_context_lines, 150 bool show_bytes, 151 bool raw, 152 Stream &strm); 153 154 static bool 155 Disassemble (Debugger &debugger, 156 const ArchSpec &arch, 157 const ExecutionContext &exe_ctx, 158 uint32_t num_instructions, 159 uint32_t num_mixed_context_lines, 160 bool show_bytes, 161 bool raw, 162 Stream &strm); 163 164 //------------------------------------------------------------------ 165 // Constructors and Destructors 166 //------------------------------------------------------------------ 167 Disassembler(const ArchSpec &arch); 168 virtual ~Disassembler(); 169 170 typedef const char * (*SummaryCallback)(const Instruction& inst, ExecutionContext *exe_context, void *user_data); 171 172 static bool 173 PrintInstructions (Disassembler *disasm_ptr, 174 DataExtractor &data, 175 Debugger &debugger, 176 const ArchSpec &arch, 177 const ExecutionContext &exe_ctx, 178 const Address &start_addr, 179 uint32_t num_instructions, 180 uint32_t num_mixed_context_lines, 181 bool show_bytes, 182 bool raw, 183 Stream &strm); 184 185 size_t 186 ParseInstructions (const ExecutionContext *exe_ctx, 187 const AddressRange &range, 188 DataExtractor& data); 189 190 size_t 191 ParseInstructions (const ExecutionContext *exe_ctx, 192 const Address &range, 193 uint32_t num_instructions, 194 DataExtractor& data); 195 196 virtual size_t 197 DecodeInstructions (const Address &base_addr, 198 const DataExtractor& data, 199 uint32_t data_offset, 200 uint32_t num_instructions, 201 bool append) = 0; 202 203 InstructionList & 204 GetInstructionList (); 205 206 const InstructionList & 207 GetInstructionList () const; 208 209protected: 210 //------------------------------------------------------------------ 211 // Classes that inherit from Disassembler can see and modify these 212 //------------------------------------------------------------------ 213 const ArchSpec m_arch; 214 InstructionList m_instruction_list; 215 lldb::addr_t m_base_addr; 216 217private: 218 //------------------------------------------------------------------ 219 // For Disassembler only 220 //------------------------------------------------------------------ 221 DISALLOW_COPY_AND_ASSIGN (Disassembler); 222}; 223 224} // namespace lldb_private 225 226#endif // liblldb_Disassembler_h_ 227