Disassembler.h revision 24943d2ee8bfaa7cf5893e4709143924157a5c1e
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/ArchSpec.h"
21#include "lldb/Core/PluginInterface.h"
22
23namespace lldb_private {
24
25class ExecutionContext;
26
27class Disassembler :
28    public PluginInterface
29{
30public:
31    class Instruction
32    {
33    public:
34        typedef lldb::SharedPtr<Instruction>::Type shared_ptr;
35
36        Instruction();
37
38        virtual
39       ~Instruction();
40
41        virtual size_t
42        GetByteSize() const = 0;
43
44        virtual void
45        Dump (Stream *s, lldb::addr_t base_address, DataExtractor *bytes, uint32_t bytes_offset, const lldb_private::ExecutionContext exe_ctx, bool raw) = 0;
46
47        virtual bool
48        DoesBranch () const = 0;
49
50        virtual size_t
51        Extract (const DataExtractor& data, uint32_t data_offset) = 0;
52    };
53
54
55    class InstructionList
56    {
57    public:
58        InstructionList();
59        ~InstructionList();
60
61        size_t
62        GetSize() const;
63
64        Instruction *
65        GetInstructionAtIndex (uint32_t idx);
66
67        const Instruction *
68        GetInstructionAtIndex (uint32_t idx) const;
69
70    void
71    Clear();
72
73    void
74    AppendInstruction (Instruction::shared_ptr &inst_sp);
75
76    private:
77        typedef std::vector<Instruction::shared_ptr> collection;
78        typedef collection::iterator iterator;
79        typedef collection::const_iterator const_iterator;
80
81        collection m_instructions;
82    };
83
84
85    static Disassembler*
86    FindPlugin (const ArchSpec &arch);
87
88    static bool
89    Disassemble (const ArchSpec &arch,
90                 const ExecutionContext &exe_ctx,
91                 uint32_t mixed_context_lines,
92                 Stream &strm);
93
94    //------------------------------------------------------------------
95    // Constructors and Destructors
96    //------------------------------------------------------------------
97    Disassembler(const ArchSpec &arch);
98    virtual ~Disassembler();
99
100    typedef const char * (*SummaryCallback)(const Instruction& inst, ExecutionContext *exe_context, void *user_data);
101
102    size_t
103    ParseInstructions (const ExecutionContext *exe_ctx,
104                       lldb::AddressType addr_type,
105                       lldb::addr_t addr,
106                       size_t byte_size,
107                       DataExtractor& data);
108
109    virtual size_t
110    ParseInstructions (const DataExtractor& data,
111                       uint32_t data_offset,
112                       uint32_t num_instructions,
113                       lldb::addr_t base_addr) = 0;
114
115    InstructionList &
116    GetInstructionList ();
117
118    const InstructionList &
119    GetInstructionList () const;
120
121protected:
122    //------------------------------------------------------------------
123    // Classes that inherit from Disassembler can see and modify these
124    //------------------------------------------------------------------
125    const ArchSpec m_arch;
126    InstructionList m_instruction_list;
127    lldb::addr_t m_base_addr;
128
129private:
130    //------------------------------------------------------------------
131    // For Disassembler only
132    //------------------------------------------------------------------
133    DISALLOW_COPY_AND_ASSIGN (Disassembler);
134};
135
136} // namespace lldb_private
137
138#endif  // liblldb_Disassembler_h_
139