LLDB mainline
ABIAArch64.cpp
Go to the documentation of this file.
1//===-- AArch66.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#include "ABIAArch64.h"
10#include "ABIMacOSX_arm64.h"
11#include "ABISysV_arm64.h"
14#include "lldb/Target/Process.h"
15
16#include <bitset>
17#include <optional>
18
20
21void ABIAArch64::Initialize() {
24}
25
29}
30
32 if (lldb::ProcessSP process_sp = GetProcessSP())
33 return FixAddress(pc, process_sp->GetCodeAddressMask());
34 return pc;
35}
36
38 if (lldb::ProcessSP process_sp = GetProcessSP())
39 return FixAddress(pc, process_sp->GetDataAddressMask());
40 return pc;
41}
42
43std::pair<uint32_t, uint32_t>
44ABIAArch64::GetEHAndDWARFNums(llvm::StringRef name) {
45 if (name == "pc")
47 if (name == "cpsr")
49 return MCBasedABI::GetEHAndDWARFNums(name);
50}
51
52std::string ABIAArch64::GetMCName(std::string reg) {
53 MapRegisterName(reg, "v", "q");
54 MapRegisterName(reg, "x29", "fp");
55 MapRegisterName(reg, "x30", "lr");
56 return reg;
57}
58
59uint32_t ABIAArch64::GetGenericNum(llvm::StringRef name) {
60 return llvm::StringSwitch<uint32_t>(name)
61 .Case("pc", LLDB_REGNUM_GENERIC_PC)
62 .Cases("lr", "x30", LLDB_REGNUM_GENERIC_RA)
63 .Cases("sp", "x31", LLDB_REGNUM_GENERIC_SP)
64 .Cases("fp", "x29", LLDB_REGNUM_GENERIC_FP)
65 .Case("cpsr", LLDB_REGNUM_GENERIC_FLAGS)
66 .Case("x0", LLDB_REGNUM_GENERIC_ARG1)
67 .Case("x1", LLDB_REGNUM_GENERIC_ARG2)
68 .Case("x2", LLDB_REGNUM_GENERIC_ARG3)
69 .Case("x3", LLDB_REGNUM_GENERIC_ARG4)
70 .Case("x4", LLDB_REGNUM_GENERIC_ARG5)
71 .Case("x5", LLDB_REGNUM_GENERIC_ARG6)
72 .Case("x6", LLDB_REGNUM_GENERIC_ARG7)
73 .Case("x7", LLDB_REGNUM_GENERIC_ARG8)
74 .Default(LLDB_INVALID_REGNUM);
75}
76
78 std::vector<lldb_private::DynamicRegisterInfo::Register> &regs,
79 llvm::ArrayRef<std::optional<uint32_t>> full_reg_indices,
80 uint32_t full_reg_size, const char *partial_reg_format,
81 uint32_t partial_reg_size, lldb::Encoding encoding, lldb::Format format) {
82 for (auto it : llvm::enumerate(full_reg_indices)) {
83 std::optional<uint32_t> full_reg_index = it.value();
84 if (!full_reg_index || regs[*full_reg_index].byte_size != full_reg_size)
85 return;
86
89 llvm::formatv(partial_reg_format, it.index()).str()),
91 lldb_private::ConstString("supplementary registers"),
92 partial_reg_size,
94 encoding,
95 format,
100 {*full_reg_index},
101 {}};
102 addSupplementaryRegister(regs, partial_reg);
103 }
104}
105
107 std::vector<lldb_private::DynamicRegisterInfo::Register> &regs) {
109
110 lldb_private::ConstString sp_string{"sp"};
111
112 std::array<std::optional<uint32_t>, 32> x_regs;
113 std::array<std::optional<uint32_t>, 32> v_regs;
114
115 for (auto it : llvm::enumerate(regs)) {
117 // GDB sends x31 as "sp". Add the "x31" alt_name for convenience.
118 if (info.name == sp_string && !info.alt_name)
119 info.alt_name.SetCString("x31");
120
121 unsigned int reg_num;
122 auto get_reg = [&info, &reg_num](const char *prefix) {
123 llvm::StringRef reg_name = info.name.GetStringRef();
124 llvm::StringRef alt_name = info.alt_name.GetStringRef();
125 return (reg_name.consume_front(prefix) &&
126 llvm::to_integer(reg_name, reg_num, 10) && reg_num < 32) ||
127 (alt_name.consume_front(prefix) &&
128 llvm::to_integer(alt_name, reg_num, 10) && reg_num < 32);
129 };
130
131 if (get_reg("x"))
132 x_regs[reg_num] = it.index();
133 else if (get_reg("v"))
134 v_regs[reg_num] = it.index();
135 // if we have at least one subregister, abort
136 else if (get_reg("w") || get_reg("s") || get_reg("d"))
137 return;
138 }
139
140 // Create aliases for partial registers: wN for xN, and sN/dN for vN.
141 addPartialRegisters(regs, x_regs, 8, "w{0}", 4, lldb::eEncodingUint,
143 addPartialRegisters(regs, v_regs, 16, "s{0}", 4, lldb::eEncodingIEEE754,
145 addPartialRegisters(regs, v_regs, 16, "d{0}", 8, lldb::eEncodingIEEE754,
147}
static void addPartialRegisters(std::vector< lldb_private::DynamicRegisterInfo::Register > &regs, llvm::ArrayRef< std::optional< uint32_t > > full_reg_indices, uint32_t full_reg_size, const char *partial_reg_format, uint32_t partial_reg_size, lldb::Encoding encoding, lldb::Format format)
Definition: ABIAArch64.cpp:77
#define LLDB_PLUGIN_DEFINE(PluginName)
Definition: PluginManager.h:31
static void Terminate()
Definition: ABIAArch64.cpp:26
lldb::addr_t FixDataAddress(lldb::addr_t pc) override
Definition: ABIAArch64.cpp:37
lldb::addr_t FixCodeAddress(lldb::addr_t pc) override
Some targets might use bits in a code address to indicate a mode switch.
Definition: ABIAArch64.cpp:31
uint32_t GetGenericNum(llvm::StringRef name) override
Return the generic number of the given register.
Definition: ABIAArch64.cpp:59
virtual lldb::addr_t FixAddress(lldb::addr_t pc, lldb::addr_t mask)
Definition: ABIAArch64.h:23
void AugmentRegisterInfo(std::vector< lldb_private::DynamicRegisterInfo::Register > &regs) override
Definition: ABIAArch64.cpp:106
std::pair< uint32_t, uint32_t > GetEHAndDWARFNums(llvm::StringRef name) override
Return eh_frame and dwarf numbers for the given register.
Definition: ABIAArch64.cpp:44
std::string GetMCName(std::string reg) override
For the given (capitalized) lldb register name, return the name of this register in the MCRegisterInf...
Definition: ABIAArch64.cpp:52
static void Terminate()
static void Initialize()
static void Initialize()
static void Terminate()
lldb::ProcessSP GetProcessSP() const
Request to get a Process shared pointer.
Definition: ABI.h:96
A uniqued constant string class.
Definition: ConstString.h:40
void SetCString(const char *cstr)
Set the C string value.
llvm::StringRef GetStringRef() const
Get the string value as a llvm::StringRef.
Definition: ConstString.h:191
void AugmentRegisterInfo(std::vector< DynamicRegisterInfo::Register > &regs) override
Definition: ABI.cpp:238
static void MapRegisterName(std::string &reg, llvm::StringRef from_prefix, llvm::StringRef to_prefix)
If the register name is of the form "<from_prefix>[<number>]" then change the name to "<to_prefix>[<n...
Definition: ABI.cpp:272
#define LLDB_REGNUM_GENERIC_RA
Definition: lldb-defines.h:56
#define LLDB_REGNUM_GENERIC_ARG8
Definition: lldb-defines.h:72
#define LLDB_REGNUM_GENERIC_ARG6
Definition: lldb-defines.h:68
#define LLDB_INVALID_INDEX32
Definition: lldb-defines.h:77
#define LLDB_REGNUM_GENERIC_SP
Definition: lldb-defines.h:54
#define LLDB_REGNUM_GENERIC_ARG4
Definition: lldb-defines.h:64
#define LLDB_REGNUM_GENERIC_ARG3
Definition: lldb-defines.h:62
#define LLDB_REGNUM_GENERIC_ARG1
Definition: lldb-defines.h:58
#define LLDB_REGNUM_GENERIC_ARG7
Definition: lldb-defines.h:70
#define LLDB_REGNUM_GENERIC_FLAGS
Definition: lldb-defines.h:57
#define LLDB_INVALID_REGNUM
Definition: lldb-defines.h:81
#define LLDB_REGNUM_GENERIC_ARG2
Definition: lldb-defines.h:60
#define LLDB_REGNUM_GENERIC_PC
Definition: lldb-defines.h:53
#define LLDB_REGNUM_GENERIC_FP
Definition: lldb-defines.h:55
#define LLDB_REGNUM_GENERIC_ARG5
Definition: lldb-defines.h:66
Format
Display format definitions.
std::shared_ptr< lldb_private::Process > ProcessSP
Definition: lldb-forward.h:368
Encoding
Register encoding definitions.
@ eEncodingIEEE754
float
@ eEncodingUint
unsigned integer
uint64_t addr_t
Definition: lldb-types.h:79