LLDB  mainline
EmulateInstructionRISCV.h
Go to the documentation of this file.
1 //===-- EmulateInstructionRISCV.h -----------------------------------------===//
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_INSTRUCTION_RISCV_EMULATEINSTRUCTIONRISCV_H
10 #define LLDB_SOURCE_PLUGINS_INSTRUCTION_RISCV_EMULATEINSTRUCTIONRISCV_H
11 
12 #include "RISCVInstructions.h"
13 
16 #include "lldb/Utility/Log.h"
18 #include "lldb/Utility/Status.h"
19 
20 namespace lldb_private {
21 
23 public:
24  static llvm::StringRef GetPluginNameStatic() { return "riscv"; }
25 
26  static llvm::StringRef GetPluginDescriptionStatic() {
27  return "Emulate instructions for the RISC-V architecture.";
28  }
29 
31  switch (inst_type) {
34  return true;
37  return false;
38  }
39  llvm_unreachable("Fully covered switch above!");
40  }
41 
42  static bool SupportsThisArch(const ArchSpec &arch);
43 
46 
47  static void Initialize();
48 
49  static void Terminate();
50 
51 public:
53 
54  llvm::StringRef GetPluginName() override { return GetPluginNameStatic(); }
55 
57  return SupportsThisInstructionType(inst_type);
58  }
59 
60  bool SetTargetTriple(const ArchSpec &arch) override;
61  bool ReadInstruction() override;
62  bool EvaluateInstruction(uint32_t options) override;
63  bool TestEmulation(Stream *out_stream, ArchSpec &arch,
64  OptionValueDictionary *test_data) override;
65  llvm::Optional<RegisterInfo> GetRegisterInfo(lldb::RegisterKind reg_kind,
66  uint32_t reg_num) override;
67 
68  llvm::Optional<lldb::addr_t> ReadPC();
69  bool WritePC(lldb::addr_t pc);
70 
71  llvm::Optional<DecodeResult> ReadInstructionAt(lldb::addr_t addr);
72  llvm::Optional<DecodeResult> Decode(uint32_t inst);
73  bool Execute(DecodeResult inst, bool ignore_cond);
74 
75  template <typename T>
76  std::enable_if_t<std::is_integral_v<T>, llvm::Optional<T>>
77  ReadMem(uint64_t addr) {
80  ctx.SetNoArgs();
81  bool success = false;
82  T result = ReadMemoryUnsigned(ctx, addr, sizeof(T), T(), &success);
83  if (!success)
84  return {}; // aka return false
85  return result;
86  }
87 
88  template <typename T> bool WriteMem(uint64_t addr, uint64_t value) {
91  ctx.SetNoArgs();
92  return WriteMemoryUnsigned(ctx, addr, value, sizeof(T));
93  }
94 
95  llvm::RoundingMode GetRoundingMode();
96  bool SetAccruedExceptions(llvm::APFloatBase::opStatus);
97 
98 private:
99  /// Last decoded instruction from m_opcode
101 };
102 
103 } // namespace lldb_private
104 
105 #endif // LLDB_SOURCE_PLUGINS_INSTRUCTION_RISCV_EMULATEINSTRUCTIONRISCV_H
RISCVInstructions.h
lldb_private::eInstructionTypePCModifying
@ eInstructionTypePCModifying
Definition: lldb-private-enumerations.h:123
lldb_private::ArchSpec
Definition: ArchSpec.h:32
lldb_private::EmulateInstructionRISCV::ReadInstruction
bool ReadInstruction() override
Definition: EmulateInstructionRISCV.cpp:1511
lldb_private::EmulateInstructionRISCV::SupportsThisInstructionType
static bool SupportsThisInstructionType(InstructionType inst_type)
Definition: EmulateInstructionRISCV.h:30
lldb_private::EmulateInstructionRISCV::SetTargetTriple
bool SetTargetTriple(const ArchSpec &arch) override
Definition: EmulateInstructionRISCV.cpp:1637
lldb_private::EmulateInstructionRISCV::GetPluginName
llvm::StringRef GetPluginName() override
Definition: EmulateInstructionRISCV.h:54
lldb_private::EmulateInstructionRISCV::Initialize
static void Initialize()
Definition: EmulateInstructionRISCV.cpp:1646
lldb_private::EmulateInstruction::Context
Definition: EmulateInstruction.h:184
lldb_private::EmulateInstruction::eContextRegisterStore
@ eContextRegisterStore
Definition: EmulateInstruction.h:136
lldb_private::EmulateInstructionRISCV::GetPluginNameStatic
static llvm::StringRef GetPluginNameStatic()
Definition: EmulateInstructionRISCV.h:24
RegisterValue.h
lldb_private::Stream
Definition: Stream.h:28
lldb::addr_t
uint64_t addr_t
Definition: lldb-types.h:83
pc
@ pc
Definition: CompactUnwindInfo.cpp:1251
lldb_private::EmulateInstructionRISCV::SupportsThisArch
static bool SupportsThisArch(const ArchSpec &arch)
Definition: EmulateInstructionRISCV.cpp:1666
lldb_private::eInstructionTypeAll
@ eInstructionTypeAll
Definition: lldb-private-enumerations.h:125
lldb_private::EmulateInstructionRISCV::ReadPC
llvm::Optional< lldb::addr_t > ReadPC()
Definition: EmulateInstructionRISCV.cpp:1527
lldb_private::EmulateInstructionRISCV::GetRegisterInfo
llvm::Optional< RegisterInfo > GetRegisterInfo(lldb::RegisterKind reg_kind, uint32_t reg_num) override
Definition: EmulateInstructionRISCV.cpp:1599
OptionValue.h
lldb_private::EmulateInstructionRISCV::CreateInstance
static lldb_private::EmulateInstruction * CreateInstance(const lldb_private::ArchSpec &arch, InstructionType inst_type)
Definition: EmulateInstructionRISCV.cpp:1656
lldb_private::EmulateInstructionRISCV::GetPluginDescriptionStatic
static llvm::StringRef GetPluginDescriptionStatic()
Definition: EmulateInstructionRISCV.h:26
EmulateInstruction.h
lldb_private::EmulateInstructionRISCV::GetRoundingMode
llvm::RoundingMode GetRoundingMode()
Definition: EmulateInstructionRISCV.cpp:1542
Log.h
lldb_private::EmulateInstructionRISCV::Terminate
static void Terminate()
Definition: EmulateInstructionRISCV.cpp:1651
lldb_private::EmulateInstruction::Context::type
ContextType type
Definition: EmulateInstruction.h:185
lldb_private::EmulateInstructionRISCV
Definition: EmulateInstructionRISCV.h:22
lldb_private::EmulateInstructionRISCV::Decode
llvm::Optional< DecodeResult > Decode(uint32_t inst)
Definition: EmulateInstructionRISCV.cpp:565
lldb_private::EmulateInstructionRISCV::TestEmulation
bool TestEmulation(Stream *out_stream, ArchSpec &arch, OptionValueDictionary *test_data) override
Definition: EmulateInstructionRISCV.cpp:1641
lldb_private::EmulateInstructionRISCV::SetAccruedExceptions
bool SetAccruedExceptions(llvm::APFloatBase::opStatus)
Definition: EmulateInstructionRISCV.cpp:1566
lldb_private::EmulateInstruction::WriteMemoryUnsigned
bool WriteMemoryUnsigned(const Context &context, lldb::addr_t addr, uint64_t uval, size_t uval_byte_size)
Definition: EmulateInstruction.cpp:200
lldb_private::EmulateInstructionRISCV::WritePC
bool WritePC(lldb::addr_t pc)
Definition: EmulateInstructionRISCV.cpp:1534
lldb::RegisterKind
RegisterKind
Register numbering types.
Definition: lldb-enumerations.h:228
lldb_private::EmulateInstructionRISCV::Execute
bool Execute(DecodeResult inst, bool ignore_cond)
Definition: EmulateInstructionRISCV.cpp:1476
lldb_private::EmulateInstruction::Context::SetNoArgs
void SetNoArgs()
Definition: EmulateInstruction.h:328
uint32_t
lldb_private::EmulateInstruction
Definition: EmulateInstruction.h:93
lldb_private::EmulateInstructionRISCV::m_decoded
DecodeResult m_decoded
Last decoded instruction from m_opcode.
Definition: EmulateInstructionRISCV.h:100
lldb_private::EmulateInstruction::eContextRegisterLoad
@ eContextRegisterLoad
Definition: EmulateInstruction.h:138
lldb_private::EmulateInstructionRISCV::EmulateInstructionRISCV
EmulateInstructionRISCV(const ArchSpec &arch)
Definition: EmulateInstructionRISCV.h:52
lldb_private::DecodeResult
Definition: RISCVInstructions.h:248
lldb_private::eInstructionTypePrologueEpilogue
@ eInstructionTypePrologueEpilogue
Definition: lldb-private-enumerations.h:120
lldb_private::EmulateInstructionRISCV::ReadMem
std::enable_if_t< std::is_integral_v< T >, llvm::Optional< T > > ReadMem(uint64_t addr)
Definition: EmulateInstructionRISCV.h:77
lldb_private::InstructionType
InstructionType
Instruction types.
Definition: lldb-private-enumerations.h:118
Status.h
lldb_private
A class that represents a running process on the host machine.
Definition: SBCommandInterpreterRunOptions.h:16
lldb_private::EmulateInstructionRISCV::ReadInstructionAt
llvm::Optional< DecodeResult > ReadInstructionAt(lldb::addr_t addr)
Definition: EmulateInstructionRISCV.cpp:1505
lldb_private::EmulateInstructionRISCV::EvaluateInstruction
bool EvaluateInstruction(uint32_t options) override
Definition: EmulateInstructionRISCV.cpp:1480
lldb_private::OptionValueDictionary
Definition: OptionValueDictionary.h:19
lldb_private::EmulateInstruction::ReadMemoryUnsigned
uint64_t ReadMemoryUnsigned(const Context &context, lldb::addr_t addr, size_t byte_size, uint64_t fail_value, bool *success_ptr)
Definition: EmulateInstruction.cpp:173
lldb_private::EmulateInstructionRISCV::WriteMem
bool WriteMem(uint64_t addr, uint64_t value)
Definition: EmulateInstructionRISCV.h:88
lldb_private::EmulateInstructionRISCV::SupportsEmulatingInstructionsOfType
bool SupportsEmulatingInstructionsOfType(InstructionType inst_type) override
Definition: EmulateInstructionRISCV.h:56
lldb_private::eInstructionTypeAny
@ eInstructionTypeAny
Definition: lldb-private-enumerations.h:119