blob: c6c3e6652bb6b1192c3f6c49507b15fbf665a6dd [file] [log] [blame]
Sean Callanan95e5c632012-02-17 00:53:45 +00001//===-- DisassemblerLLVMC.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_DisassemblerLLVMC_h_
11#define liblldb_DisassemblerLLVMC_h_
12
13
14#include "llvm-c/Disassembler.h"
15
16#include "lldb/Core/Address.h"
17#include "lldb/Core/Disassembler.h"
18#include "lldb/Core/PluginManager.h"
19#include "lldb/Host/Mutex.h"
20
21class InstructionLLVMC;
22
23class DisassemblerLLVMC : public lldb_private::Disassembler
24{
25public:
26 //------------------------------------------------------------------
27 // Static Functions
28 //------------------------------------------------------------------
29 static void
30 Initialize();
31
32 static void
33 Terminate();
34
35 static const char *
36 GetPluginNameStatic();
37
38 static const char *
39 GetPluginDescriptionStatic();
40
41 static lldb_private::Disassembler *
42 CreateInstance(const lldb_private::ArchSpec &arch);
43
44
45 DisassemblerLLVMC(const lldb_private::ArchSpec &arch);
46
47 virtual
48 ~DisassemblerLLVMC();
49
50 size_t
51 DecodeInstructions (const lldb_private::Address &base_addr,
52 const lldb_private::DataExtractor& data,
Greg Claytonc7bece562013-01-25 18:06:21 +000053 lldb::offset_t data_offset,
54 size_t num_instructions,
Sean Callanan95e5c632012-02-17 00:53:45 +000055 bool append);
56
57 //------------------------------------------------------------------
58 // PluginInterface protocol
59 //------------------------------------------------------------------
60 virtual const char *
61 GetPluginName();
62
63 virtual const char *
64 GetShortPluginName();
65
66 virtual uint32_t
67 GetPluginVersion();
68
69protected:
70 friend class InstructionLLVMC;
71
72 bool
73 IsValid()
74 {
75 return (m_disasm_context != NULL);
76 }
77
78 int OpInfo(uint64_t PC,
79 uint64_t Offset,
80 uint64_t Size,
81 int TagType,
82 void *TagBug);
83
84 const char *SymbolLookup (uint64_t ReferenceValue,
85 uint64_t *ReferenceType,
86 uint64_t ReferencePC,
87 const char **ReferenceName);
88
89 static int OpInfoCallback (void *DisInfo,
90 uint64_t PC,
91 uint64_t Offset,
92 uint64_t Size,
93 int TagType,
94 void *TagBug);
95
96 static const char *SymbolLookupCallback(void *DisInfo,
97 uint64_t ReferenceValue,
98 uint64_t *ReferenceType,
99 uint64_t ReferencePC,
100 const char **ReferenceName);
101
102 void Lock(InstructionLLVMC *inst,
Greg Claytonba812f42012-05-10 02:52:23 +0000103 const lldb_private::ExecutionContext *exe_ctx)
Sean Callanan95e5c632012-02-17 00:53:45 +0000104 {
105 m_mutex.Lock();
Sean Callanan95e5c632012-02-17 00:53:45 +0000106 m_inst = inst;
Greg Claytonba812f42012-05-10 02:52:23 +0000107 m_exe_ctx = exe_ctx;
Sean Callanan95e5c632012-02-17 00:53:45 +0000108 }
109
110 void Unlock()
111 {
Sean Callanan95e5c632012-02-17 00:53:45 +0000112 m_inst = NULL;
Greg Claytonba812f42012-05-10 02:52:23 +0000113 m_exe_ctx = NULL;
Sean Callanan95e5c632012-02-17 00:53:45 +0000114 m_mutex.Unlock();
115 }
116
Greg Claytonba812f42012-05-10 02:52:23 +0000117 const lldb_private::ExecutionContext *m_exe_ctx;
118 InstructionLLVMC *m_inst;
119 lldb_private::Mutex m_mutex;
120 ::LLVMDisasmContextRef m_disasm_context;
121 ::LLVMDisasmContextRef m_alternate_disasm_context;
Sean Callanan95e5c632012-02-17 00:53:45 +0000122};
123
124#endif // liblldb_DisassemblerLLVM_h_