Sean Callanan | 95e5c63 | 2012-02-17 00:53:45 +0000 | [diff] [blame] | 1 | //===-- 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 | |
| 21 | class InstructionLLVMC; |
| 22 | |
| 23 | class DisassemblerLLVMC : public lldb_private::Disassembler |
| 24 | { |
| 25 | public: |
| 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 Clayton | c7bece56 | 2013-01-25 18:06:21 +0000 | [diff] [blame^] | 53 | lldb::offset_t data_offset, |
| 54 | size_t num_instructions, |
Sean Callanan | 95e5c63 | 2012-02-17 00:53:45 +0000 | [diff] [blame] | 55 | 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 | |
| 69 | protected: |
| 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 Clayton | ba812f4 | 2012-05-10 02:52:23 +0000 | [diff] [blame] | 103 | const lldb_private::ExecutionContext *exe_ctx) |
Sean Callanan | 95e5c63 | 2012-02-17 00:53:45 +0000 | [diff] [blame] | 104 | { |
| 105 | m_mutex.Lock(); |
Sean Callanan | 95e5c63 | 2012-02-17 00:53:45 +0000 | [diff] [blame] | 106 | m_inst = inst; |
Greg Clayton | ba812f4 | 2012-05-10 02:52:23 +0000 | [diff] [blame] | 107 | m_exe_ctx = exe_ctx; |
Sean Callanan | 95e5c63 | 2012-02-17 00:53:45 +0000 | [diff] [blame] | 108 | } |
| 109 | |
| 110 | void Unlock() |
| 111 | { |
Sean Callanan | 95e5c63 | 2012-02-17 00:53:45 +0000 | [diff] [blame] | 112 | m_inst = NULL; |
Greg Clayton | ba812f4 | 2012-05-10 02:52:23 +0000 | [diff] [blame] | 113 | m_exe_ctx = NULL; |
Sean Callanan | 95e5c63 | 2012-02-17 00:53:45 +0000 | [diff] [blame] | 114 | m_mutex.Unlock(); |
| 115 | } |
| 116 | |
Greg Clayton | ba812f4 | 2012-05-10 02:52:23 +0000 | [diff] [blame] | 117 | 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 Callanan | 95e5c63 | 2012-02-17 00:53:45 +0000 | [diff] [blame] | 122 | }; |
| 123 | |
| 124 | #endif // liblldb_DisassemblerLLVM_h_ |