Disassembler.h revision 5c4c746a3a83c1aad411c6cdc5f9525a4fc2d17e
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_mixed_context_lines,
115                 bool show_bytes,
116                 Stream &strm);
117
118    static size_t
119    Disassemble (Debugger &debugger,
120                 const ArchSpec &arch,
121                 const ExecutionContext &exe_ctx,
122                 SymbolContextList &sc_list,
123                 uint32_t num_mixed_context_lines,
124                 bool show_bytes,
125                 Stream &strm);
126
127    static bool
128    Disassemble (Debugger &debugger,
129                 const ArchSpec &arch,
130                 const ExecutionContext &exe_ctx,
131                 const ConstString &name,
132                 Module *module,
133                 uint32_t num_mixed_context_lines,
134                 bool show_bytes,
135                 Stream &strm);
136
137    static bool
138    Disassemble (Debugger &debugger,
139                 const ArchSpec &arch,
140                 const ExecutionContext &exe_ctx,
141                 uint32_t num_mixed_context_lines,
142                 bool show_bytes,
143                 Stream &strm);
144
145    //------------------------------------------------------------------
146    // Constructors and Destructors
147    //------------------------------------------------------------------
148    Disassembler(const ArchSpec &arch);
149    virtual ~Disassembler();
150
151    typedef const char * (*SummaryCallback)(const Instruction& inst, ExecutionContext *exe_context, void *user_data);
152
153    size_t
154    ParseInstructions (const ExecutionContext *exe_ctx,
155                       const AddressRange &range,
156                       DataExtractor& data);
157
158    virtual size_t
159    DecodeInstructions (const Address &base_addr,
160                        const DataExtractor& data,
161                        uint32_t data_offset,
162                        uint32_t num_instructions) = 0;
163
164    InstructionList &
165    GetInstructionList ();
166
167    const InstructionList &
168    GetInstructionList () const;
169
170protected:
171    //------------------------------------------------------------------
172    // Classes that inherit from Disassembler can see and modify these
173    //------------------------------------------------------------------
174    const ArchSpec m_arch;
175    InstructionList m_instruction_list;
176    lldb::addr_t m_base_addr;
177
178private:
179    //------------------------------------------------------------------
180    // For Disassembler only
181    //------------------------------------------------------------------
182    DISALLOW_COPY_AND_ASSIGN (Disassembler);
183};
184
185} // namespace lldb_private
186
187#endif  // liblldb_Disassembler_h_
188