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 
19 
20 void ABIAArch64::Initialize() {
23 }
24 
28 }
29 
31  if (lldb::ProcessSP process_sp = GetProcessSP())
32  return FixAddress(pc, process_sp->GetCodeAddressMask());
33  return pc;
34 }
35 
37  if (lldb::ProcessSP process_sp = GetProcessSP())
38  return FixAddress(pc, process_sp->GetDataAddressMask());
39  return pc;
40 }
41 
42 std::pair<uint32_t, uint32_t>
43 ABIAArch64::GetEHAndDWARFNums(llvm::StringRef name) {
44  if (name == "pc")
46  if (name == "cpsr")
48  return MCBasedABI::GetEHAndDWARFNums(name);
49 }
50 
52  MapRegisterName(reg, "v", "q");
53  MapRegisterName(reg, "x29", "fp");
54  MapRegisterName(reg, "x30", "lr");
55  return reg;
56 }
57 
58 uint32_t ABIAArch64::GetGenericNum(llvm::StringRef name) {
59  return llvm::StringSwitch<uint32_t>(name)
60  .Case("pc", LLDB_REGNUM_GENERIC_PC)
61  .Cases("lr", "x30", LLDB_REGNUM_GENERIC_RA)
62  .Cases("sp", "x31", LLDB_REGNUM_GENERIC_SP)
63  .Cases("fp", "x29", LLDB_REGNUM_GENERIC_FP)
64  .Case("cpsr", LLDB_REGNUM_GENERIC_FLAGS)
65  .Case("x0", LLDB_REGNUM_GENERIC_ARG1)
66  .Case("x1", LLDB_REGNUM_GENERIC_ARG2)
67  .Case("x2", LLDB_REGNUM_GENERIC_ARG3)
68  .Case("x3", LLDB_REGNUM_GENERIC_ARG4)
69  .Case("x4", LLDB_REGNUM_GENERIC_ARG5)
70  .Case("x5", LLDB_REGNUM_GENERIC_ARG6)
71  .Case("x6", LLDB_REGNUM_GENERIC_ARG7)
72  .Case("x7", LLDB_REGNUM_GENERIC_ARG8)
73  .Default(LLDB_INVALID_REGNUM);
74 }
75 
76 static void addPartialRegisters(
77  std::vector<lldb_private::DynamicRegisterInfo::Register> &regs,
78  llvm::ArrayRef<llvm::Optional<uint32_t>> full_reg_indices,
79  uint32_t full_reg_size, const char *partial_reg_format,
80  uint32_t partial_reg_size, lldb::Encoding encoding, lldb::Format format) {
81  for (auto it : llvm::enumerate(full_reg_indices)) {
82  llvm::Optional<uint32_t> full_reg_index = it.value();
83  if (!full_reg_index ||
84  regs[full_reg_index.getValue()].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.getValue()},
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<llvm::Optional<uint32_t>, 32> x_regs;
113  std::array<llvm::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 }
LLDB_REGNUM_GENERIC_ARG2
#define LLDB_REGNUM_GENERIC_ARG2
Definition: lldb-defines.h:70
LLDB_REGNUM_GENERIC_ARG3
#define LLDB_REGNUM_GENERIC_ARG3
Definition: lldb-defines.h:72
LLDB_REGNUM_GENERIC_ARG1
#define LLDB_REGNUM_GENERIC_ARG1
Definition: lldb-defines.h:68
LLDB_INVALID_REGNUM
#define LLDB_INVALID_REGNUM
Definition: lldb-defines.h:91
lldb::Format
Format
Display format definitions.
Definition: lldb-enumerations.h:155
lldb_private::DynamicRegisterInfo::Register::alt_name
ConstString alt_name
Definition: DynamicRegisterInfo.h:29
ABIMacOSX_arm64.h
LLDB_REGNUM_GENERIC_ARG5
#define LLDB_REGNUM_GENERIC_ARG5
Definition: lldb-defines.h:76
ABIAArch64::Terminate
static void Terminate()
Definition: ABIAArch64.cpp:25
arm64_dwarf::cpsr
@ cpsr
Definition: ARM64_DWARF_Registers.h:53
lldb::eEncodingIEEE754
@ eEncodingIEEE754
float
Definition: lldb-enumerations.h:150
ABIAArch64::GetMCName
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:51
lldb_private::ConstString::SetCString
void SetCString(const char *cstr)
Set the C string value.
Definition: ConstString.cpp:302
lldb_private::addSupplementaryRegister
void addSupplementaryRegister(std::vector< DynamicRegisterInfo::Register > &regs, DynamicRegisterInfo::Register new_reg_info)
Definition: DynamicRegisterInfo.cpp:796
ABIAArch64::FixDataAddress
virtual lldb::addr_t FixDataAddress(lldb::addr_t pc) override
Definition: ABIAArch64.cpp:36
lldb::addr_t
uint64_t addr_t
Definition: lldb-types.h:83
pc
@ pc
Definition: CompactUnwindInfo.cpp:1250
ABISysV_arm64::Initialize
static void Initialize()
Definition: ABISysV_arm64.cpp:840
LLDB_REGNUM_GENERIC_ARG6
#define LLDB_REGNUM_GENERIC_ARG6
Definition: lldb-defines.h:78
Process.h
ABISysV_arm64::Terminate
static void Terminate()
Definition: ABISysV_arm64.cpp:845
ABIAArch64.h
LLDB_REGNUM_GENERIC_FLAGS
#define LLDB_REGNUM_GENERIC_FLAGS
Definition: lldb-defines.h:67
ABIAArch64::AugmentRegisterInfo
void AugmentRegisterInfo(std::vector< lldb_private::DynamicRegisterInfo::Register > &regs) override
Definition: ABIAArch64.cpp:106
lldb_private::ConstString::GetStringRef
llvm::StringRef GetStringRef() const
Get the string value as a llvm::StringRef.
Definition: ConstString.h:202
ABIAArch64::GetGenericNum
uint32_t GetGenericNum(llvm::StringRef name) override
Return the generic number of the given register.
Definition: ABIAArch64.cpp:58
lldb::eEncodingUint
@ eEncodingUint
unsigned integer
Definition: lldb-enumerations.h:148
lldb_private::ConstString
Definition: ConstString.h:40
string
string(SUBSTRING ${p} 10 -1 pStripped) if($
Definition: Plugins/CMakeLists.txt:40
lldb_private::ABI::GetProcessSP
lldb::ProcessSP GetProcessSP() const
Request to get a Process shared pointer.
Definition: ABI.h:96
arm64_dwarf::pc
@ pc
Definition: ARM64_DWARF_Registers.h:52
ABIAArch64
Definition: ABIAArch64.h:14
lldb_private::DynamicRegisterInfo::Register
Definition: DynamicRegisterInfo.h:27
ARM64_DWARF_Registers.h
ABISysV_arm64.h
uint32_t
LLDB_REGNUM_GENERIC_SP
#define LLDB_REGNUM_GENERIC_SP
Definition: lldb-defines.h:64
lldb_private::MCBasedABI::AugmentRegisterInfo
void AugmentRegisterInfo(std::vector< DynamicRegisterInfo::Register > &regs) override
Definition: ABI.cpp:237
lldb::Encoding
Encoding
Register encoding definitions.
Definition: lldb-enumerations.h:146
PluginManager.h
LLDB_REGNUM_GENERIC_ARG4
#define LLDB_REGNUM_GENERIC_ARG4
Definition: lldb-defines.h:74
lldb::eFormatHex
@ eFormatHex
Definition: lldb-enumerations.h:169
LLDB_REGNUM_GENERIC_FP
#define LLDB_REGNUM_GENERIC_FP
Definition: lldb-defines.h:65
LLDB_REGNUM_GENERIC_PC
#define LLDB_REGNUM_GENERIC_PC
Definition: lldb-defines.h:63
LLDB_INVALID_INDEX32
#define LLDB_INVALID_INDEX32
Definition: lldb-defines.h:87
ABIAArch64::FixCodeAddress
virtual 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:30
LLDB_PLUGIN_DEFINE
#define LLDB_PLUGIN_DEFINE(PluginName)
Definition: PluginManager.h:31
ABIMacOSX_arm64::Terminate
static void Terminate()
Definition: ABIMacOSX_arm64.cpp:828
LLDB_REGNUM_GENERIC_ARG8
#define LLDB_REGNUM_GENERIC_ARG8
Definition: lldb-defines.h:82
LLDB_REGNUM_GENERIC_ARG7
#define LLDB_REGNUM_GENERIC_ARG7
Definition: lldb-defines.h:80
lldb::eFormatFloat
@ eFormatFloat
Definition: lldb-enumerations.h:171
lldb_private::DynamicRegisterInfo::Register::name
ConstString name
Definition: DynamicRegisterInfo.h:28
addPartialRegisters
static void addPartialRegisters(std::vector< lldb_private::DynamicRegisterInfo::Register > &regs, llvm::ArrayRef< llvm::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:76
ABIAArch64::FixAddress
virtual lldb::addr_t FixAddress(lldb::addr_t pc, lldb::addr_t mask)
Definition: ABIAArch64.h:23
ABIMacOSX_arm64::Initialize
static void Initialize()
Definition: ABIMacOSX_arm64.cpp:823
ABIAArch64::GetEHAndDWARFNums
std::pair< uint32_t, uint32_t > GetEHAndDWARFNums(llvm::StringRef name) override
Return eh_frame and dwarf numbers for the given register.
Definition: ABIAArch64.cpp:43
lldb_private::MCBasedABI::MapRegisterName
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:271
LLDB_REGNUM_GENERIC_RA
#define LLDB_REGNUM_GENERIC_RA
Definition: lldb-defines.h:66