LLDB mainline
RegisterInfoPOSIXDynamic_riscv32.cpp
Go to the documentation of this file.
1//===----------------------------------------------------------------------===//
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
10
12#include "lldb/lldb-defines.h"
13#include "llvm/ADT/StringMap.h"
14#include "llvm/Support/Compiler.h"
15
16#include <stddef.h>
17
18#define GPR_OFFSET(idx) ((idx) * sizeof(uint32_t))
19#define FPR_OFFSET(idx) ((idx) * sizeof(uint32_t))
20
21#define DECLARE_REGISTER_INFOS_RISCV32_STRUCT
23#undef DECLARE_REGISTER_INFOS_RISCV32_STRUCT
24
29
31 return m_dyn_reg_infos.GetNumRegisters();
32}
33
35 for (uint32_t set_idx = 0; set_idx < GetRegisterSetCount(); ++set_idx) {
36 const lldb_private::RegisterSet *set =
37 m_dyn_reg_infos.GetRegisterSet(set_idx);
38 if (strcmp(set->name, "GPR") == 0)
39 return set->num_registers;
40 }
41 return 0;
42}
43
45 for (uint32_t set_idx = 0; set_idx < GetRegisterSetCount(); ++set_idx) {
46 const lldb_private::RegisterSet *set =
47 m_dyn_reg_infos.GetRegisterSet(set_idx);
48 if (strcmp(set->name, "FPR") == 0)
49 return set->num_registers;
50 }
51 return 0;
52}
53
56 return &*m_dyn_reg_infos
57 .registers<lldb_private::DynamicRegisterInfo::
58 reg_collection_const_range>()
59 .begin();
60}
61
63 return m_dyn_reg_infos.GetNumRegisterSets();
64}
65
67 uint32_t reg_index) const {
68 for (size_t set_index = 0; set_index < m_dyn_reg_infos.GetNumRegisterSets();
69 ++set_index) {
70 const lldb_private::RegisterSet *reg_set =
71 m_dyn_reg_infos.GetRegisterSet(set_index);
72 for (uint32_t idx = 0; idx < reg_set->num_registers; ++idx)
73 if (reg_set->registers[idx] == reg_index)
74 return set_index;
75 }
77}
78
81 if (set_index < GetRegisterSetCount())
82 return m_dyn_reg_infos.GetRegisterSet(set_index);
83 return nullptr;
84}
85
87 std::vector<lldb_private::DynamicRegisterInfo::Register> regs) {
88 return m_dyn_reg_infos.SetRegisterInfo(std::move(regs), m_target_arch);
89}
90
93 llvm::StringRef reg_name) const {
94 return m_dyn_reg_infos.GetRegisterInfo(reg_name);
95}
96
98 llvm::ArrayRef<std::string> features,
100 cs_reg_infos.clear();
101
102 // Sort and deduplicate to make the list independent of caller ordering.
103 llvm::SmallVector<llvm::StringRef> normalized_features(features.begin(),
104 features.end());
105 llvm::sort(normalized_features);
106 normalized_features.erase(llvm::unique(normalized_features),
107 normalized_features.end());
108
110 cs_reg_infos.reserve(k_num_csr_registers);
111
112 // Construct default CS register information. CS register information entries
113 // are stored in CSR-address order.
114 for (uint32_t reg = 0; reg < k_num_csr_registers; ++reg) {
116 for (auto &kind : csr.kinds)
117 kind = LLDB_INVALID_REGNUM;
118
119 lldb_private::ConstString name(llvm::formatv("csr_{0:x}", reg).str());
120 csr.name = name.GetCString();
121 csr.alt_name = csr.name;
122 csr.byte_size = 4;
123 csr.byte_offset = 0;
131 csr.value_regs = nullptr;
132 csr.invalidate_regs = nullptr;
133 csr.register_type = nullptr;
134
135 cs_reg_infos.push_back(csr);
136 }
137
138 // Patch application is order-dependent; later patches override earlier ones
139 // for the same CSR address.
140 ConfigureCSRegInfos("default", cs_reg_infos);
141
142 for (const auto &feature : normalized_features)
143 ConfigureCSRegInfos(feature, cs_reg_infos);
144}
145
147 llvm::StringRef feature,
149 // Initialized on first use so that the patch set does not depend on the
150 // initialization order of globals in other translation units.
151 static const llvm::StringMap<llvm::ArrayRef<lldb_private::RegisterInfo>>
152 g_register_infos_riscv32_csr_patches = {
153 {"default", llvm::ArrayRef(g_register_infos_riscv32_csr_patch)},
154 {"xqci", llvm::ArrayRef(g_register_infos_riscv32_csr_xqci_patch)},
155 {"xqciint",
156 llvm::ArrayRef(g_register_infos_riscv32_csr_xqciint_patch)}};
157
158 auto it = g_register_infos_riscv32_csr_patches.find(feature);
159 if (it == g_register_infos_riscv32_csr_patches.end())
160 return;
161
162 for (const auto &csr : it->second) {
163 const uint32_t lldb_reg = csr.kinds[lldb::eRegisterKindLLDB];
164 if (lldb_reg < csr_first_riscv || lldb_reg > csr_last_riscv)
165 continue;
166 uint32_t idx = lldb_reg - csr_first_riscv;
167 if (idx < cs_reg_infos.size())
168 cs_reg_infos[idx] = csr;
169 }
170}
const size_t k_num_csr_registers
const lldb_private::RegisterSet * GetRegisterSet(size_t reg_set) const override
static void ConfigureCSRegInfos(llvm::StringRef feature, llvm::SmallVectorImpl< lldb_private::RegisterInfo > &cs_reg_infos)
Applies the CS register information patch set for a given feature.
RegisterInfoPOSIXDynamic_riscv32(const lldb_private::ArchSpec &target_arch)
size_t SetRegisterInfo(std::vector< lldb_private::DynamicRegisterInfo::Register > regs)
const lldb_private::RegisterInfo * GetRegisterInfo() const override
lldb_private::DynamicRegisterInfo m_dyn_reg_infos
size_t GetRegisterSetFromRegisterIndex(uint32_t reg_index) const override
static void BuildCSRegInfos(llvm::ArrayRef< std::string > features, llvm::SmallVectorImpl< lldb_private::RegisterInfo > &cs_reg_infos)
Builds CS register information entries for 32-bit RISC-V debug targets on the basis of the enabled IS...
An architecture specification class.
Definition ArchSpec.h:32
A uniqued constant string class.
Definition ConstString.h:40
const char * GetCString() const
Get the string value as a C string.
RegisterInfoAndSetInterface(const lldb_private::ArchSpec &target_arch)
#define LLDB_INVALID_REGNUM
A class that represents a running process on the host machine.
@ eEncodingUint
unsigned integer
@ eRegisterKindGeneric
insn ptr reg, stack ptr reg, etc not specific to any particular target
@ eRegisterKindLLDB
lldb's internal register numbers
@ eRegisterKindDWARF
the register numbers seen DWARF
@ eRegisterKindEHFrame
the register numbers seen in eh_frame
@ eRegisterKindProcessPlugin
num used by the process plugin - e.g.
Every register is described in detail including its name, alternate name (optional),...
lldb::Encoding encoding
Encoding of the register bits.
const char * alt_name
Alternate name of this register, can be NULL.
uint32_t * value_regs
List of registers (terminated with LLDB_INVALID_REGNUM).
uint32_t byte_offset
The byte offset in the register context data where this register's value is found.
uint32_t byte_size
Size in bytes of the register.
uint32_t kinds[lldb::kNumRegisterKinds]
Holds all of the various register numbers for all register kinds.
const RegisterType * register_type
If not nullptr, a type defined by XML descriptions.
const char * name
Name of this register, can't be NULL.
lldb::Format format
Default display format.
uint32_t * invalidate_regs
List of registers (terminated with LLDB_INVALID_REGNUM).
Registers are grouped into register sets.
size_t num_registers
The number of registers in REGISTERS array below.
const uint32_t * registers
An array of register indicies in this set.
const char * name
Name of this register set.