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