1 //===-- DisassemblerLLVMC.h -------------------------------------*- C++ -*-===//
2 //
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
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #ifndef LLDB_SOURCE_PLUGINS_DISASSEMBLER_LLVMC_DISASSEMBLERLLVMC_H
10 #define LLDB_SOURCE_PLUGINS_DISASSEMBLER_LLVMC_DISASSEMBLERLLVMC_H
11 
12 #include <memory>
13 #include <mutex>
14 #include <string>
15 
16 #include "lldb/Core/Address.h"
17 #include "lldb/Core/Disassembler.h"
18 #include "lldb/Core/PluginManager.h"
19 
20 class InstructionLLVMC;
21 
22 class DisassemblerLLVMC : public lldb_private::Disassembler {
23 public:
24   DisassemblerLLVMC(const lldb_private::ArchSpec &arch,
25                     const char *flavor /* = NULL */);
26 
27   ~DisassemblerLLVMC() override;
28 
29   // Static Functions
30   static void Initialize();
31 
32   static void Terminate();
33 
34   static lldb_private::ConstString GetPluginNameStatic();
35 
36   static lldb_private::Disassembler *
37   CreateInstance(const lldb_private::ArchSpec &arch, const char *flavor);
38 
39   size_t DecodeInstructions(const lldb_private::Address &base_addr,
40                             const lldb_private::DataExtractor &data,
41                             lldb::offset_t data_offset, size_t num_instructions,
42                             bool append, bool data_from_file) override;
43 
44   // PluginInterface protocol
45   lldb_private::ConstString GetPluginName() override;
46 
47   uint32_t GetPluginVersion() override;
48 
49 protected:
50   friend class InstructionLLVMC;
51 
52   bool FlavorValidForArchSpec(const lldb_private::ArchSpec &arch,
53                               const char *flavor) override;
54 
55   bool IsValid() const;
56 
57   int OpInfo(uint64_t PC, uint64_t Offset, uint64_t Size, int TagType,
58              void *TagBug);
59 
60   const char *SymbolLookup(uint64_t ReferenceValue, uint64_t *ReferenceType,
61                            uint64_t ReferencePC, const char **ReferenceName);
62 
63   static int OpInfoCallback(void *DisInfo, uint64_t PC, uint64_t Offset,
64                             uint64_t Size, int TagType, void *TagBug);
65 
66   static const char *SymbolLookupCallback(void *DisInfo,
67                                           uint64_t ReferenceValue,
68                                           uint64_t *ReferenceType,
69                                           uint64_t ReferencePC,
70                                           const char **ReferenceName);
71 
72   const lldb_private::ExecutionContext *m_exe_ctx;
73   InstructionLLVMC *m_inst;
74   std::mutex m_mutex;
75   bool m_data_from_file;
76 
77   // Since we need to make two actual MC Disassemblers for ARM (ARM & THUMB),
78   // and there's a bit of goo to set up and own in the MC disassembler world,
79   // this class was added to manage the actual disassemblers.
80   class MCDisasmInstance;
81   std::unique_ptr<MCDisasmInstance> m_disasm_up;
82   std::unique_ptr<MCDisasmInstance> m_alternate_disasm_up;
83 };
84 
85 #endif // LLDB_SOURCE_PLUGINS_DISASSEMBLER_LLVMC_DISASSEMBLERLLVMC_H
86