blob: 9af873fcd45465f78497ce33b6e5c7e7bac35fa1 [file] [log] [blame]
Sean Callanan95e5c632012-02-17 00:53:45 +00001//===-- DisassemblerLLVMC.h -------------------------------------*- C++ -*-===//
2//
Chandler Carruth2946cd72019-01-19 08:50:56 +00003// 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 Callanan95e5c632012-02-17 00:53:45 +00006//
7//===----------------------------------------------------------------------===//
8
9#ifndef liblldb_DisassemblerLLVMC_h_
10#define liblldb_DisassemblerLLVMC_h_
11
Eugene Zelenko45a40142015-10-22 21:24:37 +000012#include <memory>
Saleem Abdulrasool16ff8602016-05-18 01:59:10 +000013#include <mutex>
Jim Ingham0f063ba2013-03-02 00:26:47 +000014#include <string>
Sean Callanan95e5c632012-02-17 00:53:45 +000015
Eugene Zelenko45a40142015-10-22 21:24:37 +000016#include "lldb/Core/Address.h"
17#include "lldb/Core/Disassembler.h"
18#include "lldb/Core/PluginManager.h"
Eugene Zelenko45a40142015-10-22 21:24:37 +000019
Sean Callanan95e5c632012-02-17 00:53:45 +000020class InstructionLLVMC;
21
Kate Stoneb9c1b512016-09-06 20:57:50 +000022class DisassemblerLLVMC : public lldb_private::Disassembler {
Sean Callanan95e5c632012-02-17 00:53:45 +000023public:
Kate Stoneb9c1b512016-09-06 20:57:50 +000024 DisassemblerLLVMC(const lldb_private::ArchSpec &arch,
25 const char *flavor /* = NULL */);
Eugene Zelenko45a40142015-10-22 21:24:37 +000026
Kate Stoneb9c1b512016-09-06 20:57:50 +000027 ~DisassemblerLLVMC() override;
Eugene Zelenko45a40142015-10-22 21:24:37 +000028
Kate Stoneb9c1b512016-09-06 20:57:50 +000029 //------------------------------------------------------------------
30 // Static Functions
31 //------------------------------------------------------------------
32 static void Initialize();
Sylvestre Ledrua3e4ceb2014-04-15 12:08:57 +000033
Kate Stoneb9c1b512016-09-06 20:57:50 +000034 static void Terminate();
Sylvestre Ledrua3e4ceb2014-04-15 12:08:57 +000035
Kate Stoneb9c1b512016-09-06 20:57:50 +000036 static lldb_private::ConstString GetPluginNameStatic();
Sylvestre Ledrua3e4ceb2014-04-15 12:08:57 +000037
Kate Stoneb9c1b512016-09-06 20:57:50 +000038 static lldb_private::Disassembler *
39 CreateInstance(const lldb_private::ArchSpec &arch, const char *flavor);
Sylvestre Ledrua3e4ceb2014-04-15 12:08:57 +000040
Kate Stoneb9c1b512016-09-06 20:57:50 +000041 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 Ledrua3e4ceb2014-04-15 12:08:57 +000045
Kate Stoneb9c1b512016-09-06 20:57:50 +000046 //------------------------------------------------------------------
47 // PluginInterface protocol
48 //------------------------------------------------------------------
49 lldb_private::ConstString GetPluginName() override;
Sylvestre Ledrua3e4ceb2014-04-15 12:08:57 +000050
Kate Stoneb9c1b512016-09-06 20:57:50 +000051 uint32_t GetPluginVersion() override;
Sylvestre Ledrua3e4ceb2014-04-15 12:08:57 +000052
Sean Callanan95e5c632012-02-17 00:53:45 +000053protected:
Kate Stoneb9c1b512016-09-06 20:57:50 +000054 friend class InstructionLLVMC;
Sylvestre Ledrua3e4ceb2014-04-15 12:08:57 +000055
Kate Stoneb9c1b512016-09-06 20:57:50 +000056 bool FlavorValidForArchSpec(const lldb_private::ArchSpec &arch,
57 const char *flavor) override;
Sylvestre Ledrua3e4ceb2014-04-15 12:08:57 +000058
Tatyana Krasnukha6c2c08f2018-01-11 12:06:22 +000059 bool IsValid() const;
Sylvestre Ledrua3e4ceb2014-04-15 12:08:57 +000060
Kate Stoneb9c1b512016-09-06 20:57:50 +000061 int OpInfo(uint64_t PC, uint64_t Offset, uint64_t Size, int TagType,
62 void *TagBug);
Sylvestre Ledrua3e4ceb2014-04-15 12:08:57 +000063
Kate Stoneb9c1b512016-09-06 20:57:50 +000064 const char *SymbolLookup(uint64_t ReferenceValue, uint64_t *ReferenceType,
65 uint64_t ReferencePC, const char **ReferenceName);
Sylvestre Ledrua3e4ceb2014-04-15 12:08:57 +000066
Kate Stoneb9c1b512016-09-06 20:57:50 +000067 static int OpInfoCallback(void *DisInfo, uint64_t PC, uint64_t Offset,
68 uint64_t Size, int TagType, void *TagBug);
Sylvestre Ledrua3e4ceb2014-04-15 12:08:57 +000069
Kate Stoneb9c1b512016-09-06 20:57:50 +000070 static const char *SymbolLookupCallback(void *DisInfo,
71 uint64_t ReferenceValue,
72 uint64_t *ReferenceType,
73 uint64_t ReferencePC,
74 const char **ReferenceName);
Sylvestre Ledrua3e4ceb2014-04-15 12:08:57 +000075
Kate Stoneb9c1b512016-09-06 20:57:50 +000076 const lldb_private::ExecutionContext *m_exe_ctx;
77 InstructionLLVMC *m_inst;
78 std::mutex m_mutex;
79 bool m_data_from_file;
Sylvestre Ledrua3e4ceb2014-04-15 12:08:57 +000080
Tatyana Krasnukha6c2c08f2018-01-11 12:06:22 +000081 // 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 Callanan95e5c632012-02-17 00:53:45 +000087};
88
Eugene Zelenko45a40142015-10-22 21:24:37 +000089#endif // liblldb_DisassemblerLLVM_h_