LLDB mainline
ABISysV_riscv.h
Go to the documentation of this file.
1//===-- ABISysV_riscv.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 liblldb_ABISysV_riscv_h_
10#define liblldb_ABISysV_riscv_h_
11
12// Other libraries and framework includes
13#include "llvm/TargetParser/Triple.h"
14
15// Project includes
16#include "lldb/Target/ABI.h"
17#include "lldb/Target/Process.h"
18#include "lldb/Utility/Flags.h"
19#include "lldb/lldb-private.h"
20
22public:
23 ~ABISysV_riscv() override = default;
24
25 size_t GetRedZoneSize() const override { return 0; }
26
28 lldb::addr_t functionAddress,
29 lldb::addr_t returnAddress,
30 llvm::ArrayRef<lldb::addr_t> args) const override;
31
32 // Special thread plan for GDB style non-jit function calls.
33 bool
35 lldb::addr_t functionAddress, lldb::addr_t returnAddress,
36 llvm::Type &prototype,
37 llvm::ArrayRef<ABI::CallArgument> args) const override;
38
40 lldb_private::ValueList &values) const override;
41
44 lldb::ValueObjectSP &new_value) override;
45
48 lldb_private::CompilerType &type) const override;
49
50 // Specialized to work with llvm IR types.
52 llvm::Type &type) const override;
53
54 bool
56
57 bool CreateDefaultUnwindPlan(lldb_private::UnwindPlan &unwind_plan) override;
58
59 bool RegisterIsVolatile(const lldb_private::RegisterInfo *reg_info) override;
60
62 // The CFA must be 128 bit aligned, unless the E ABI is used
63 lldb_private::ArchSpec arch = GetProcessSP()->GetTarget().GetArchitecture();
64 lldb_private::Flags arch_flags = arch.GetFlags();
66 return (cfa & 0x3ull) == 0;
67 return (cfa & 0xfull) == 0;
68 }
69
70 void SetIsRV64(bool is_rv64) { m_is_rv64 = is_rv64; }
71
73 // Calls can use the least significant bit to store auxiliary information,
74 // so no strict check is done for alignment.
75
76 lldb_private::ArchSpec arch = GetProcessSP()->GetTarget().GetArchitecture();
77
78 // <addr> & 2 set is a fault if C extension is not used.
79 lldb_private::Flags arch_flags(arch.GetFlags());
80 if (!arch_flags.Test(lldb_private::ArchSpec::eRISCV_rvc) && (pc & 2))
81 return false;
82
83 // Make sure 64 bit addr_t only has lower 32 bits set on riscv32
84 llvm::Triple::ArchType machine = arch.GetMachine();
85 if (llvm::Triple::riscv32 == machine)
86 return (pc <= UINT32_MAX);
87
88 return true;
89 }
90
92 GetRegisterInfoArray(uint32_t &count) override;
93
94 //------------------------------------------------------------------
95 // Static Functions
96 //------------------------------------------------------------------
97
98 static void Initialize();
99
100 static void Terminate();
101
103 const lldb_private::ArchSpec &arch);
104
105 static llvm::StringRef GetPluginNameStatic() { return "sysv-riscv"; }
106
107 //------------------------------------------------------------------
108 // PluginInterface protocol
109 //------------------------------------------------------------------
110
111 llvm::StringRef GetPluginName() override { return GetPluginNameStatic(); }
112
113protected:
115 std::vector<lldb_private::DynamicRegisterInfo::Register> &regs) override;
116
118
119private:
122 lldb_private::CompilerType &ast_type) const;
123
124 using lldb_private::RegInfoBasedABI::RegInfoBasedABI; // Call CreateInstance
125 // instead.
126 bool m_is_rv64; // true if target is riscv64; false if target is riscv32
127};
128
129#endif // liblldb_ABISysV_riscv_h_
llvm::StringRef GetPluginName() override
static void Initialize()
static llvm::StringRef GetPluginNameStatic()
bool PrepareTrivialCall(lldb_private::Thread &thread, lldb::addr_t sp, lldb::addr_t functionAddress, lldb::addr_t returnAddress, llvm::Type &prototype, llvm::ArrayRef< ABI::CallArgument > args) const override
bool CreateFunctionEntryUnwindPlan(lldb_private::UnwindPlan &unwind_plan) override
bool RegisterIsCalleeSaved(const lldb_private::RegisterInfo *reg_info)
void SetIsRV64(bool is_rv64)
Definition: ABISysV_riscv.h:70
bool CreateDefaultUnwindPlan(lldb_private::UnwindPlan &unwind_plan) override
void AugmentRegisterInfo(std::vector< lldb_private::DynamicRegisterInfo::Register > &regs) override
bool CodeAddressIsValid(lldb::addr_t pc) override
Definition: ABISysV_riscv.h:72
size_t GetRedZoneSize() const override
Definition: ABISysV_riscv.h:25
lldb_private::Status SetReturnValueObject(lldb::StackFrameSP &frame_sp, lldb::ValueObjectSP &new_value) override
bool PrepareTrivialCall(lldb_private::Thread &thread, lldb::addr_t sp, lldb::addr_t functionAddress, lldb::addr_t returnAddress, llvm::ArrayRef< lldb::addr_t > args) const override
~ABISysV_riscv() override=default
lldb::ValueObjectSP GetReturnValueObjectSimple(lldb_private::Thread &thread, lldb_private::CompilerType &ast_type) const
bool GetArgumentValues(lldb_private::Thread &thread, lldb_private::ValueList &values) const override
static void Terminate()
static lldb::ABISP CreateInstance(lldb::ProcessSP process_sp, const lldb_private::ArchSpec &arch)
bool RegisterIsVolatile(const lldb_private::RegisterInfo *reg_info) override
const lldb_private::RegisterInfo * GetRegisterInfoArray(uint32_t &count) override
lldb::ValueObjectSP GetReturnValueObjectImpl(lldb_private::Thread &thread, lldb_private::CompilerType &type) const override
bool CallFrameAddressIsValid(lldb::addr_t cfa) override
Definition: ABISysV_riscv.h:61
lldb::ProcessSP GetProcessSP() const
Request to get a Process shared pointer.
Definition: ABI.h:96
An architecture specification class.
Definition: ArchSpec.h:31
uint32_t GetFlags() const
Definition: ArchSpec.h:521
llvm::Triple::ArchType GetMachine() const
Returns a machine family for the current architecture.
Definition: ArchSpec.cpp:683
Generic representation of a type in a programming language.
Definition: CompilerType.h:36
A class to manage flags.
Definition: Flags.h:22
bool Test(ValueType bit) const
Test a single flag bit.
Definition: Flags.h:96
An error handling class.
Definition: Status.h:44
#define UINT32_MAX
Definition: lldb-defines.h:19
std::shared_ptr< lldb_private::ABI > ABISP
Definition: lldb-forward.h:315
std::shared_ptr< lldb_private::StackFrame > StackFrameSP
Definition: lldb-forward.h:420
std::shared_ptr< lldb_private::ValueObject > ValueObjectSP
Definition: lldb-forward.h:480
std::shared_ptr< lldb_private::Process > ProcessSP
Definition: lldb-forward.h:387
uint64_t addr_t
Definition: lldb-types.h:80
Every register is described in detail including its name, alternate name (optional),...