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