Sean Callanan | 95e5c63 | 2012-02-17 00:53:45 +0000 | [diff] [blame] | 1 | //===-- DisassemblerLLVMC.h -------------------------------------*- C++ -*-===// |
| 2 | // |
Chandler Carruth | 2946cd7 | 2019-01-19 08:50:56 +0000 | [diff] [blame] | 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
Sean Callanan | 95e5c63 | 2012-02-17 00:53:45 +0000 | [diff] [blame] | 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | |
| 9 | #ifndef liblldb_DisassemblerLLVMC_h_ |
| 10 | #define liblldb_DisassemblerLLVMC_h_ |
| 11 | |
Eugene Zelenko | 45a4014 | 2015-10-22 21:24:37 +0000 | [diff] [blame] | 12 | #include <memory> |
Saleem Abdulrasool | 16ff860 | 2016-05-18 01:59:10 +0000 | [diff] [blame] | 13 | #include <mutex> |
Jim Ingham | 0f063ba | 2013-03-02 00:26:47 +0000 | [diff] [blame] | 14 | #include <string> |
Sean Callanan | 95e5c63 | 2012-02-17 00:53:45 +0000 | [diff] [blame] | 15 | |
Eugene Zelenko | 45a4014 | 2015-10-22 21:24:37 +0000 | [diff] [blame] | 16 | #include "lldb/Core/Address.h" |
| 17 | #include "lldb/Core/Disassembler.h" |
| 18 | #include "lldb/Core/PluginManager.h" |
Eugene Zelenko | 45a4014 | 2015-10-22 21:24:37 +0000 | [diff] [blame] | 19 | |
Sean Callanan | 95e5c63 | 2012-02-17 00:53:45 +0000 | [diff] [blame] | 20 | class InstructionLLVMC; |
| 21 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 22 | class DisassemblerLLVMC : public lldb_private::Disassembler { |
Sean Callanan | 95e5c63 | 2012-02-17 00:53:45 +0000 | [diff] [blame] | 23 | public: |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 24 | DisassemblerLLVMC(const lldb_private::ArchSpec &arch, |
| 25 | const char *flavor /* = NULL */); |
Eugene Zelenko | 45a4014 | 2015-10-22 21:24:37 +0000 | [diff] [blame] | 26 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 27 | ~DisassemblerLLVMC() override; |
Eugene Zelenko | 45a4014 | 2015-10-22 21:24:37 +0000 | [diff] [blame] | 28 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 29 | //------------------------------------------------------------------ |
| 30 | // Static Functions |
| 31 | //------------------------------------------------------------------ |
| 32 | static void Initialize(); |
Sylvestre Ledru | a3e4ceb | 2014-04-15 12:08:57 +0000 | [diff] [blame] | 33 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 34 | static void Terminate(); |
Sylvestre Ledru | a3e4ceb | 2014-04-15 12:08:57 +0000 | [diff] [blame] | 35 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 36 | static lldb_private::ConstString GetPluginNameStatic(); |
Sylvestre Ledru | a3e4ceb | 2014-04-15 12:08:57 +0000 | [diff] [blame] | 37 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 38 | static lldb_private::Disassembler * |
| 39 | CreateInstance(const lldb_private::ArchSpec &arch, const char *flavor); |
Sylvestre Ledru | a3e4ceb | 2014-04-15 12:08:57 +0000 | [diff] [blame] | 40 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 41 | size_t DecodeInstructions(const lldb_private::Address &base_addr, |
| 42 | const lldb_private::DataExtractor &data, |
| 43 | lldb::offset_t data_offset, size_t num_instructions, |
| 44 | bool append, bool data_from_file) override; |
Sylvestre Ledru | a3e4ceb | 2014-04-15 12:08:57 +0000 | [diff] [blame] | 45 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 46 | //------------------------------------------------------------------ |
| 47 | // PluginInterface protocol |
| 48 | //------------------------------------------------------------------ |
| 49 | lldb_private::ConstString GetPluginName() override; |
Sylvestre Ledru | a3e4ceb | 2014-04-15 12:08:57 +0000 | [diff] [blame] | 50 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 51 | uint32_t GetPluginVersion() override; |
Sylvestre Ledru | a3e4ceb | 2014-04-15 12:08:57 +0000 | [diff] [blame] | 52 | |
Sean Callanan | 95e5c63 | 2012-02-17 00:53:45 +0000 | [diff] [blame] | 53 | protected: |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 54 | friend class InstructionLLVMC; |
Sylvestre Ledru | a3e4ceb | 2014-04-15 12:08:57 +0000 | [diff] [blame] | 55 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 56 | bool FlavorValidForArchSpec(const lldb_private::ArchSpec &arch, |
| 57 | const char *flavor) override; |
Sylvestre Ledru | a3e4ceb | 2014-04-15 12:08:57 +0000 | [diff] [blame] | 58 | |
Tatyana Krasnukha | 6c2c08f | 2018-01-11 12:06:22 +0000 | [diff] [blame] | 59 | bool IsValid() const; |
Sylvestre Ledru | a3e4ceb | 2014-04-15 12:08:57 +0000 | [diff] [blame] | 60 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 61 | int OpInfo(uint64_t PC, uint64_t Offset, uint64_t Size, int TagType, |
| 62 | void *TagBug); |
Sylvestre Ledru | a3e4ceb | 2014-04-15 12:08:57 +0000 | [diff] [blame] | 63 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 64 | const char *SymbolLookup(uint64_t ReferenceValue, uint64_t *ReferenceType, |
| 65 | uint64_t ReferencePC, const char **ReferenceName); |
Sylvestre Ledru | a3e4ceb | 2014-04-15 12:08:57 +0000 | [diff] [blame] | 66 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 67 | static int OpInfoCallback(void *DisInfo, uint64_t PC, uint64_t Offset, |
| 68 | uint64_t Size, int TagType, void *TagBug); |
Sylvestre Ledru | a3e4ceb | 2014-04-15 12:08:57 +0000 | [diff] [blame] | 69 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 70 | static const char *SymbolLookupCallback(void *DisInfo, |
| 71 | uint64_t ReferenceValue, |
| 72 | uint64_t *ReferenceType, |
| 73 | uint64_t ReferencePC, |
| 74 | const char **ReferenceName); |
Sylvestre Ledru | a3e4ceb | 2014-04-15 12:08:57 +0000 | [diff] [blame] | 75 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 76 | const lldb_private::ExecutionContext *m_exe_ctx; |
| 77 | InstructionLLVMC *m_inst; |
| 78 | std::mutex m_mutex; |
| 79 | bool m_data_from_file; |
Sylvestre Ledru | a3e4ceb | 2014-04-15 12:08:57 +0000 | [diff] [blame] | 80 | |
Tatyana Krasnukha | 6c2c08f | 2018-01-11 12:06:22 +0000 | [diff] [blame] | 81 | // Since we need to make two actual MC Disassemblers for ARM (ARM & THUMB), |
| 82 | // and there's a bit of goo to set up and own in the MC disassembler world, |
| 83 | // this class was added to manage the actual disassemblers. |
| 84 | class MCDisasmInstance; |
| 85 | std::unique_ptr<MCDisasmInstance> m_disasm_up; |
| 86 | std::unique_ptr<MCDisasmInstance> m_alternate_disasm_up; |
Sean Callanan | 95e5c63 | 2012-02-17 00:53:45 +0000 | [diff] [blame] | 87 | }; |
| 88 | |
Eugene Zelenko | 45a4014 | 2015-10-22 21:24:37 +0000 | [diff] [blame] | 89 | #endif // liblldb_DisassemblerLLVM_h_ |