LLDB  mainline
DisassemblerLLVMC.h
Go to the documentation of this file.
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"
19 #include "llvm/ADT/Optional.h"
20 
21 class InstructionLLVMC;
22 
24 public:
26  const char *flavor /* = NULL */);
27 
28  ~DisassemblerLLVMC() override;
29 
30  // Static Functions
31  static void Initialize();
32 
33  static void Terminate();
34 
35  static llvm::StringRef GetPluginNameStatic() { return "llvm-mc"; }
36 
38  CreateInstance(const lldb_private::ArchSpec &arch, const char *flavor);
39 
40  size_t DecodeInstructions(const lldb_private::Address &base_addr,
41  const lldb_private::DataExtractor &data,
42  lldb::offset_t data_offset, size_t num_instructions,
43  bool append, bool data_from_file) override;
44 
45  // PluginInterface protocol
46  llvm::StringRef GetPluginName() override { return GetPluginNameStatic(); }
47 
48 protected:
49  friend class InstructionLLVMC;
50 
52  const char *flavor) override;
53 
54  bool IsValid() const;
55 
56  int OpInfo(uint64_t PC, uint64_t Offset, uint64_t Size, int TagType,
57  void *TagBug);
58 
59  const char *SymbolLookup(uint64_t ReferenceValue, uint64_t *ReferenceType,
60  uint64_t ReferencePC, const char **ReferenceName);
61 
62  static int OpInfoCallback(void *DisInfo, uint64_t PC, uint64_t Offset,
63  uint64_t Size, int TagType, void *TagBug);
64 
65  static const char *SymbolLookupCallback(void *DisInfo,
66  uint64_t ReferenceValue,
67  uint64_t *ReferenceType,
68  uint64_t ReferencePC,
69  const char **ReferenceName);
70 
73  std::mutex m_mutex;
75  // Save the AArch64 ADRP instruction word and address it was at,
76  // in case the next instruction is an ADD to the same register;
77  // this is a pc-relative address calculation and we need both
78  // parts to calculate the symbolication.
80  llvm::Optional<uint32_t> m_adrp_insn;
81 
82  // Since we need to make two actual MC Disassemblers for ARM (ARM & THUMB),
83  // and there's a bit of goo to set up and own in the MC disassembler world,
84  // this class was added to manage the actual disassemblers.
86  std::unique_ptr<MCDisasmInstance> m_disasm_up;
87  std::unique_ptr<MCDisasmInstance> m_alternate_disasm_up;
88 };
89 
90 #endif // LLDB_SOURCE_PLUGINS_DISASSEMBLER_LLVMC_DISASSEMBLERLLVMC_H
DisassemblerLLVMC::m_inst
InstructionLLVMC * m_inst
Definition: DisassemblerLLVMC.h:72
DisassemblerLLVMC::m_disasm_up
std::unique_ptr< MCDisasmInstance > m_disasm_up
Definition: DisassemblerLLVMC.h:85
lldb_private::ExecutionContext
Definition: ExecutionContext.h:292
lldb_private::ArchSpec
Definition: ArchSpec.h:33
DisassemblerLLVMC::OpInfo
int OpInfo(uint64_t PC, uint64_t Offset, uint64_t Size, int TagType, void *TagBug)
Definition: DisassemblerLLVMC.cpp:1328
DisassemblerLLVMC::SymbolLookup
const char * SymbolLookup(uint64_t ReferenceValue, uint64_t *ReferenceType, uint64_t ReferencePC, const char **ReferenceName)
Definition: DisassemblerLLVMC.cpp:1340
DisassemblerLLVMC::DisassemblerLLVMC
DisassemblerLLVMC(const lldb_private::ArchSpec &arch, const char *flavor)
Definition: DisassemblerLLVMC.cpp:1069
lldb::offset_t
uint64_t offset_t
Definition: lldb-types.h:87
InstructionLLVMC
Definition: DisassemblerLLVMC.cpp:85
Disassembler.h
lldb::addr_t
uint64_t addr_t
Definition: lldb-types.h:83
DisassemblerLLVMC::~DisassemblerLLVMC
~DisassemblerLLVMC() override
DisassemblerLLVMC::m_adrp_address
lldb::addr_t m_adrp_address
Definition: DisassemblerLLVMC.h:79
DisassemblerLLVMC::FlavorValidForArchSpec
bool FlavorValidForArchSpec(const lldb_private::ArchSpec &arch, const char *flavor) override
Definition: DisassemblerLLVMC.cpp:1313
DisassemblerLLVMC::GetPluginNameStatic
static llvm::StringRef GetPluginNameStatic()
Definition: DisassemblerLLVMC.h:35
DisassemblerLLVMC::IsValid
bool IsValid() const
Definition: DisassemblerLLVMC.cpp:1326
lldb_private::DataExtractor
Definition: DataExtractor.h:48
DisassemblerLLVMC::DecodeInstructions
size_t DecodeInstructions(const lldb_private::Address &base_addr, const lldb_private::DataExtractor &data, lldb::offset_t data_offset, size_t num_instructions, bool append, bool data_from_file) override
Definition: DisassemblerLLVMC.cpp:1237
DisassemblerLLVMC::m_alternate_disasm_up
std::unique_ptr< MCDisasmInstance > m_alternate_disasm_up
Definition: DisassemblerLLVMC.h:87
DisassemblerLLVMC
Definition: DisassemblerLLVMC.h:23
DisassemblerLLVMC::m_adrp_insn
llvm::Optional< uint32_t > m_adrp_insn
Definition: DisassemblerLLVMC.h:80
DisassemblerLLVMC::GetPluginName
llvm::StringRef GetPluginName() override
Definition: DisassemblerLLVMC.h:46
Address.h
DisassemblerLLVMC::Initialize
static void Initialize()
Definition: DisassemblerLLVMC.cpp:1282
DisassemblerLLVMC::CreateInstance
static lldb_private::Disassembler * CreateInstance(const lldb_private::ArchSpec &arch, const char *flavor)
Definition: DisassemblerLLVMC.cpp:1225
DisassemblerLLVMC::SymbolLookupCallback
static const char * SymbolLookupCallback(void *DisInfo, uint64_t ReferenceValue, uint64_t *ReferenceType, uint64_t ReferencePC, const char **ReferenceName)
Definition: DisassemblerLLVMC.cpp:1305
DisassemblerLLVMC::OpInfoCallback
static int OpInfoCallback(void *DisInfo, uint64_t PC, uint64_t Offset, uint64_t Size, int TagType, void *TagBug)
Definition: DisassemblerLLVMC.cpp:1298
DisassemblerLLVMC::m_exe_ctx
const lldb_private::ExecutionContext * m_exe_ctx
Definition: DisassemblerLLVMC.h:71
lldb_private::Address
Definition: Address.h:59
DisassemblerLLVMC::m_mutex
std::mutex m_mutex
Definition: DisassemblerLLVMC.h:73
DisassemblerLLVMC::MCDisasmInstance
Definition: DisassemblerLLVMC.cpp:48
PluginManager.h
DisassemblerLLVMC::m_data_from_file
bool m_data_from_file
Definition: DisassemblerLLVMC.h:74
lldb_private::Disassembler
Definition: Disassembler.h:368
DisassemblerLLVMC::Terminate
static void Terminate()
Definition: DisassemblerLLVMC.cpp:1294