1*0b57cec5SDimitry Andric //===-- GDBRemoteRegisterContext.cpp ----------------------------*- C++ -*-===// 2*0b57cec5SDimitry Andric // 3*0b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4*0b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information. 5*0b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6*0b57cec5SDimitry Andric // 7*0b57cec5SDimitry Andric //===----------------------------------------------------------------------===// 8*0b57cec5SDimitry Andric 9*0b57cec5SDimitry Andric #include "GDBRemoteRegisterContext.h" 10*0b57cec5SDimitry Andric 11*0b57cec5SDimitry Andric #include "lldb/Target/ExecutionContext.h" 12*0b57cec5SDimitry Andric #include "lldb/Target/Target.h" 13*0b57cec5SDimitry Andric #include "lldb/Utility/DataBufferHeap.h" 14*0b57cec5SDimitry Andric #include "lldb/Utility/DataExtractor.h" 15*0b57cec5SDimitry Andric #include "lldb/Utility/RegisterValue.h" 16*0b57cec5SDimitry Andric #include "lldb/Utility/Scalar.h" 17*0b57cec5SDimitry Andric #include "lldb/Utility/StreamString.h" 18*0b57cec5SDimitry Andric #include "ProcessGDBRemote.h" 19*0b57cec5SDimitry Andric #include "ProcessGDBRemoteLog.h" 20*0b57cec5SDimitry Andric #include "ThreadGDBRemote.h" 21*0b57cec5SDimitry Andric #include "Utility/ARM_DWARF_Registers.h" 22*0b57cec5SDimitry Andric #include "Utility/ARM_ehframe_Registers.h" 23*0b57cec5SDimitry Andric #include "lldb/Utility/StringExtractorGDBRemote.h" 24*0b57cec5SDimitry Andric 25*0b57cec5SDimitry Andric #include <memory> 26*0b57cec5SDimitry Andric 27*0b57cec5SDimitry Andric using namespace lldb; 28*0b57cec5SDimitry Andric using namespace lldb_private; 29*0b57cec5SDimitry Andric using namespace lldb_private::process_gdb_remote; 30*0b57cec5SDimitry Andric 31*0b57cec5SDimitry Andric // GDBRemoteRegisterContext constructor 32*0b57cec5SDimitry Andric GDBRemoteRegisterContext::GDBRemoteRegisterContext( 33*0b57cec5SDimitry Andric ThreadGDBRemote &thread, uint32_t concrete_frame_idx, 34*0b57cec5SDimitry Andric GDBRemoteDynamicRegisterInfo ®_info, bool read_all_at_once) 35*0b57cec5SDimitry Andric : RegisterContext(thread, concrete_frame_idx), m_reg_info(reg_info), 36*0b57cec5SDimitry Andric m_reg_valid(), m_reg_data(), m_read_all_at_once(read_all_at_once) { 37*0b57cec5SDimitry Andric // Resize our vector of bools to contain one bool for every register. We will 38*0b57cec5SDimitry Andric // use these boolean values to know when a register value is valid in 39*0b57cec5SDimitry Andric // m_reg_data. 40*0b57cec5SDimitry Andric m_reg_valid.resize(reg_info.GetNumRegisters()); 41*0b57cec5SDimitry Andric 42*0b57cec5SDimitry Andric // Make a heap based buffer that is big enough to store all registers 43*0b57cec5SDimitry Andric DataBufferSP reg_data_sp( 44*0b57cec5SDimitry Andric new DataBufferHeap(reg_info.GetRegisterDataByteSize(), 0)); 45*0b57cec5SDimitry Andric m_reg_data.SetData(reg_data_sp); 46*0b57cec5SDimitry Andric m_reg_data.SetByteOrder(thread.GetProcess()->GetByteOrder()); 47*0b57cec5SDimitry Andric } 48*0b57cec5SDimitry Andric 49*0b57cec5SDimitry Andric // Destructor 50*0b57cec5SDimitry Andric GDBRemoteRegisterContext::~GDBRemoteRegisterContext() {} 51*0b57cec5SDimitry Andric 52*0b57cec5SDimitry Andric void GDBRemoteRegisterContext::InvalidateAllRegisters() { 53*0b57cec5SDimitry Andric SetAllRegisterValid(false); 54*0b57cec5SDimitry Andric } 55*0b57cec5SDimitry Andric 56*0b57cec5SDimitry Andric void GDBRemoteRegisterContext::SetAllRegisterValid(bool b) { 57*0b57cec5SDimitry Andric std::vector<bool>::iterator pos, end = m_reg_valid.end(); 58*0b57cec5SDimitry Andric for (pos = m_reg_valid.begin(); pos != end; ++pos) 59*0b57cec5SDimitry Andric *pos = b; 60*0b57cec5SDimitry Andric } 61*0b57cec5SDimitry Andric 62*0b57cec5SDimitry Andric size_t GDBRemoteRegisterContext::GetRegisterCount() { 63*0b57cec5SDimitry Andric return m_reg_info.GetNumRegisters(); 64*0b57cec5SDimitry Andric } 65*0b57cec5SDimitry Andric 66*0b57cec5SDimitry Andric const RegisterInfo * 67*0b57cec5SDimitry Andric GDBRemoteRegisterContext::GetRegisterInfoAtIndex(size_t reg) { 68*0b57cec5SDimitry Andric RegisterInfo *reg_info = m_reg_info.GetRegisterInfoAtIndex(reg); 69*0b57cec5SDimitry Andric 70*0b57cec5SDimitry Andric if (reg_info && reg_info->dynamic_size_dwarf_expr_bytes) { 71*0b57cec5SDimitry Andric const ArchSpec &arch = m_thread.GetProcess()->GetTarget().GetArchitecture(); 72*0b57cec5SDimitry Andric uint8_t reg_size = UpdateDynamicRegisterSize(arch, reg_info); 73*0b57cec5SDimitry Andric reg_info->byte_size = reg_size; 74*0b57cec5SDimitry Andric } 75*0b57cec5SDimitry Andric return reg_info; 76*0b57cec5SDimitry Andric } 77*0b57cec5SDimitry Andric 78*0b57cec5SDimitry Andric size_t GDBRemoteRegisterContext::GetRegisterSetCount() { 79*0b57cec5SDimitry Andric return m_reg_info.GetNumRegisterSets(); 80*0b57cec5SDimitry Andric } 81*0b57cec5SDimitry Andric 82*0b57cec5SDimitry Andric const RegisterSet *GDBRemoteRegisterContext::GetRegisterSet(size_t reg_set) { 83*0b57cec5SDimitry Andric return m_reg_info.GetRegisterSet(reg_set); 84*0b57cec5SDimitry Andric } 85*0b57cec5SDimitry Andric 86*0b57cec5SDimitry Andric bool GDBRemoteRegisterContext::ReadRegister(const RegisterInfo *reg_info, 87*0b57cec5SDimitry Andric RegisterValue &value) { 88*0b57cec5SDimitry Andric // Read the register 89*0b57cec5SDimitry Andric if (ReadRegisterBytes(reg_info, m_reg_data)) { 90*0b57cec5SDimitry Andric const bool partial_data_ok = false; 91*0b57cec5SDimitry Andric Status error(value.SetValueFromData( 92*0b57cec5SDimitry Andric reg_info, m_reg_data, reg_info->byte_offset, partial_data_ok)); 93*0b57cec5SDimitry Andric return error.Success(); 94*0b57cec5SDimitry Andric } 95*0b57cec5SDimitry Andric return false; 96*0b57cec5SDimitry Andric } 97*0b57cec5SDimitry Andric 98*0b57cec5SDimitry Andric bool GDBRemoteRegisterContext::PrivateSetRegisterValue( 99*0b57cec5SDimitry Andric uint32_t reg, llvm::ArrayRef<uint8_t> data) { 100*0b57cec5SDimitry Andric const RegisterInfo *reg_info = GetRegisterInfoAtIndex(reg); 101*0b57cec5SDimitry Andric if (reg_info == nullptr) 102*0b57cec5SDimitry Andric return false; 103*0b57cec5SDimitry Andric 104*0b57cec5SDimitry Andric // Invalidate if needed 105*0b57cec5SDimitry Andric InvalidateIfNeeded(false); 106*0b57cec5SDimitry Andric 107*0b57cec5SDimitry Andric const size_t reg_byte_size = reg_info->byte_size; 108*0b57cec5SDimitry Andric memcpy(const_cast<uint8_t *>( 109*0b57cec5SDimitry Andric m_reg_data.PeekData(reg_info->byte_offset, reg_byte_size)), 110*0b57cec5SDimitry Andric data.data(), std::min(data.size(), reg_byte_size)); 111*0b57cec5SDimitry Andric bool success = data.size() >= reg_byte_size; 112*0b57cec5SDimitry Andric if (success) { 113*0b57cec5SDimitry Andric SetRegisterIsValid(reg, true); 114*0b57cec5SDimitry Andric } else if (data.size() > 0) { 115*0b57cec5SDimitry Andric // Only set register is valid to false if we copied some bytes, else leave 116*0b57cec5SDimitry Andric // it as it was. 117*0b57cec5SDimitry Andric SetRegisterIsValid(reg, false); 118*0b57cec5SDimitry Andric } 119*0b57cec5SDimitry Andric return success; 120*0b57cec5SDimitry Andric } 121*0b57cec5SDimitry Andric 122*0b57cec5SDimitry Andric bool GDBRemoteRegisterContext::PrivateSetRegisterValue(uint32_t reg, 123*0b57cec5SDimitry Andric uint64_t new_reg_val) { 124*0b57cec5SDimitry Andric const RegisterInfo *reg_info = GetRegisterInfoAtIndex(reg); 125*0b57cec5SDimitry Andric if (reg_info == nullptr) 126*0b57cec5SDimitry Andric return false; 127*0b57cec5SDimitry Andric 128*0b57cec5SDimitry Andric // Early in process startup, we can get a thread that has an invalid byte 129*0b57cec5SDimitry Andric // order because the process hasn't been completely set up yet (see the ctor 130*0b57cec5SDimitry Andric // where the byte order is setfrom the process). If that's the case, we 131*0b57cec5SDimitry Andric // can't set the value here. 132*0b57cec5SDimitry Andric if (m_reg_data.GetByteOrder() == eByteOrderInvalid) { 133*0b57cec5SDimitry Andric return false; 134*0b57cec5SDimitry Andric } 135*0b57cec5SDimitry Andric 136*0b57cec5SDimitry Andric // Invalidate if needed 137*0b57cec5SDimitry Andric InvalidateIfNeeded(false); 138*0b57cec5SDimitry Andric 139*0b57cec5SDimitry Andric DataBufferSP buffer_sp(new DataBufferHeap(&new_reg_val, sizeof(new_reg_val))); 140*0b57cec5SDimitry Andric DataExtractor data(buffer_sp, endian::InlHostByteOrder(), sizeof(void *)); 141*0b57cec5SDimitry Andric 142*0b57cec5SDimitry Andric // If our register context and our register info disagree, which should never 143*0b57cec5SDimitry Andric // happen, don't overwrite past the end of the buffer. 144*0b57cec5SDimitry Andric if (m_reg_data.GetByteSize() < reg_info->byte_offset + reg_info->byte_size) 145*0b57cec5SDimitry Andric return false; 146*0b57cec5SDimitry Andric 147*0b57cec5SDimitry Andric // Grab a pointer to where we are going to put this register 148*0b57cec5SDimitry Andric uint8_t *dst = const_cast<uint8_t *>( 149*0b57cec5SDimitry Andric m_reg_data.PeekData(reg_info->byte_offset, reg_info->byte_size)); 150*0b57cec5SDimitry Andric 151*0b57cec5SDimitry Andric if (dst == nullptr) 152*0b57cec5SDimitry Andric return false; 153*0b57cec5SDimitry Andric 154*0b57cec5SDimitry Andric if (data.CopyByteOrderedData(0, // src offset 155*0b57cec5SDimitry Andric reg_info->byte_size, // src length 156*0b57cec5SDimitry Andric dst, // dst 157*0b57cec5SDimitry Andric reg_info->byte_size, // dst length 158*0b57cec5SDimitry Andric m_reg_data.GetByteOrder())) // dst byte order 159*0b57cec5SDimitry Andric { 160*0b57cec5SDimitry Andric SetRegisterIsValid(reg, true); 161*0b57cec5SDimitry Andric return true; 162*0b57cec5SDimitry Andric } 163*0b57cec5SDimitry Andric return false; 164*0b57cec5SDimitry Andric } 165*0b57cec5SDimitry Andric 166*0b57cec5SDimitry Andric // Helper function for GDBRemoteRegisterContext::ReadRegisterBytes(). 167*0b57cec5SDimitry Andric bool GDBRemoteRegisterContext::GetPrimordialRegister( 168*0b57cec5SDimitry Andric const RegisterInfo *reg_info, GDBRemoteCommunicationClient &gdb_comm) { 169*0b57cec5SDimitry Andric const uint32_t lldb_reg = reg_info->kinds[eRegisterKindLLDB]; 170*0b57cec5SDimitry Andric const uint32_t remote_reg = reg_info->kinds[eRegisterKindProcessPlugin]; 171*0b57cec5SDimitry Andric 172*0b57cec5SDimitry Andric if (DataBufferSP buffer_sp = 173*0b57cec5SDimitry Andric gdb_comm.ReadRegister(m_thread.GetProtocolID(), remote_reg)) 174*0b57cec5SDimitry Andric return PrivateSetRegisterValue( 175*0b57cec5SDimitry Andric lldb_reg, llvm::ArrayRef<uint8_t>(buffer_sp->GetBytes(), 176*0b57cec5SDimitry Andric buffer_sp->GetByteSize())); 177*0b57cec5SDimitry Andric return false; 178*0b57cec5SDimitry Andric } 179*0b57cec5SDimitry Andric 180*0b57cec5SDimitry Andric bool GDBRemoteRegisterContext::ReadRegisterBytes(const RegisterInfo *reg_info, 181*0b57cec5SDimitry Andric DataExtractor &data) { 182*0b57cec5SDimitry Andric ExecutionContext exe_ctx(CalculateThread()); 183*0b57cec5SDimitry Andric 184*0b57cec5SDimitry Andric Process *process = exe_ctx.GetProcessPtr(); 185*0b57cec5SDimitry Andric Thread *thread = exe_ctx.GetThreadPtr(); 186*0b57cec5SDimitry Andric if (process == nullptr || thread == nullptr) 187*0b57cec5SDimitry Andric return false; 188*0b57cec5SDimitry Andric 189*0b57cec5SDimitry Andric GDBRemoteCommunicationClient &gdb_comm( 190*0b57cec5SDimitry Andric ((ProcessGDBRemote *)process)->GetGDBRemote()); 191*0b57cec5SDimitry Andric 192*0b57cec5SDimitry Andric InvalidateIfNeeded(false); 193*0b57cec5SDimitry Andric 194*0b57cec5SDimitry Andric const uint32_t reg = reg_info->kinds[eRegisterKindLLDB]; 195*0b57cec5SDimitry Andric 196*0b57cec5SDimitry Andric if (!GetRegisterIsValid(reg)) { 197*0b57cec5SDimitry Andric if (m_read_all_at_once) { 198*0b57cec5SDimitry Andric if (DataBufferSP buffer_sp = 199*0b57cec5SDimitry Andric gdb_comm.ReadAllRegisters(m_thread.GetProtocolID())) { 200*0b57cec5SDimitry Andric memcpy(const_cast<uint8_t *>(m_reg_data.GetDataStart()), 201*0b57cec5SDimitry Andric buffer_sp->GetBytes(), 202*0b57cec5SDimitry Andric std::min(buffer_sp->GetByteSize(), m_reg_data.GetByteSize())); 203*0b57cec5SDimitry Andric if (buffer_sp->GetByteSize() >= m_reg_data.GetByteSize()) { 204*0b57cec5SDimitry Andric SetAllRegisterValid(true); 205*0b57cec5SDimitry Andric return true; 206*0b57cec5SDimitry Andric } else { 207*0b57cec5SDimitry Andric Log *log(ProcessGDBRemoteLog::GetLogIfAnyCategoryIsSet(GDBR_LOG_THREAD | 208*0b57cec5SDimitry Andric GDBR_LOG_PACKETS)); 209*0b57cec5SDimitry Andric if (log) 210*0b57cec5SDimitry Andric log->Printf ("error: GDBRemoteRegisterContext::ReadRegisterBytes tried to read the " 211*0b57cec5SDimitry Andric "entire register context at once, expected at least %" PRId64 " bytes " 212*0b57cec5SDimitry Andric "but only got %" PRId64 " bytes.", m_reg_data.GetByteSize(), 213*0b57cec5SDimitry Andric buffer_sp->GetByteSize()); 214*0b57cec5SDimitry Andric } 215*0b57cec5SDimitry Andric } 216*0b57cec5SDimitry Andric return false; 217*0b57cec5SDimitry Andric } 218*0b57cec5SDimitry Andric if (reg_info->value_regs) { 219*0b57cec5SDimitry Andric // Process this composite register request by delegating to the 220*0b57cec5SDimitry Andric // constituent primordial registers. 221*0b57cec5SDimitry Andric 222*0b57cec5SDimitry Andric // Index of the primordial register. 223*0b57cec5SDimitry Andric bool success = true; 224*0b57cec5SDimitry Andric for (uint32_t idx = 0; success; ++idx) { 225*0b57cec5SDimitry Andric const uint32_t prim_reg = reg_info->value_regs[idx]; 226*0b57cec5SDimitry Andric if (prim_reg == LLDB_INVALID_REGNUM) 227*0b57cec5SDimitry Andric break; 228*0b57cec5SDimitry Andric // We have a valid primordial register as our constituent. Grab the 229*0b57cec5SDimitry Andric // corresponding register info. 230*0b57cec5SDimitry Andric const RegisterInfo *prim_reg_info = GetRegisterInfoAtIndex(prim_reg); 231*0b57cec5SDimitry Andric if (prim_reg_info == nullptr) 232*0b57cec5SDimitry Andric success = false; 233*0b57cec5SDimitry Andric else { 234*0b57cec5SDimitry Andric // Read the containing register if it hasn't already been read 235*0b57cec5SDimitry Andric if (!GetRegisterIsValid(prim_reg)) 236*0b57cec5SDimitry Andric success = GetPrimordialRegister(prim_reg_info, gdb_comm); 237*0b57cec5SDimitry Andric } 238*0b57cec5SDimitry Andric } 239*0b57cec5SDimitry Andric 240*0b57cec5SDimitry Andric if (success) { 241*0b57cec5SDimitry Andric // If we reach this point, all primordial register requests have 242*0b57cec5SDimitry Andric // succeeded. Validate this composite register. 243*0b57cec5SDimitry Andric SetRegisterIsValid(reg_info, true); 244*0b57cec5SDimitry Andric } 245*0b57cec5SDimitry Andric } else { 246*0b57cec5SDimitry Andric // Get each register individually 247*0b57cec5SDimitry Andric GetPrimordialRegister(reg_info, gdb_comm); 248*0b57cec5SDimitry Andric } 249*0b57cec5SDimitry Andric 250*0b57cec5SDimitry Andric // Make sure we got a valid register value after reading it 251*0b57cec5SDimitry Andric if (!GetRegisterIsValid(reg)) 252*0b57cec5SDimitry Andric return false; 253*0b57cec5SDimitry Andric } 254*0b57cec5SDimitry Andric 255*0b57cec5SDimitry Andric if (&data != &m_reg_data) { 256*0b57cec5SDimitry Andric assert(m_reg_data.GetByteSize() >= 257*0b57cec5SDimitry Andric reg_info->byte_offset + reg_info->byte_size); 258*0b57cec5SDimitry Andric // If our register context and our register info disagree, which should 259*0b57cec5SDimitry Andric // never happen, don't read past the end of the buffer. 260*0b57cec5SDimitry Andric if (m_reg_data.GetByteSize() < reg_info->byte_offset + reg_info->byte_size) 261*0b57cec5SDimitry Andric return false; 262*0b57cec5SDimitry Andric 263*0b57cec5SDimitry Andric // If we aren't extracting into our own buffer (which only happens when 264*0b57cec5SDimitry Andric // this function is called from ReadRegisterValue(uint32_t, Scalar&)) then 265*0b57cec5SDimitry Andric // we transfer bytes from our buffer into the data buffer that was passed 266*0b57cec5SDimitry Andric // in 267*0b57cec5SDimitry Andric 268*0b57cec5SDimitry Andric data.SetByteOrder(m_reg_data.GetByteOrder()); 269*0b57cec5SDimitry Andric data.SetData(m_reg_data, reg_info->byte_offset, reg_info->byte_size); 270*0b57cec5SDimitry Andric } 271*0b57cec5SDimitry Andric return true; 272*0b57cec5SDimitry Andric } 273*0b57cec5SDimitry Andric 274*0b57cec5SDimitry Andric bool GDBRemoteRegisterContext::WriteRegister(const RegisterInfo *reg_info, 275*0b57cec5SDimitry Andric const RegisterValue &value) { 276*0b57cec5SDimitry Andric DataExtractor data; 277*0b57cec5SDimitry Andric if (value.GetData(data)) 278*0b57cec5SDimitry Andric return WriteRegisterBytes(reg_info, data, 0); 279*0b57cec5SDimitry Andric return false; 280*0b57cec5SDimitry Andric } 281*0b57cec5SDimitry Andric 282*0b57cec5SDimitry Andric // Helper function for GDBRemoteRegisterContext::WriteRegisterBytes(). 283*0b57cec5SDimitry Andric bool GDBRemoteRegisterContext::SetPrimordialRegister( 284*0b57cec5SDimitry Andric const RegisterInfo *reg_info, GDBRemoteCommunicationClient &gdb_comm) { 285*0b57cec5SDimitry Andric StreamString packet; 286*0b57cec5SDimitry Andric StringExtractorGDBRemote response; 287*0b57cec5SDimitry Andric const uint32_t reg = reg_info->kinds[eRegisterKindLLDB]; 288*0b57cec5SDimitry Andric // Invalidate just this register 289*0b57cec5SDimitry Andric SetRegisterIsValid(reg, false); 290*0b57cec5SDimitry Andric 291*0b57cec5SDimitry Andric return gdb_comm.WriteRegister( 292*0b57cec5SDimitry Andric m_thread.GetProtocolID(), reg_info->kinds[eRegisterKindProcessPlugin], 293*0b57cec5SDimitry Andric {m_reg_data.PeekData(reg_info->byte_offset, reg_info->byte_size), 294*0b57cec5SDimitry Andric reg_info->byte_size}); 295*0b57cec5SDimitry Andric } 296*0b57cec5SDimitry Andric 297*0b57cec5SDimitry Andric bool GDBRemoteRegisterContext::WriteRegisterBytes(const RegisterInfo *reg_info, 298*0b57cec5SDimitry Andric DataExtractor &data, 299*0b57cec5SDimitry Andric uint32_t data_offset) { 300*0b57cec5SDimitry Andric ExecutionContext exe_ctx(CalculateThread()); 301*0b57cec5SDimitry Andric 302*0b57cec5SDimitry Andric Process *process = exe_ctx.GetProcessPtr(); 303*0b57cec5SDimitry Andric Thread *thread = exe_ctx.GetThreadPtr(); 304*0b57cec5SDimitry Andric if (process == nullptr || thread == nullptr) 305*0b57cec5SDimitry Andric return false; 306*0b57cec5SDimitry Andric 307*0b57cec5SDimitry Andric GDBRemoteCommunicationClient &gdb_comm( 308*0b57cec5SDimitry Andric ((ProcessGDBRemote *)process)->GetGDBRemote()); 309*0b57cec5SDimitry Andric 310*0b57cec5SDimitry Andric assert(m_reg_data.GetByteSize() >= 311*0b57cec5SDimitry Andric reg_info->byte_offset + reg_info->byte_size); 312*0b57cec5SDimitry Andric 313*0b57cec5SDimitry Andric // If our register context and our register info disagree, which should never 314*0b57cec5SDimitry Andric // happen, don't overwrite past the end of the buffer. 315*0b57cec5SDimitry Andric if (m_reg_data.GetByteSize() < reg_info->byte_offset + reg_info->byte_size) 316*0b57cec5SDimitry Andric return false; 317*0b57cec5SDimitry Andric 318*0b57cec5SDimitry Andric // Grab a pointer to where we are going to put this register 319*0b57cec5SDimitry Andric uint8_t *dst = const_cast<uint8_t *>( 320*0b57cec5SDimitry Andric m_reg_data.PeekData(reg_info->byte_offset, reg_info->byte_size)); 321*0b57cec5SDimitry Andric 322*0b57cec5SDimitry Andric if (dst == nullptr) 323*0b57cec5SDimitry Andric return false; 324*0b57cec5SDimitry Andric 325*0b57cec5SDimitry Andric if (data.CopyByteOrderedData(data_offset, // src offset 326*0b57cec5SDimitry Andric reg_info->byte_size, // src length 327*0b57cec5SDimitry Andric dst, // dst 328*0b57cec5SDimitry Andric reg_info->byte_size, // dst length 329*0b57cec5SDimitry Andric m_reg_data.GetByteOrder())) // dst byte order 330*0b57cec5SDimitry Andric { 331*0b57cec5SDimitry Andric GDBRemoteClientBase::Lock lock(gdb_comm, false); 332*0b57cec5SDimitry Andric if (lock) { 333*0b57cec5SDimitry Andric if (m_read_all_at_once) { 334*0b57cec5SDimitry Andric // Invalidate all register values 335*0b57cec5SDimitry Andric InvalidateIfNeeded(true); 336*0b57cec5SDimitry Andric 337*0b57cec5SDimitry Andric // Set all registers in one packet 338*0b57cec5SDimitry Andric if (gdb_comm.WriteAllRegisters( 339*0b57cec5SDimitry Andric m_thread.GetProtocolID(), 340*0b57cec5SDimitry Andric {m_reg_data.GetDataStart(), size_t(m_reg_data.GetByteSize())})) 341*0b57cec5SDimitry Andric 342*0b57cec5SDimitry Andric { 343*0b57cec5SDimitry Andric SetAllRegisterValid(false); 344*0b57cec5SDimitry Andric return true; 345*0b57cec5SDimitry Andric } 346*0b57cec5SDimitry Andric } else { 347*0b57cec5SDimitry Andric bool success = true; 348*0b57cec5SDimitry Andric 349*0b57cec5SDimitry Andric if (reg_info->value_regs) { 350*0b57cec5SDimitry Andric // This register is part of another register. In this case we read 351*0b57cec5SDimitry Andric // the actual register data for any "value_regs", and once all that 352*0b57cec5SDimitry Andric // data is read, we will have enough data in our register context 353*0b57cec5SDimitry Andric // bytes for the value of this register 354*0b57cec5SDimitry Andric 355*0b57cec5SDimitry Andric // Invalidate this composite register first. 356*0b57cec5SDimitry Andric 357*0b57cec5SDimitry Andric for (uint32_t idx = 0; success; ++idx) { 358*0b57cec5SDimitry Andric const uint32_t reg = reg_info->value_regs[idx]; 359*0b57cec5SDimitry Andric if (reg == LLDB_INVALID_REGNUM) 360*0b57cec5SDimitry Andric break; 361*0b57cec5SDimitry Andric // We have a valid primordial register as our constituent. Grab the 362*0b57cec5SDimitry Andric // corresponding register info. 363*0b57cec5SDimitry Andric const RegisterInfo *value_reg_info = GetRegisterInfoAtIndex(reg); 364*0b57cec5SDimitry Andric if (value_reg_info == nullptr) 365*0b57cec5SDimitry Andric success = false; 366*0b57cec5SDimitry Andric else 367*0b57cec5SDimitry Andric success = SetPrimordialRegister(value_reg_info, gdb_comm); 368*0b57cec5SDimitry Andric } 369*0b57cec5SDimitry Andric } else { 370*0b57cec5SDimitry Andric // This is an actual register, write it 371*0b57cec5SDimitry Andric success = SetPrimordialRegister(reg_info, gdb_comm); 372*0b57cec5SDimitry Andric } 373*0b57cec5SDimitry Andric 374*0b57cec5SDimitry Andric // Check if writing this register will invalidate any other register 375*0b57cec5SDimitry Andric // values? If so, invalidate them 376*0b57cec5SDimitry Andric if (reg_info->invalidate_regs) { 377*0b57cec5SDimitry Andric for (uint32_t idx = 0, reg = reg_info->invalidate_regs[0]; 378*0b57cec5SDimitry Andric reg != LLDB_INVALID_REGNUM; 379*0b57cec5SDimitry Andric reg = reg_info->invalidate_regs[++idx]) { 380*0b57cec5SDimitry Andric SetRegisterIsValid(reg, false); 381*0b57cec5SDimitry Andric } 382*0b57cec5SDimitry Andric } 383*0b57cec5SDimitry Andric 384*0b57cec5SDimitry Andric return success; 385*0b57cec5SDimitry Andric } 386*0b57cec5SDimitry Andric } else { 387*0b57cec5SDimitry Andric Log *log(ProcessGDBRemoteLog::GetLogIfAnyCategoryIsSet(GDBR_LOG_THREAD | 388*0b57cec5SDimitry Andric GDBR_LOG_PACKETS)); 389*0b57cec5SDimitry Andric if (log) { 390*0b57cec5SDimitry Andric if (log->GetVerbose()) { 391*0b57cec5SDimitry Andric StreamString strm; 392*0b57cec5SDimitry Andric gdb_comm.DumpHistory(strm); 393*0b57cec5SDimitry Andric log->Printf("error: failed to get packet sequence mutex, not sending " 394*0b57cec5SDimitry Andric "write register for \"%s\":\n%s", 395*0b57cec5SDimitry Andric reg_info->name, strm.GetData()); 396*0b57cec5SDimitry Andric } else 397*0b57cec5SDimitry Andric log->Printf("error: failed to get packet sequence mutex, not sending " 398*0b57cec5SDimitry Andric "write register for \"%s\"", 399*0b57cec5SDimitry Andric reg_info->name); 400*0b57cec5SDimitry Andric } 401*0b57cec5SDimitry Andric } 402*0b57cec5SDimitry Andric } 403*0b57cec5SDimitry Andric return false; 404*0b57cec5SDimitry Andric } 405*0b57cec5SDimitry Andric 406*0b57cec5SDimitry Andric bool GDBRemoteRegisterContext::ReadAllRegisterValues( 407*0b57cec5SDimitry Andric RegisterCheckpoint ®_checkpoint) { 408*0b57cec5SDimitry Andric ExecutionContext exe_ctx(CalculateThread()); 409*0b57cec5SDimitry Andric 410*0b57cec5SDimitry Andric Process *process = exe_ctx.GetProcessPtr(); 411*0b57cec5SDimitry Andric Thread *thread = exe_ctx.GetThreadPtr(); 412*0b57cec5SDimitry Andric if (process == nullptr || thread == nullptr) 413*0b57cec5SDimitry Andric return false; 414*0b57cec5SDimitry Andric 415*0b57cec5SDimitry Andric GDBRemoteCommunicationClient &gdb_comm( 416*0b57cec5SDimitry Andric ((ProcessGDBRemote *)process)->GetGDBRemote()); 417*0b57cec5SDimitry Andric 418*0b57cec5SDimitry Andric uint32_t save_id = 0; 419*0b57cec5SDimitry Andric if (gdb_comm.SaveRegisterState(thread->GetProtocolID(), save_id)) { 420*0b57cec5SDimitry Andric reg_checkpoint.SetID(save_id); 421*0b57cec5SDimitry Andric reg_checkpoint.GetData().reset(); 422*0b57cec5SDimitry Andric return true; 423*0b57cec5SDimitry Andric } else { 424*0b57cec5SDimitry Andric reg_checkpoint.SetID(0); // Invalid save ID is zero 425*0b57cec5SDimitry Andric return ReadAllRegisterValues(reg_checkpoint.GetData()); 426*0b57cec5SDimitry Andric } 427*0b57cec5SDimitry Andric } 428*0b57cec5SDimitry Andric 429*0b57cec5SDimitry Andric bool GDBRemoteRegisterContext::WriteAllRegisterValues( 430*0b57cec5SDimitry Andric const RegisterCheckpoint ®_checkpoint) { 431*0b57cec5SDimitry Andric uint32_t save_id = reg_checkpoint.GetID(); 432*0b57cec5SDimitry Andric if (save_id != 0) { 433*0b57cec5SDimitry Andric ExecutionContext exe_ctx(CalculateThread()); 434*0b57cec5SDimitry Andric 435*0b57cec5SDimitry Andric Process *process = exe_ctx.GetProcessPtr(); 436*0b57cec5SDimitry Andric Thread *thread = exe_ctx.GetThreadPtr(); 437*0b57cec5SDimitry Andric if (process == nullptr || thread == nullptr) 438*0b57cec5SDimitry Andric return false; 439*0b57cec5SDimitry Andric 440*0b57cec5SDimitry Andric GDBRemoteCommunicationClient &gdb_comm( 441*0b57cec5SDimitry Andric ((ProcessGDBRemote *)process)->GetGDBRemote()); 442*0b57cec5SDimitry Andric 443*0b57cec5SDimitry Andric return gdb_comm.RestoreRegisterState(m_thread.GetProtocolID(), save_id); 444*0b57cec5SDimitry Andric } else { 445*0b57cec5SDimitry Andric return WriteAllRegisterValues(reg_checkpoint.GetData()); 446*0b57cec5SDimitry Andric } 447*0b57cec5SDimitry Andric } 448*0b57cec5SDimitry Andric 449*0b57cec5SDimitry Andric bool GDBRemoteRegisterContext::ReadAllRegisterValues( 450*0b57cec5SDimitry Andric lldb::DataBufferSP &data_sp) { 451*0b57cec5SDimitry Andric ExecutionContext exe_ctx(CalculateThread()); 452*0b57cec5SDimitry Andric 453*0b57cec5SDimitry Andric Process *process = exe_ctx.GetProcessPtr(); 454*0b57cec5SDimitry Andric Thread *thread = exe_ctx.GetThreadPtr(); 455*0b57cec5SDimitry Andric if (process == nullptr || thread == nullptr) 456*0b57cec5SDimitry Andric return false; 457*0b57cec5SDimitry Andric 458*0b57cec5SDimitry Andric GDBRemoteCommunicationClient &gdb_comm( 459*0b57cec5SDimitry Andric ((ProcessGDBRemote *)process)->GetGDBRemote()); 460*0b57cec5SDimitry Andric 461*0b57cec5SDimitry Andric const bool use_g_packet = 462*0b57cec5SDimitry Andric !gdb_comm.AvoidGPackets((ProcessGDBRemote *)process); 463*0b57cec5SDimitry Andric 464*0b57cec5SDimitry Andric GDBRemoteClientBase::Lock lock(gdb_comm, false); 465*0b57cec5SDimitry Andric if (lock) { 466*0b57cec5SDimitry Andric if (gdb_comm.SyncThreadState(m_thread.GetProtocolID())) 467*0b57cec5SDimitry Andric InvalidateAllRegisters(); 468*0b57cec5SDimitry Andric 469*0b57cec5SDimitry Andric if (use_g_packet && 470*0b57cec5SDimitry Andric (data_sp = gdb_comm.ReadAllRegisters(m_thread.GetProtocolID()))) 471*0b57cec5SDimitry Andric return true; 472*0b57cec5SDimitry Andric 473*0b57cec5SDimitry Andric // We're going to read each register 474*0b57cec5SDimitry Andric // individually and store them as binary data in a buffer. 475*0b57cec5SDimitry Andric const RegisterInfo *reg_info; 476*0b57cec5SDimitry Andric 477*0b57cec5SDimitry Andric for (uint32_t i = 0; (reg_info = GetRegisterInfoAtIndex(i)) != nullptr; 478*0b57cec5SDimitry Andric i++) { 479*0b57cec5SDimitry Andric if (reg_info 480*0b57cec5SDimitry Andric ->value_regs) // skip registers that are slices of real registers 481*0b57cec5SDimitry Andric continue; 482*0b57cec5SDimitry Andric ReadRegisterBytes(reg_info, m_reg_data); 483*0b57cec5SDimitry Andric // ReadRegisterBytes saves the contents of the register in to the 484*0b57cec5SDimitry Andric // m_reg_data buffer 485*0b57cec5SDimitry Andric } 486*0b57cec5SDimitry Andric data_sp = std::make_shared<DataBufferHeap>( 487*0b57cec5SDimitry Andric m_reg_data.GetDataStart(), m_reg_info.GetRegisterDataByteSize()); 488*0b57cec5SDimitry Andric return true; 489*0b57cec5SDimitry Andric } else { 490*0b57cec5SDimitry Andric 491*0b57cec5SDimitry Andric Log *log(ProcessGDBRemoteLog::GetLogIfAnyCategoryIsSet(GDBR_LOG_THREAD | 492*0b57cec5SDimitry Andric GDBR_LOG_PACKETS)); 493*0b57cec5SDimitry Andric if (log) { 494*0b57cec5SDimitry Andric if (log->GetVerbose()) { 495*0b57cec5SDimitry Andric StreamString strm; 496*0b57cec5SDimitry Andric gdb_comm.DumpHistory(strm); 497*0b57cec5SDimitry Andric log->Printf("error: failed to get packet sequence mutex, not sending " 498*0b57cec5SDimitry Andric "read all registers:\n%s", 499*0b57cec5SDimitry Andric strm.GetData()); 500*0b57cec5SDimitry Andric } else 501*0b57cec5SDimitry Andric log->Printf("error: failed to get packet sequence mutex, not sending " 502*0b57cec5SDimitry Andric "read all registers"); 503*0b57cec5SDimitry Andric } 504*0b57cec5SDimitry Andric } 505*0b57cec5SDimitry Andric 506*0b57cec5SDimitry Andric data_sp.reset(); 507*0b57cec5SDimitry Andric return false; 508*0b57cec5SDimitry Andric } 509*0b57cec5SDimitry Andric 510*0b57cec5SDimitry Andric bool GDBRemoteRegisterContext::WriteAllRegisterValues( 511*0b57cec5SDimitry Andric const lldb::DataBufferSP &data_sp) { 512*0b57cec5SDimitry Andric if (!data_sp || data_sp->GetBytes() == nullptr || data_sp->GetByteSize() == 0) 513*0b57cec5SDimitry Andric return false; 514*0b57cec5SDimitry Andric 515*0b57cec5SDimitry Andric ExecutionContext exe_ctx(CalculateThread()); 516*0b57cec5SDimitry Andric 517*0b57cec5SDimitry Andric Process *process = exe_ctx.GetProcessPtr(); 518*0b57cec5SDimitry Andric Thread *thread = exe_ctx.GetThreadPtr(); 519*0b57cec5SDimitry Andric if (process == nullptr || thread == nullptr) 520*0b57cec5SDimitry Andric return false; 521*0b57cec5SDimitry Andric 522*0b57cec5SDimitry Andric GDBRemoteCommunicationClient &gdb_comm( 523*0b57cec5SDimitry Andric ((ProcessGDBRemote *)process)->GetGDBRemote()); 524*0b57cec5SDimitry Andric 525*0b57cec5SDimitry Andric const bool use_g_packet = 526*0b57cec5SDimitry Andric !gdb_comm.AvoidGPackets((ProcessGDBRemote *)process); 527*0b57cec5SDimitry Andric 528*0b57cec5SDimitry Andric GDBRemoteClientBase::Lock lock(gdb_comm, false); 529*0b57cec5SDimitry Andric if (lock) { 530*0b57cec5SDimitry Andric // The data_sp contains the G response packet. 531*0b57cec5SDimitry Andric if (use_g_packet) { 532*0b57cec5SDimitry Andric if (gdb_comm.WriteAllRegisters( 533*0b57cec5SDimitry Andric m_thread.GetProtocolID(), 534*0b57cec5SDimitry Andric {data_sp->GetBytes(), size_t(data_sp->GetByteSize())})) 535*0b57cec5SDimitry Andric return true; 536*0b57cec5SDimitry Andric 537*0b57cec5SDimitry Andric uint32_t num_restored = 0; 538*0b57cec5SDimitry Andric // We need to manually go through all of the registers and restore them 539*0b57cec5SDimitry Andric // manually 540*0b57cec5SDimitry Andric DataExtractor restore_data(data_sp, m_reg_data.GetByteOrder(), 541*0b57cec5SDimitry Andric m_reg_data.GetAddressByteSize()); 542*0b57cec5SDimitry Andric 543*0b57cec5SDimitry Andric const RegisterInfo *reg_info; 544*0b57cec5SDimitry Andric 545*0b57cec5SDimitry Andric // The g packet contents may either include the slice registers 546*0b57cec5SDimitry Andric // (registers defined in terms of other registers, e.g. eax is a subset 547*0b57cec5SDimitry Andric // of rax) or not. The slice registers should NOT be in the g packet, 548*0b57cec5SDimitry Andric // but some implementations may incorrectly include them. 549*0b57cec5SDimitry Andric // 550*0b57cec5SDimitry Andric // If the slice registers are included in the packet, we must step over 551*0b57cec5SDimitry Andric // the slice registers when parsing the packet -- relying on the 552*0b57cec5SDimitry Andric // RegisterInfo byte_offset field would be incorrect. If the slice 553*0b57cec5SDimitry Andric // registers are not included, then using the byte_offset values into the 554*0b57cec5SDimitry Andric // data buffer is the best way to find individual register values. 555*0b57cec5SDimitry Andric 556*0b57cec5SDimitry Andric uint64_t size_including_slice_registers = 0; 557*0b57cec5SDimitry Andric uint64_t size_not_including_slice_registers = 0; 558*0b57cec5SDimitry Andric uint64_t size_by_highest_offset = 0; 559*0b57cec5SDimitry Andric 560*0b57cec5SDimitry Andric for (uint32_t reg_idx = 0; 561*0b57cec5SDimitry Andric (reg_info = GetRegisterInfoAtIndex(reg_idx)) != nullptr; ++reg_idx) { 562*0b57cec5SDimitry Andric size_including_slice_registers += reg_info->byte_size; 563*0b57cec5SDimitry Andric if (reg_info->value_regs == nullptr) 564*0b57cec5SDimitry Andric size_not_including_slice_registers += reg_info->byte_size; 565*0b57cec5SDimitry Andric if (reg_info->byte_offset >= size_by_highest_offset) 566*0b57cec5SDimitry Andric size_by_highest_offset = reg_info->byte_offset + reg_info->byte_size; 567*0b57cec5SDimitry Andric } 568*0b57cec5SDimitry Andric 569*0b57cec5SDimitry Andric bool use_byte_offset_into_buffer; 570*0b57cec5SDimitry Andric if (size_by_highest_offset == restore_data.GetByteSize()) { 571*0b57cec5SDimitry Andric // The size of the packet agrees with the highest offset: + size in the 572*0b57cec5SDimitry Andric // register file 573*0b57cec5SDimitry Andric use_byte_offset_into_buffer = true; 574*0b57cec5SDimitry Andric } else if (size_not_including_slice_registers == 575*0b57cec5SDimitry Andric restore_data.GetByteSize()) { 576*0b57cec5SDimitry Andric // The size of the packet is the same as concatenating all of the 577*0b57cec5SDimitry Andric // registers sequentially, skipping the slice registers 578*0b57cec5SDimitry Andric use_byte_offset_into_buffer = true; 579*0b57cec5SDimitry Andric } else if (size_including_slice_registers == restore_data.GetByteSize()) { 580*0b57cec5SDimitry Andric // The slice registers are present in the packet (when they shouldn't 581*0b57cec5SDimitry Andric // be). Don't try to use the RegisterInfo byte_offset into the 582*0b57cec5SDimitry Andric // restore_data, it will point to the wrong place. 583*0b57cec5SDimitry Andric use_byte_offset_into_buffer = false; 584*0b57cec5SDimitry Andric } else { 585*0b57cec5SDimitry Andric // None of our expected sizes match the actual g packet data we're 586*0b57cec5SDimitry Andric // looking at. The most conservative approach here is to use the 587*0b57cec5SDimitry Andric // running total byte offset. 588*0b57cec5SDimitry Andric use_byte_offset_into_buffer = false; 589*0b57cec5SDimitry Andric } 590*0b57cec5SDimitry Andric 591*0b57cec5SDimitry Andric // In case our register definitions don't include the correct offsets, 592*0b57cec5SDimitry Andric // keep track of the size of each reg & compute offset based on that. 593*0b57cec5SDimitry Andric uint32_t running_byte_offset = 0; 594*0b57cec5SDimitry Andric for (uint32_t reg_idx = 0; 595*0b57cec5SDimitry Andric (reg_info = GetRegisterInfoAtIndex(reg_idx)) != nullptr; 596*0b57cec5SDimitry Andric ++reg_idx, running_byte_offset += reg_info->byte_size) { 597*0b57cec5SDimitry Andric // Skip composite aka slice registers (e.g. eax is a slice of rax). 598*0b57cec5SDimitry Andric if (reg_info->value_regs) 599*0b57cec5SDimitry Andric continue; 600*0b57cec5SDimitry Andric 601*0b57cec5SDimitry Andric const uint32_t reg = reg_info->kinds[eRegisterKindLLDB]; 602*0b57cec5SDimitry Andric 603*0b57cec5SDimitry Andric uint32_t register_offset; 604*0b57cec5SDimitry Andric if (use_byte_offset_into_buffer) { 605*0b57cec5SDimitry Andric register_offset = reg_info->byte_offset; 606*0b57cec5SDimitry Andric } else { 607*0b57cec5SDimitry Andric register_offset = running_byte_offset; 608*0b57cec5SDimitry Andric } 609*0b57cec5SDimitry Andric 610*0b57cec5SDimitry Andric const uint32_t reg_byte_size = reg_info->byte_size; 611*0b57cec5SDimitry Andric 612*0b57cec5SDimitry Andric const uint8_t *restore_src = 613*0b57cec5SDimitry Andric restore_data.PeekData(register_offset, reg_byte_size); 614*0b57cec5SDimitry Andric if (restore_src) { 615*0b57cec5SDimitry Andric SetRegisterIsValid(reg, false); 616*0b57cec5SDimitry Andric if (gdb_comm.WriteRegister( 617*0b57cec5SDimitry Andric m_thread.GetProtocolID(), 618*0b57cec5SDimitry Andric reg_info->kinds[eRegisterKindProcessPlugin], 619*0b57cec5SDimitry Andric {restore_src, reg_byte_size})) 620*0b57cec5SDimitry Andric ++num_restored; 621*0b57cec5SDimitry Andric } 622*0b57cec5SDimitry Andric } 623*0b57cec5SDimitry Andric return num_restored > 0; 624*0b57cec5SDimitry Andric } else { 625*0b57cec5SDimitry Andric // For the use_g_packet == false case, we're going to write each register 626*0b57cec5SDimitry Andric // individually. The data buffer is binary data in this case, instead of 627*0b57cec5SDimitry Andric // ascii characters. 628*0b57cec5SDimitry Andric 629*0b57cec5SDimitry Andric bool arm64_debugserver = false; 630*0b57cec5SDimitry Andric if (m_thread.GetProcess().get()) { 631*0b57cec5SDimitry Andric const ArchSpec &arch = 632*0b57cec5SDimitry Andric m_thread.GetProcess()->GetTarget().GetArchitecture(); 633*0b57cec5SDimitry Andric if (arch.IsValid() && arch.GetMachine() == llvm::Triple::aarch64 && 634*0b57cec5SDimitry Andric arch.GetTriple().getVendor() == llvm::Triple::Apple && 635*0b57cec5SDimitry Andric arch.GetTriple().getOS() == llvm::Triple::IOS) { 636*0b57cec5SDimitry Andric arm64_debugserver = true; 637*0b57cec5SDimitry Andric } 638*0b57cec5SDimitry Andric } 639*0b57cec5SDimitry Andric uint32_t num_restored = 0; 640*0b57cec5SDimitry Andric const RegisterInfo *reg_info; 641*0b57cec5SDimitry Andric for (uint32_t i = 0; (reg_info = GetRegisterInfoAtIndex(i)) != nullptr; 642*0b57cec5SDimitry Andric i++) { 643*0b57cec5SDimitry Andric if (reg_info->value_regs) // skip registers that are slices of real 644*0b57cec5SDimitry Andric // registers 645*0b57cec5SDimitry Andric continue; 646*0b57cec5SDimitry Andric // Skip the fpsr and fpcr floating point status/control register 647*0b57cec5SDimitry Andric // writing to work around a bug in an older version of debugserver that 648*0b57cec5SDimitry Andric // would lead to register context corruption when writing fpsr/fpcr. 649*0b57cec5SDimitry Andric if (arm64_debugserver && (strcmp(reg_info->name, "fpsr") == 0 || 650*0b57cec5SDimitry Andric strcmp(reg_info->name, "fpcr") == 0)) { 651*0b57cec5SDimitry Andric continue; 652*0b57cec5SDimitry Andric } 653*0b57cec5SDimitry Andric 654*0b57cec5SDimitry Andric SetRegisterIsValid(reg_info, false); 655*0b57cec5SDimitry Andric if (gdb_comm.WriteRegister(m_thread.GetProtocolID(), 656*0b57cec5SDimitry Andric reg_info->kinds[eRegisterKindProcessPlugin], 657*0b57cec5SDimitry Andric {data_sp->GetBytes() + reg_info->byte_offset, 658*0b57cec5SDimitry Andric reg_info->byte_size})) 659*0b57cec5SDimitry Andric ++num_restored; 660*0b57cec5SDimitry Andric } 661*0b57cec5SDimitry Andric return num_restored > 0; 662*0b57cec5SDimitry Andric } 663*0b57cec5SDimitry Andric } else { 664*0b57cec5SDimitry Andric Log *log(ProcessGDBRemoteLog::GetLogIfAnyCategoryIsSet(GDBR_LOG_THREAD | 665*0b57cec5SDimitry Andric GDBR_LOG_PACKETS)); 666*0b57cec5SDimitry Andric if (log) { 667*0b57cec5SDimitry Andric if (log->GetVerbose()) { 668*0b57cec5SDimitry Andric StreamString strm; 669*0b57cec5SDimitry Andric gdb_comm.DumpHistory(strm); 670*0b57cec5SDimitry Andric log->Printf("error: failed to get packet sequence mutex, not sending " 671*0b57cec5SDimitry Andric "write all registers:\n%s", 672*0b57cec5SDimitry Andric strm.GetData()); 673*0b57cec5SDimitry Andric } else 674*0b57cec5SDimitry Andric log->Printf("error: failed to get packet sequence mutex, not sending " 675*0b57cec5SDimitry Andric "write all registers"); 676*0b57cec5SDimitry Andric } 677*0b57cec5SDimitry Andric } 678*0b57cec5SDimitry Andric return false; 679*0b57cec5SDimitry Andric } 680*0b57cec5SDimitry Andric 681*0b57cec5SDimitry Andric uint32_t GDBRemoteRegisterContext::ConvertRegisterKindToRegisterNumber( 682*0b57cec5SDimitry Andric lldb::RegisterKind kind, uint32_t num) { 683*0b57cec5SDimitry Andric return m_reg_info.ConvertRegisterKindToRegisterNumber(kind, num); 684*0b57cec5SDimitry Andric } 685*0b57cec5SDimitry Andric 686*0b57cec5SDimitry Andric void GDBRemoteDynamicRegisterInfo::HardcodeARMRegisters(bool from_scratch) { 687*0b57cec5SDimitry Andric // For Advanced SIMD and VFP register mapping. 688*0b57cec5SDimitry Andric static uint32_t g_d0_regs[] = {26, 27, LLDB_INVALID_REGNUM}; // (s0, s1) 689*0b57cec5SDimitry Andric static uint32_t g_d1_regs[] = {28, 29, LLDB_INVALID_REGNUM}; // (s2, s3) 690*0b57cec5SDimitry Andric static uint32_t g_d2_regs[] = {30, 31, LLDB_INVALID_REGNUM}; // (s4, s5) 691*0b57cec5SDimitry Andric static uint32_t g_d3_regs[] = {32, 33, LLDB_INVALID_REGNUM}; // (s6, s7) 692*0b57cec5SDimitry Andric static uint32_t g_d4_regs[] = {34, 35, LLDB_INVALID_REGNUM}; // (s8, s9) 693*0b57cec5SDimitry Andric static uint32_t g_d5_regs[] = {36, 37, LLDB_INVALID_REGNUM}; // (s10, s11) 694*0b57cec5SDimitry Andric static uint32_t g_d6_regs[] = {38, 39, LLDB_INVALID_REGNUM}; // (s12, s13) 695*0b57cec5SDimitry Andric static uint32_t g_d7_regs[] = {40, 41, LLDB_INVALID_REGNUM}; // (s14, s15) 696*0b57cec5SDimitry Andric static uint32_t g_d8_regs[] = {42, 43, LLDB_INVALID_REGNUM}; // (s16, s17) 697*0b57cec5SDimitry Andric static uint32_t g_d9_regs[] = {44, 45, LLDB_INVALID_REGNUM}; // (s18, s19) 698*0b57cec5SDimitry Andric static uint32_t g_d10_regs[] = {46, 47, LLDB_INVALID_REGNUM}; // (s20, s21) 699*0b57cec5SDimitry Andric static uint32_t g_d11_regs[] = {48, 49, LLDB_INVALID_REGNUM}; // (s22, s23) 700*0b57cec5SDimitry Andric static uint32_t g_d12_regs[] = {50, 51, LLDB_INVALID_REGNUM}; // (s24, s25) 701*0b57cec5SDimitry Andric static uint32_t g_d13_regs[] = {52, 53, LLDB_INVALID_REGNUM}; // (s26, s27) 702*0b57cec5SDimitry Andric static uint32_t g_d14_regs[] = {54, 55, LLDB_INVALID_REGNUM}; // (s28, s29) 703*0b57cec5SDimitry Andric static uint32_t g_d15_regs[] = {56, 57, LLDB_INVALID_REGNUM}; // (s30, s31) 704*0b57cec5SDimitry Andric static uint32_t g_q0_regs[] = { 705*0b57cec5SDimitry Andric 26, 27, 28, 29, LLDB_INVALID_REGNUM}; // (d0, d1) -> (s0, s1, s2, s3) 706*0b57cec5SDimitry Andric static uint32_t g_q1_regs[] = { 707*0b57cec5SDimitry Andric 30, 31, 32, 33, LLDB_INVALID_REGNUM}; // (d2, d3) -> (s4, s5, s6, s7) 708*0b57cec5SDimitry Andric static uint32_t g_q2_regs[] = { 709*0b57cec5SDimitry Andric 34, 35, 36, 37, LLDB_INVALID_REGNUM}; // (d4, d5) -> (s8, s9, s10, s11) 710*0b57cec5SDimitry Andric static uint32_t g_q3_regs[] = { 711*0b57cec5SDimitry Andric 38, 39, 40, 41, LLDB_INVALID_REGNUM}; // (d6, d7) -> (s12, s13, s14, s15) 712*0b57cec5SDimitry Andric static uint32_t g_q4_regs[] = { 713*0b57cec5SDimitry Andric 42, 43, 44, 45, LLDB_INVALID_REGNUM}; // (d8, d9) -> (s16, s17, s18, s19) 714*0b57cec5SDimitry Andric static uint32_t g_q5_regs[] = { 715*0b57cec5SDimitry Andric 46, 47, 48, 49, 716*0b57cec5SDimitry Andric LLDB_INVALID_REGNUM}; // (d10, d11) -> (s20, s21, s22, s23) 717*0b57cec5SDimitry Andric static uint32_t g_q6_regs[] = { 718*0b57cec5SDimitry Andric 50, 51, 52, 53, 719*0b57cec5SDimitry Andric LLDB_INVALID_REGNUM}; // (d12, d13) -> (s24, s25, s26, s27) 720*0b57cec5SDimitry Andric static uint32_t g_q7_regs[] = { 721*0b57cec5SDimitry Andric 54, 55, 56, 57, 722*0b57cec5SDimitry Andric LLDB_INVALID_REGNUM}; // (d14, d15) -> (s28, s29, s30, s31) 723*0b57cec5SDimitry Andric static uint32_t g_q8_regs[] = {59, 60, LLDB_INVALID_REGNUM}; // (d16, d17) 724*0b57cec5SDimitry Andric static uint32_t g_q9_regs[] = {61, 62, LLDB_INVALID_REGNUM}; // (d18, d19) 725*0b57cec5SDimitry Andric static uint32_t g_q10_regs[] = {63, 64, LLDB_INVALID_REGNUM}; // (d20, d21) 726*0b57cec5SDimitry Andric static uint32_t g_q11_regs[] = {65, 66, LLDB_INVALID_REGNUM}; // (d22, d23) 727*0b57cec5SDimitry Andric static uint32_t g_q12_regs[] = {67, 68, LLDB_INVALID_REGNUM}; // (d24, d25) 728*0b57cec5SDimitry Andric static uint32_t g_q13_regs[] = {69, 70, LLDB_INVALID_REGNUM}; // (d26, d27) 729*0b57cec5SDimitry Andric static uint32_t g_q14_regs[] = {71, 72, LLDB_INVALID_REGNUM}; // (d28, d29) 730*0b57cec5SDimitry Andric static uint32_t g_q15_regs[] = {73, 74, LLDB_INVALID_REGNUM}; // (d30, d31) 731*0b57cec5SDimitry Andric 732*0b57cec5SDimitry Andric // This is our array of composite registers, with each element coming from 733*0b57cec5SDimitry Andric // the above register mappings. 734*0b57cec5SDimitry Andric static uint32_t *g_composites[] = { 735*0b57cec5SDimitry Andric g_d0_regs, g_d1_regs, g_d2_regs, g_d3_regs, g_d4_regs, g_d5_regs, 736*0b57cec5SDimitry Andric g_d6_regs, g_d7_regs, g_d8_regs, g_d9_regs, g_d10_regs, g_d11_regs, 737*0b57cec5SDimitry Andric g_d12_regs, g_d13_regs, g_d14_regs, g_d15_regs, g_q0_regs, g_q1_regs, 738*0b57cec5SDimitry Andric g_q2_regs, g_q3_regs, g_q4_regs, g_q5_regs, g_q6_regs, g_q7_regs, 739*0b57cec5SDimitry Andric g_q8_regs, g_q9_regs, g_q10_regs, g_q11_regs, g_q12_regs, g_q13_regs, 740*0b57cec5SDimitry Andric g_q14_regs, g_q15_regs}; 741*0b57cec5SDimitry Andric 742*0b57cec5SDimitry Andric // clang-format off 743*0b57cec5SDimitry Andric static RegisterInfo g_register_infos[] = { 744*0b57cec5SDimitry Andric // NAME ALT SZ OFF ENCODING FORMAT EH_FRAME DWARF GENERIC PROCESS PLUGIN LLDB VALUE REGS INVALIDATE REGS SIZE EXPR SIZE LEN 745*0b57cec5SDimitry Andric // ====== ====== === === ============= ========== =================== =================== ====================== ============= ==== ========== =============== ========= ======== 746*0b57cec5SDimitry Andric { "r0", "arg1", 4, 0, eEncodingUint, eFormatHex, { ehframe_r0, dwarf_r0, LLDB_REGNUM_GENERIC_ARG1,0, 0 }, nullptr, nullptr, nullptr, 0 }, 747*0b57cec5SDimitry Andric { "r1", "arg2", 4, 0, eEncodingUint, eFormatHex, { ehframe_r1, dwarf_r1, LLDB_REGNUM_GENERIC_ARG2,1, 1 }, nullptr, nullptr, nullptr, 0 }, 748*0b57cec5SDimitry Andric { "r2", "arg3", 4, 0, eEncodingUint, eFormatHex, { ehframe_r2, dwarf_r2, LLDB_REGNUM_GENERIC_ARG3,2, 2 }, nullptr, nullptr, nullptr, 0 }, 749*0b57cec5SDimitry Andric { "r3", "arg4", 4, 0, eEncodingUint, eFormatHex, { ehframe_r3, dwarf_r3, LLDB_REGNUM_GENERIC_ARG4,3, 3 }, nullptr, nullptr, nullptr, 0 }, 750*0b57cec5SDimitry Andric { "r4", nullptr, 4, 0, eEncodingUint, eFormatHex, { ehframe_r4, dwarf_r4, LLDB_INVALID_REGNUM, 4, 4 }, nullptr, nullptr, nullptr, 0 }, 751*0b57cec5SDimitry Andric { "r5", nullptr, 4, 0, eEncodingUint, eFormatHex, { ehframe_r5, dwarf_r5, LLDB_INVALID_REGNUM, 5, 5 }, nullptr, nullptr, nullptr, 0 }, 752*0b57cec5SDimitry Andric { "r6", nullptr, 4, 0, eEncodingUint, eFormatHex, { ehframe_r6, dwarf_r6, LLDB_INVALID_REGNUM, 6, 6 }, nullptr, nullptr, nullptr, 0 }, 753*0b57cec5SDimitry Andric { "r7", "fp", 4, 0, eEncodingUint, eFormatHex, { ehframe_r7, dwarf_r7, LLDB_REGNUM_GENERIC_FP, 7, 7 }, nullptr, nullptr, nullptr, 0 }, 754*0b57cec5SDimitry Andric { "r8", nullptr, 4, 0, eEncodingUint, eFormatHex, { ehframe_r8, dwarf_r8, LLDB_INVALID_REGNUM, 8, 8 }, nullptr, nullptr, nullptr, 0 }, 755*0b57cec5SDimitry Andric { "r9", nullptr, 4, 0, eEncodingUint, eFormatHex, { ehframe_r9, dwarf_r9, LLDB_INVALID_REGNUM, 9, 9 }, nullptr, nullptr, nullptr, 0 }, 756*0b57cec5SDimitry Andric { "r10", nullptr, 4, 0, eEncodingUint, eFormatHex, { ehframe_r10, dwarf_r10, LLDB_INVALID_REGNUM, 10, 10 }, nullptr, nullptr, nullptr, 0 }, 757*0b57cec5SDimitry Andric { "r11", nullptr, 4, 0, eEncodingUint, eFormatHex, { ehframe_r11, dwarf_r11, LLDB_INVALID_REGNUM, 11, 11 }, nullptr, nullptr, nullptr, 0 }, 758*0b57cec5SDimitry Andric { "r12", nullptr, 4, 0, eEncodingUint, eFormatHex, { ehframe_r12, dwarf_r12, LLDB_INVALID_REGNUM, 12, 12 }, nullptr, nullptr, nullptr, 0 }, 759*0b57cec5SDimitry Andric { "sp", "r13", 4, 0, eEncodingUint, eFormatHex, { ehframe_sp, dwarf_sp, LLDB_REGNUM_GENERIC_SP, 13, 13 }, nullptr, nullptr, nullptr, 0 }, 760*0b57cec5SDimitry Andric { "lr", "r14", 4, 0, eEncodingUint, eFormatHex, { ehframe_lr, dwarf_lr, LLDB_REGNUM_GENERIC_RA, 14, 14 }, nullptr, nullptr, nullptr, 0 }, 761*0b57cec5SDimitry Andric { "pc", "r15", 4, 0, eEncodingUint, eFormatHex, { ehframe_pc, dwarf_pc, LLDB_REGNUM_GENERIC_PC, 15, 15 }, nullptr, nullptr, nullptr, 0 }, 762*0b57cec5SDimitry Andric { "f0", nullptr, 12, 0, eEncodingUint, eFormatHex, { LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM, 16, 16 }, nullptr, nullptr, nullptr, 0 }, 763*0b57cec5SDimitry Andric { "f1", nullptr, 12, 0, eEncodingUint, eFormatHex, { LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM, 17, 17 }, nullptr, nullptr, nullptr, 0 }, 764*0b57cec5SDimitry Andric { "f2", nullptr, 12, 0, eEncodingUint, eFormatHex, { LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM, 18, 18 }, nullptr, nullptr, nullptr, 0 }, 765*0b57cec5SDimitry Andric { "f3", nullptr, 12, 0, eEncodingUint, eFormatHex, { LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM, 19, 19 }, nullptr, nullptr, nullptr, 0 }, 766*0b57cec5SDimitry Andric { "f4", nullptr, 12, 0, eEncodingUint, eFormatHex, { LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM, 20, 20 }, nullptr, nullptr, nullptr, 0 }, 767*0b57cec5SDimitry Andric { "f5", nullptr, 12, 0, eEncodingUint, eFormatHex, { LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM, 21, 21 }, nullptr, nullptr, nullptr, 0 }, 768*0b57cec5SDimitry Andric { "f6", nullptr, 12, 0, eEncodingUint, eFormatHex, { LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM, 22, 22 }, nullptr, nullptr, nullptr, 0 }, 769*0b57cec5SDimitry Andric { "f7", nullptr, 12, 0, eEncodingUint, eFormatHex, { LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM, 23, 23 }, nullptr, nullptr, nullptr, 0 }, 770*0b57cec5SDimitry Andric { "fps", nullptr, 4, 0, eEncodingUint, eFormatHex, { LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM, 24, 24 }, nullptr, nullptr, nullptr, 0 }, 771*0b57cec5SDimitry Andric { "cpsr","flags", 4, 0, eEncodingUint, eFormatHex, { ehframe_cpsr, dwarf_cpsr, LLDB_INVALID_REGNUM, 25, 25 }, nullptr, nullptr, nullptr, 0 }, 772*0b57cec5SDimitry Andric { "s0", nullptr, 4, 0, eEncodingIEEE754, eFormatFloat, { LLDB_INVALID_REGNUM, dwarf_s0, LLDB_INVALID_REGNUM, 26, 26 }, nullptr, nullptr, nullptr, 0 }, 773*0b57cec5SDimitry Andric { "s1", nullptr, 4, 0, eEncodingIEEE754, eFormatFloat, { LLDB_INVALID_REGNUM, dwarf_s1, LLDB_INVALID_REGNUM, 27, 27 }, nullptr, nullptr, nullptr, 0 }, 774*0b57cec5SDimitry Andric { "s2", nullptr, 4, 0, eEncodingIEEE754, eFormatFloat, { LLDB_INVALID_REGNUM, dwarf_s2, LLDB_INVALID_REGNUM, 28, 28 }, nullptr, nullptr, nullptr, 0 }, 775*0b57cec5SDimitry Andric { "s3", nullptr, 4, 0, eEncodingIEEE754, eFormatFloat, { LLDB_INVALID_REGNUM, dwarf_s3, LLDB_INVALID_REGNUM, 29, 29 }, nullptr, nullptr, nullptr, 0 }, 776*0b57cec5SDimitry Andric { "s4", nullptr, 4, 0, eEncodingIEEE754, eFormatFloat, { LLDB_INVALID_REGNUM, dwarf_s4, LLDB_INVALID_REGNUM, 30, 30 }, nullptr, nullptr, nullptr, 0 }, 777*0b57cec5SDimitry Andric { "s5", nullptr, 4, 0, eEncodingIEEE754, eFormatFloat, { LLDB_INVALID_REGNUM, dwarf_s5, LLDB_INVALID_REGNUM, 31, 31 }, nullptr, nullptr, nullptr, 0 }, 778*0b57cec5SDimitry Andric { "s6", nullptr, 4, 0, eEncodingIEEE754, eFormatFloat, { LLDB_INVALID_REGNUM, dwarf_s6, LLDB_INVALID_REGNUM, 32, 32 }, nullptr, nullptr, nullptr, 0 }, 779*0b57cec5SDimitry Andric { "s7", nullptr, 4, 0, eEncodingIEEE754, eFormatFloat, { LLDB_INVALID_REGNUM, dwarf_s7, LLDB_INVALID_REGNUM, 33, 33 }, nullptr, nullptr, nullptr, 0 }, 780*0b57cec5SDimitry Andric { "s8", nullptr, 4, 0, eEncodingIEEE754, eFormatFloat, { LLDB_INVALID_REGNUM, dwarf_s8, LLDB_INVALID_REGNUM, 34, 34 }, nullptr, nullptr, nullptr, 0 }, 781*0b57cec5SDimitry Andric { "s9", nullptr, 4, 0, eEncodingIEEE754, eFormatFloat, { LLDB_INVALID_REGNUM, dwarf_s9, LLDB_INVALID_REGNUM, 35, 35 }, nullptr, nullptr, nullptr, 0 }, 782*0b57cec5SDimitry Andric { "s10", nullptr, 4, 0, eEncodingIEEE754, eFormatFloat, { LLDB_INVALID_REGNUM, dwarf_s10, LLDB_INVALID_REGNUM, 36, 36 }, nullptr, nullptr, nullptr, 0 }, 783*0b57cec5SDimitry Andric { "s11", nullptr, 4, 0, eEncodingIEEE754, eFormatFloat, { LLDB_INVALID_REGNUM, dwarf_s11, LLDB_INVALID_REGNUM, 37, 37 }, nullptr, nullptr, nullptr, 0 }, 784*0b57cec5SDimitry Andric { "s12", nullptr, 4, 0, eEncodingIEEE754, eFormatFloat, { LLDB_INVALID_REGNUM, dwarf_s12, LLDB_INVALID_REGNUM, 38, 38 }, nullptr, nullptr, nullptr, 0 }, 785*0b57cec5SDimitry Andric { "s13", nullptr, 4, 0, eEncodingIEEE754, eFormatFloat, { LLDB_INVALID_REGNUM, dwarf_s13, LLDB_INVALID_REGNUM, 39, 39 }, nullptr, nullptr, nullptr, 0 }, 786*0b57cec5SDimitry Andric { "s14", nullptr, 4, 0, eEncodingIEEE754, eFormatFloat, { LLDB_INVALID_REGNUM, dwarf_s14, LLDB_INVALID_REGNUM, 40, 40 }, nullptr, nullptr, nullptr, 0 }, 787*0b57cec5SDimitry Andric { "s15", nullptr, 4, 0, eEncodingIEEE754, eFormatFloat, { LLDB_INVALID_REGNUM, dwarf_s15, LLDB_INVALID_REGNUM, 41, 41 }, nullptr, nullptr, nullptr, 0 }, 788*0b57cec5SDimitry Andric { "s16", nullptr, 4, 0, eEncodingIEEE754, eFormatFloat, { LLDB_INVALID_REGNUM, dwarf_s16, LLDB_INVALID_REGNUM, 42, 42 }, nullptr, nullptr, nullptr, 0 }, 789*0b57cec5SDimitry Andric { "s17", nullptr, 4, 0, eEncodingIEEE754, eFormatFloat, { LLDB_INVALID_REGNUM, dwarf_s17, LLDB_INVALID_REGNUM, 43, 43 }, nullptr, nullptr, nullptr, 0 }, 790*0b57cec5SDimitry Andric { "s18", nullptr, 4, 0, eEncodingIEEE754, eFormatFloat, { LLDB_INVALID_REGNUM, dwarf_s18, LLDB_INVALID_REGNUM, 44, 44 }, nullptr, nullptr, nullptr, 0 }, 791*0b57cec5SDimitry Andric { "s19", nullptr, 4, 0, eEncodingIEEE754, eFormatFloat, { LLDB_INVALID_REGNUM, dwarf_s19, LLDB_INVALID_REGNUM, 45, 45 }, nullptr, nullptr, nullptr, 0 }, 792*0b57cec5SDimitry Andric { "s20", nullptr, 4, 0, eEncodingIEEE754, eFormatFloat, { LLDB_INVALID_REGNUM, dwarf_s20, LLDB_INVALID_REGNUM, 46, 46 }, nullptr, nullptr, nullptr, 0 }, 793*0b57cec5SDimitry Andric { "s21", nullptr, 4, 0, eEncodingIEEE754, eFormatFloat, { LLDB_INVALID_REGNUM, dwarf_s21, LLDB_INVALID_REGNUM, 47, 47 }, nullptr, nullptr, nullptr, 0 }, 794*0b57cec5SDimitry Andric { "s22", nullptr, 4, 0, eEncodingIEEE754, eFormatFloat, { LLDB_INVALID_REGNUM, dwarf_s22, LLDB_INVALID_REGNUM, 48, 48 }, nullptr, nullptr, nullptr, 0 }, 795*0b57cec5SDimitry Andric { "s23", nullptr, 4, 0, eEncodingIEEE754, eFormatFloat, { LLDB_INVALID_REGNUM, dwarf_s23, LLDB_INVALID_REGNUM, 49, 49 }, nullptr, nullptr, nullptr, 0 }, 796*0b57cec5SDimitry Andric { "s24", nullptr, 4, 0, eEncodingIEEE754, eFormatFloat, { LLDB_INVALID_REGNUM, dwarf_s24, LLDB_INVALID_REGNUM, 50, 50 }, nullptr, nullptr, nullptr, 0 }, 797*0b57cec5SDimitry Andric { "s25", nullptr, 4, 0, eEncodingIEEE754, eFormatFloat, { LLDB_INVALID_REGNUM, dwarf_s25, LLDB_INVALID_REGNUM, 51, 51 }, nullptr, nullptr, nullptr, 0 }, 798*0b57cec5SDimitry Andric { "s26", nullptr, 4, 0, eEncodingIEEE754, eFormatFloat, { LLDB_INVALID_REGNUM, dwarf_s26, LLDB_INVALID_REGNUM, 52, 52 }, nullptr, nullptr, nullptr, 0 }, 799*0b57cec5SDimitry Andric { "s27", nullptr, 4, 0, eEncodingIEEE754, eFormatFloat, { LLDB_INVALID_REGNUM, dwarf_s27, LLDB_INVALID_REGNUM, 53, 53 }, nullptr, nullptr, nullptr, 0 }, 800*0b57cec5SDimitry Andric { "s28", nullptr, 4, 0, eEncodingIEEE754, eFormatFloat, { LLDB_INVALID_REGNUM, dwarf_s28, LLDB_INVALID_REGNUM, 54, 54 }, nullptr, nullptr, nullptr, 0 }, 801*0b57cec5SDimitry Andric { "s29", nullptr, 4, 0, eEncodingIEEE754, eFormatFloat, { LLDB_INVALID_REGNUM, dwarf_s29, LLDB_INVALID_REGNUM, 55, 55 }, nullptr, nullptr, nullptr, 0 }, 802*0b57cec5SDimitry Andric { "s30", nullptr, 4, 0, eEncodingIEEE754, eFormatFloat, { LLDB_INVALID_REGNUM, dwarf_s30, LLDB_INVALID_REGNUM, 56, 56 }, nullptr, nullptr, nullptr, 0 }, 803*0b57cec5SDimitry Andric { "s31", nullptr, 4, 0, eEncodingIEEE754, eFormatFloat, { LLDB_INVALID_REGNUM, dwarf_s31, LLDB_INVALID_REGNUM, 57, 57 }, nullptr, nullptr, nullptr, 0 }, 804*0b57cec5SDimitry Andric { "fpscr",nullptr, 4, 0, eEncodingUint, eFormatHex, { LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM, 58, 58 }, nullptr, nullptr, nullptr, 0 }, 805*0b57cec5SDimitry Andric { "d16", nullptr, 8, 0, eEncodingIEEE754, eFormatFloat, { LLDB_INVALID_REGNUM, dwarf_d16, LLDB_INVALID_REGNUM, 59, 59 }, nullptr, nullptr, nullptr, 0 }, 806*0b57cec5SDimitry Andric { "d17", nullptr, 8, 0, eEncodingIEEE754, eFormatFloat, { LLDB_INVALID_REGNUM, dwarf_d17, LLDB_INVALID_REGNUM, 60, 60 }, nullptr, nullptr, nullptr, 0 }, 807*0b57cec5SDimitry Andric { "d18", nullptr, 8, 0, eEncodingIEEE754, eFormatFloat, { LLDB_INVALID_REGNUM, dwarf_d18, LLDB_INVALID_REGNUM, 61, 61 }, nullptr, nullptr, nullptr, 0 }, 808*0b57cec5SDimitry Andric { "d19", nullptr, 8, 0, eEncodingIEEE754, eFormatFloat, { LLDB_INVALID_REGNUM, dwarf_d19, LLDB_INVALID_REGNUM, 62, 62 }, nullptr, nullptr, nullptr, 0 }, 809*0b57cec5SDimitry Andric { "d20", nullptr, 8, 0, eEncodingIEEE754, eFormatFloat, { LLDB_INVALID_REGNUM, dwarf_d20, LLDB_INVALID_REGNUM, 63, 63 }, nullptr, nullptr, nullptr, 0 }, 810*0b57cec5SDimitry Andric { "d21", nullptr, 8, 0, eEncodingIEEE754, eFormatFloat, { LLDB_INVALID_REGNUM, dwarf_d21, LLDB_INVALID_REGNUM, 64, 64 }, nullptr, nullptr, nullptr, 0 }, 811*0b57cec5SDimitry Andric { "d22", nullptr, 8, 0, eEncodingIEEE754, eFormatFloat, { LLDB_INVALID_REGNUM, dwarf_d22, LLDB_INVALID_REGNUM, 65, 65 }, nullptr, nullptr, nullptr, 0 }, 812*0b57cec5SDimitry Andric { "d23", nullptr, 8, 0, eEncodingIEEE754, eFormatFloat, { LLDB_INVALID_REGNUM, dwarf_d23, LLDB_INVALID_REGNUM, 66, 66 }, nullptr, nullptr, nullptr, 0 }, 813*0b57cec5SDimitry Andric { "d24", nullptr, 8, 0, eEncodingIEEE754, eFormatFloat, { LLDB_INVALID_REGNUM, dwarf_d24, LLDB_INVALID_REGNUM, 67, 67 }, nullptr, nullptr, nullptr, 0 }, 814*0b57cec5SDimitry Andric { "d25", nullptr, 8, 0, eEncodingIEEE754, eFormatFloat, { LLDB_INVALID_REGNUM, dwarf_d25, LLDB_INVALID_REGNUM, 68, 68 }, nullptr, nullptr, nullptr, 0 }, 815*0b57cec5SDimitry Andric { "d26", nullptr, 8, 0, eEncodingIEEE754, eFormatFloat, { LLDB_INVALID_REGNUM, dwarf_d26, LLDB_INVALID_REGNUM, 69, 69 }, nullptr, nullptr, nullptr, 0 }, 816*0b57cec5SDimitry Andric { "d27", nullptr, 8, 0, eEncodingIEEE754, eFormatFloat, { LLDB_INVALID_REGNUM, dwarf_d27, LLDB_INVALID_REGNUM, 70, 70 }, nullptr, nullptr, nullptr, 0 }, 817*0b57cec5SDimitry Andric { "d28", nullptr, 8, 0, eEncodingIEEE754, eFormatFloat, { LLDB_INVALID_REGNUM, dwarf_d28, LLDB_INVALID_REGNUM, 71, 71 }, nullptr, nullptr, nullptr, 0 }, 818*0b57cec5SDimitry Andric { "d29", nullptr, 8, 0, eEncodingIEEE754, eFormatFloat, { LLDB_INVALID_REGNUM, dwarf_d29, LLDB_INVALID_REGNUM, 72, 72 }, nullptr, nullptr, nullptr, 0 }, 819*0b57cec5SDimitry Andric { "d30", nullptr, 8, 0, eEncodingIEEE754, eFormatFloat, { LLDB_INVALID_REGNUM, dwarf_d30, LLDB_INVALID_REGNUM, 73, 73 }, nullptr, nullptr, nullptr, 0 }, 820*0b57cec5SDimitry Andric { "d31", nullptr, 8, 0, eEncodingIEEE754, eFormatFloat, { LLDB_INVALID_REGNUM, dwarf_d31, LLDB_INVALID_REGNUM, 74, 74 }, nullptr, nullptr, nullptr, 0 }, 821*0b57cec5SDimitry Andric { "d0", nullptr, 8, 0, eEncodingIEEE754, eFormatFloat, { LLDB_INVALID_REGNUM, dwarf_d0, LLDB_INVALID_REGNUM, 75, 75 }, g_d0_regs, nullptr, nullptr, 0 }, 822*0b57cec5SDimitry Andric { "d1", nullptr, 8, 0, eEncodingIEEE754, eFormatFloat, { LLDB_INVALID_REGNUM, dwarf_d1, LLDB_INVALID_REGNUM, 76, 76 }, g_d1_regs, nullptr, nullptr, 0 }, 823*0b57cec5SDimitry Andric { "d2", nullptr, 8, 0, eEncodingIEEE754, eFormatFloat, { LLDB_INVALID_REGNUM, dwarf_d2, LLDB_INVALID_REGNUM, 77, 77 }, g_d2_regs, nullptr, nullptr, 0 }, 824*0b57cec5SDimitry Andric { "d3", nullptr, 8, 0, eEncodingIEEE754, eFormatFloat, { LLDB_INVALID_REGNUM, dwarf_d3, LLDB_INVALID_REGNUM, 78, 78 }, g_d3_regs, nullptr, nullptr, 0 }, 825*0b57cec5SDimitry Andric { "d4", nullptr, 8, 0, eEncodingIEEE754, eFormatFloat, { LLDB_INVALID_REGNUM, dwarf_d4, LLDB_INVALID_REGNUM, 79, 79 }, g_d4_regs, nullptr, nullptr, 0 }, 826*0b57cec5SDimitry Andric { "d5", nullptr, 8, 0, eEncodingIEEE754, eFormatFloat, { LLDB_INVALID_REGNUM, dwarf_d5, LLDB_INVALID_REGNUM, 80, 80 }, g_d5_regs, nullptr, nullptr, 0 }, 827*0b57cec5SDimitry Andric { "d6", nullptr, 8, 0, eEncodingIEEE754, eFormatFloat, { LLDB_INVALID_REGNUM, dwarf_d6, LLDB_INVALID_REGNUM, 81, 81 }, g_d6_regs, nullptr, nullptr, 0 }, 828*0b57cec5SDimitry Andric { "d7", nullptr, 8, 0, eEncodingIEEE754, eFormatFloat, { LLDB_INVALID_REGNUM, dwarf_d7, LLDB_INVALID_REGNUM, 82, 82 }, g_d7_regs, nullptr, nullptr, 0 }, 829*0b57cec5SDimitry Andric { "d8", nullptr, 8, 0, eEncodingIEEE754, eFormatFloat, { LLDB_INVALID_REGNUM, dwarf_d8, LLDB_INVALID_REGNUM, 83, 83 }, g_d8_regs, nullptr, nullptr, 0 }, 830*0b57cec5SDimitry Andric { "d9", nullptr, 8, 0, eEncodingIEEE754, eFormatFloat, { LLDB_INVALID_REGNUM, dwarf_d9, LLDB_INVALID_REGNUM, 84, 84 }, g_d9_regs, nullptr, nullptr, 0 }, 831*0b57cec5SDimitry Andric { "d10", nullptr, 8, 0, eEncodingIEEE754, eFormatFloat, { LLDB_INVALID_REGNUM, dwarf_d10, LLDB_INVALID_REGNUM, 85, 85 }, g_d10_regs, nullptr, nullptr, 0 }, 832*0b57cec5SDimitry Andric { "d11", nullptr, 8, 0, eEncodingIEEE754, eFormatFloat, { LLDB_INVALID_REGNUM, dwarf_d11, LLDB_INVALID_REGNUM, 86, 86 }, g_d11_regs, nullptr, nullptr, 0 }, 833*0b57cec5SDimitry Andric { "d12", nullptr, 8, 0, eEncodingIEEE754, eFormatFloat, { LLDB_INVALID_REGNUM, dwarf_d12, LLDB_INVALID_REGNUM, 87, 87 }, g_d12_regs, nullptr, nullptr, 0 }, 834*0b57cec5SDimitry Andric { "d13", nullptr, 8, 0, eEncodingIEEE754, eFormatFloat, { LLDB_INVALID_REGNUM, dwarf_d13, LLDB_INVALID_REGNUM, 88, 88 }, g_d13_regs, nullptr, nullptr, 0 }, 835*0b57cec5SDimitry Andric { "d14", nullptr, 8, 0, eEncodingIEEE754, eFormatFloat, { LLDB_INVALID_REGNUM, dwarf_d14, LLDB_INVALID_REGNUM, 89, 89 }, g_d14_regs, nullptr, nullptr, 0 }, 836*0b57cec5SDimitry Andric { "d15", nullptr, 8, 0, eEncodingIEEE754, eFormatFloat, { LLDB_INVALID_REGNUM, dwarf_d15, LLDB_INVALID_REGNUM, 90, 90 }, g_d15_regs, nullptr, nullptr, 0 }, 837*0b57cec5SDimitry Andric { "q0", nullptr, 16, 0, eEncodingVector, eFormatVectorOfUInt8, { LLDB_INVALID_REGNUM, dwarf_q0, LLDB_INVALID_REGNUM, 91, 91 }, g_q0_regs, nullptr, nullptr, 0 }, 838*0b57cec5SDimitry Andric { "q1", nullptr, 16, 0, eEncodingVector, eFormatVectorOfUInt8, { LLDB_INVALID_REGNUM, dwarf_q1, LLDB_INVALID_REGNUM, 92, 92 }, g_q1_regs, nullptr, nullptr, 0 }, 839*0b57cec5SDimitry Andric { "q2", nullptr, 16, 0, eEncodingVector, eFormatVectorOfUInt8, { LLDB_INVALID_REGNUM, dwarf_q2, LLDB_INVALID_REGNUM, 93, 93 }, g_q2_regs, nullptr, nullptr, 0 }, 840*0b57cec5SDimitry Andric { "q3", nullptr, 16, 0, eEncodingVector, eFormatVectorOfUInt8, { LLDB_INVALID_REGNUM, dwarf_q3, LLDB_INVALID_REGNUM, 94, 94 }, g_q3_regs, nullptr, nullptr, 0 }, 841*0b57cec5SDimitry Andric { "q4", nullptr, 16, 0, eEncodingVector, eFormatVectorOfUInt8, { LLDB_INVALID_REGNUM, dwarf_q4, LLDB_INVALID_REGNUM, 95, 95 }, g_q4_regs, nullptr, nullptr, 0 }, 842*0b57cec5SDimitry Andric { "q5", nullptr, 16, 0, eEncodingVector, eFormatVectorOfUInt8, { LLDB_INVALID_REGNUM, dwarf_q5, LLDB_INVALID_REGNUM, 96, 96 }, g_q5_regs, nullptr, nullptr, 0 }, 843*0b57cec5SDimitry Andric { "q6", nullptr, 16, 0, eEncodingVector, eFormatVectorOfUInt8, { LLDB_INVALID_REGNUM, dwarf_q6, LLDB_INVALID_REGNUM, 97, 97 }, g_q6_regs, nullptr, nullptr, 0 }, 844*0b57cec5SDimitry Andric { "q7", nullptr, 16, 0, eEncodingVector, eFormatVectorOfUInt8, { LLDB_INVALID_REGNUM, dwarf_q7, LLDB_INVALID_REGNUM, 98, 98 }, g_q7_regs, nullptr, nullptr, 0 }, 845*0b57cec5SDimitry Andric { "q8", nullptr, 16, 0, eEncodingVector, eFormatVectorOfUInt8, { LLDB_INVALID_REGNUM, dwarf_q8, LLDB_INVALID_REGNUM, 99, 99 }, g_q8_regs, nullptr, nullptr, 0 }, 846*0b57cec5SDimitry Andric { "q9", nullptr, 16, 0, eEncodingVector, eFormatVectorOfUInt8, { LLDB_INVALID_REGNUM, dwarf_q9, LLDB_INVALID_REGNUM, 100, 100 }, g_q9_regs, nullptr, nullptr, 0 }, 847*0b57cec5SDimitry Andric { "q10", nullptr, 16, 0, eEncodingVector, eFormatVectorOfUInt8, { LLDB_INVALID_REGNUM, dwarf_q10, LLDB_INVALID_REGNUM, 101, 101 }, g_q10_regs, nullptr, nullptr, 0 }, 848*0b57cec5SDimitry Andric { "q11", nullptr, 16, 0, eEncodingVector, eFormatVectorOfUInt8, { LLDB_INVALID_REGNUM, dwarf_q11, LLDB_INVALID_REGNUM, 102, 102 }, g_q11_regs, nullptr, nullptr, 0 }, 849*0b57cec5SDimitry Andric { "q12", nullptr, 16, 0, eEncodingVector, eFormatVectorOfUInt8, { LLDB_INVALID_REGNUM, dwarf_q12, LLDB_INVALID_REGNUM, 103, 103 }, g_q12_regs, nullptr, nullptr, 0 }, 850*0b57cec5SDimitry Andric { "q13", nullptr, 16, 0, eEncodingVector, eFormatVectorOfUInt8, { LLDB_INVALID_REGNUM, dwarf_q13, LLDB_INVALID_REGNUM, 104, 104 }, g_q13_regs, nullptr, nullptr, 0 }, 851*0b57cec5SDimitry Andric { "q14", nullptr, 16, 0, eEncodingVector, eFormatVectorOfUInt8, { LLDB_INVALID_REGNUM, dwarf_q14, LLDB_INVALID_REGNUM, 105, 105 }, g_q14_regs, nullptr, nullptr, 0 }, 852*0b57cec5SDimitry Andric { "q15", nullptr, 16, 0, eEncodingVector, eFormatVectorOfUInt8, { LLDB_INVALID_REGNUM, dwarf_q15, LLDB_INVALID_REGNUM, 106, 106 }, g_q15_regs, nullptr, nullptr, 0 } 853*0b57cec5SDimitry Andric }; 854*0b57cec5SDimitry Andric // clang-format on 855*0b57cec5SDimitry Andric 856*0b57cec5SDimitry Andric static const uint32_t num_registers = llvm::array_lengthof(g_register_infos); 857*0b57cec5SDimitry Andric static ConstString gpr_reg_set("General Purpose Registers"); 858*0b57cec5SDimitry Andric static ConstString sfp_reg_set("Software Floating Point Registers"); 859*0b57cec5SDimitry Andric static ConstString vfp_reg_set("Floating Point Registers"); 860*0b57cec5SDimitry Andric size_t i; 861*0b57cec5SDimitry Andric if (from_scratch) { 862*0b57cec5SDimitry Andric // Calculate the offsets of the registers 863*0b57cec5SDimitry Andric // Note that the layout of the "composite" registers (d0-d15 and q0-q15) 864*0b57cec5SDimitry Andric // which comes after the "primordial" registers is important. This enables 865*0b57cec5SDimitry Andric // us to calculate the offset of the composite register by using the offset 866*0b57cec5SDimitry Andric // of its first primordial register. For example, to calculate the offset 867*0b57cec5SDimitry Andric // of q0, use s0's offset. 868*0b57cec5SDimitry Andric if (g_register_infos[2].byte_offset == 0) { 869*0b57cec5SDimitry Andric uint32_t byte_offset = 0; 870*0b57cec5SDimitry Andric for (i = 0; i < num_registers; ++i) { 871*0b57cec5SDimitry Andric // For primordial registers, increment the byte_offset by the byte_size 872*0b57cec5SDimitry Andric // to arrive at the byte_offset for the next register. Otherwise, we 873*0b57cec5SDimitry Andric // have a composite register whose offset can be calculated by 874*0b57cec5SDimitry Andric // consulting the offset of its first primordial register. 875*0b57cec5SDimitry Andric if (!g_register_infos[i].value_regs) { 876*0b57cec5SDimitry Andric g_register_infos[i].byte_offset = byte_offset; 877*0b57cec5SDimitry Andric byte_offset += g_register_infos[i].byte_size; 878*0b57cec5SDimitry Andric } else { 879*0b57cec5SDimitry Andric const uint32_t first_primordial_reg = 880*0b57cec5SDimitry Andric g_register_infos[i].value_regs[0]; 881*0b57cec5SDimitry Andric g_register_infos[i].byte_offset = 882*0b57cec5SDimitry Andric g_register_infos[first_primordial_reg].byte_offset; 883*0b57cec5SDimitry Andric } 884*0b57cec5SDimitry Andric } 885*0b57cec5SDimitry Andric } 886*0b57cec5SDimitry Andric for (i = 0; i < num_registers; ++i) { 887*0b57cec5SDimitry Andric ConstString name; 888*0b57cec5SDimitry Andric ConstString alt_name; 889*0b57cec5SDimitry Andric if (g_register_infos[i].name && g_register_infos[i].name[0]) 890*0b57cec5SDimitry Andric name.SetCString(g_register_infos[i].name); 891*0b57cec5SDimitry Andric if (g_register_infos[i].alt_name && g_register_infos[i].alt_name[0]) 892*0b57cec5SDimitry Andric alt_name.SetCString(g_register_infos[i].alt_name); 893*0b57cec5SDimitry Andric 894*0b57cec5SDimitry Andric if (i <= 15 || i == 25) 895*0b57cec5SDimitry Andric AddRegister(g_register_infos[i], name, alt_name, gpr_reg_set); 896*0b57cec5SDimitry Andric else if (i <= 24) 897*0b57cec5SDimitry Andric AddRegister(g_register_infos[i], name, alt_name, sfp_reg_set); 898*0b57cec5SDimitry Andric else 899*0b57cec5SDimitry Andric AddRegister(g_register_infos[i], name, alt_name, vfp_reg_set); 900*0b57cec5SDimitry Andric } 901*0b57cec5SDimitry Andric } else { 902*0b57cec5SDimitry Andric // Add composite registers to our primordial registers, then. 903*0b57cec5SDimitry Andric const size_t num_composites = llvm::array_lengthof(g_composites); 904*0b57cec5SDimitry Andric const size_t num_dynamic_regs = GetNumRegisters(); 905*0b57cec5SDimitry Andric const size_t num_common_regs = num_registers - num_composites; 906*0b57cec5SDimitry Andric RegisterInfo *g_comp_register_infos = g_register_infos + num_common_regs; 907*0b57cec5SDimitry Andric 908*0b57cec5SDimitry Andric // First we need to validate that all registers that we already have match 909*0b57cec5SDimitry Andric // the non composite regs. If so, then we can add the registers, else we 910*0b57cec5SDimitry Andric // need to bail 911*0b57cec5SDimitry Andric bool match = true; 912*0b57cec5SDimitry Andric if (num_dynamic_regs == num_common_regs) { 913*0b57cec5SDimitry Andric for (i = 0; match && i < num_dynamic_regs; ++i) { 914*0b57cec5SDimitry Andric // Make sure all register names match 915*0b57cec5SDimitry Andric if (m_regs[i].name && g_register_infos[i].name) { 916*0b57cec5SDimitry Andric if (strcmp(m_regs[i].name, g_register_infos[i].name)) { 917*0b57cec5SDimitry Andric match = false; 918*0b57cec5SDimitry Andric break; 919*0b57cec5SDimitry Andric } 920*0b57cec5SDimitry Andric } 921*0b57cec5SDimitry Andric 922*0b57cec5SDimitry Andric // Make sure all register byte sizes match 923*0b57cec5SDimitry Andric if (m_regs[i].byte_size != g_register_infos[i].byte_size) { 924*0b57cec5SDimitry Andric match = false; 925*0b57cec5SDimitry Andric break; 926*0b57cec5SDimitry Andric } 927*0b57cec5SDimitry Andric } 928*0b57cec5SDimitry Andric } else { 929*0b57cec5SDimitry Andric // Wrong number of registers. 930*0b57cec5SDimitry Andric match = false; 931*0b57cec5SDimitry Andric } 932*0b57cec5SDimitry Andric // If "match" is true, then we can add extra registers. 933*0b57cec5SDimitry Andric if (match) { 934*0b57cec5SDimitry Andric for (i = 0; i < num_composites; ++i) { 935*0b57cec5SDimitry Andric ConstString name; 936*0b57cec5SDimitry Andric ConstString alt_name; 937*0b57cec5SDimitry Andric const uint32_t first_primordial_reg = 938*0b57cec5SDimitry Andric g_comp_register_infos[i].value_regs[0]; 939*0b57cec5SDimitry Andric const char *reg_name = g_register_infos[first_primordial_reg].name; 940*0b57cec5SDimitry Andric if (reg_name && reg_name[0]) { 941*0b57cec5SDimitry Andric for (uint32_t j = 0; j < num_dynamic_regs; ++j) { 942*0b57cec5SDimitry Andric const RegisterInfo *reg_info = GetRegisterInfoAtIndex(j); 943*0b57cec5SDimitry Andric // Find a matching primordial register info entry. 944*0b57cec5SDimitry Andric if (reg_info && reg_info->name && 945*0b57cec5SDimitry Andric ::strcasecmp(reg_info->name, reg_name) == 0) { 946*0b57cec5SDimitry Andric // The name matches the existing primordial entry. Find and 947*0b57cec5SDimitry Andric // assign the offset, and then add this composite register entry. 948*0b57cec5SDimitry Andric g_comp_register_infos[i].byte_offset = reg_info->byte_offset; 949*0b57cec5SDimitry Andric name.SetCString(g_comp_register_infos[i].name); 950*0b57cec5SDimitry Andric AddRegister(g_comp_register_infos[i], name, alt_name, 951*0b57cec5SDimitry Andric vfp_reg_set); 952*0b57cec5SDimitry Andric } 953*0b57cec5SDimitry Andric } 954*0b57cec5SDimitry Andric } 955*0b57cec5SDimitry Andric } 956*0b57cec5SDimitry Andric } 957*0b57cec5SDimitry Andric } 958*0b57cec5SDimitry Andric } 959