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/Interpreter/PythonDataObjects.h" 21 #include "lldb/Target/ExecutionContext.h" 22 #include "lldb/Utility/Utils.h" 23 // Project includes 24 #include "Utility/StringExtractorGDBRemote.h" 25 #include "ProcessGDBRemote.h" 26 #include "ProcessGDBRemoteLog.h" 27 #include "ThreadGDBRemote.h" 28 #include "Utility/ARM_GCC_Registers.h" 29 #include "Utility/ARM_DWARF_Registers.h" 30 31 using namespace lldb; 32 using namespace lldb_private; 33 34 //---------------------------------------------------------------------- 35 // GDBRemoteRegisterContext constructor 36 //---------------------------------------------------------------------- 37 GDBRemoteRegisterContext::GDBRemoteRegisterContext 38 ( 39 ThreadGDBRemote &thread, 40 uint32_t concrete_frame_idx, 41 GDBRemoteDynamicRegisterInfo ®_info, 42 bool read_all_at_once 43 ) : 44 RegisterContext (thread, concrete_frame_idx), 45 m_reg_info (reg_info), 46 m_reg_valid (), 47 m_reg_data (), 48 m_read_all_at_once (read_all_at_once) 49 { 50 // Resize our vector of bools to contain one bool for every register. 51 // We will use these boolean values to know when a register value 52 // is valid in m_reg_data. 53 m_reg_valid.resize (reg_info.GetNumRegisters()); 54 55 // Make a heap based buffer that is big enough to store all registers 56 DataBufferSP reg_data_sp(new DataBufferHeap (reg_info.GetRegisterDataByteSize(), 0)); 57 m_reg_data.SetData (reg_data_sp); 58 m_reg_data.SetByteOrder(thread.GetProcess()->GetByteOrder()); 59 } 60 61 //---------------------------------------------------------------------- 62 // Destructor 63 //---------------------------------------------------------------------- 64 GDBRemoteRegisterContext::~GDBRemoteRegisterContext() 65 { 66 } 67 68 void 69 GDBRemoteRegisterContext::InvalidateAllRegisters () 70 { 71 SetAllRegisterValid (false); 72 } 73 74 void 75 GDBRemoteRegisterContext::SetAllRegisterValid (bool b) 76 { 77 std::vector<bool>::iterator pos, end = m_reg_valid.end(); 78 for (pos = m_reg_valid.begin(); pos != end; ++pos) 79 *pos = b; 80 } 81 82 size_t 83 GDBRemoteRegisterContext::GetRegisterCount () 84 { 85 return m_reg_info.GetNumRegisters (); 86 } 87 88 const RegisterInfo * 89 GDBRemoteRegisterContext::GetRegisterInfoAtIndex (size_t reg) 90 { 91 return m_reg_info.GetRegisterInfoAtIndex (reg); 92 } 93 94 size_t 95 GDBRemoteRegisterContext::GetRegisterSetCount () 96 { 97 return m_reg_info.GetNumRegisterSets (); 98 } 99 100 101 102 const RegisterSet * 103 GDBRemoteRegisterContext::GetRegisterSet (size_t reg_set) 104 { 105 return m_reg_info.GetRegisterSet (reg_set); 106 } 107 108 109 110 bool 111 GDBRemoteRegisterContext::ReadRegister (const RegisterInfo *reg_info, RegisterValue &value) 112 { 113 // Read the register 114 if (ReadRegisterBytes (reg_info, m_reg_data)) 115 { 116 const bool partial_data_ok = false; 117 Error error (value.SetValueFromData(reg_info, m_reg_data, reg_info->byte_offset, partial_data_ok)); 118 return error.Success(); 119 } 120 return false; 121 } 122 123 bool 124 GDBRemoteRegisterContext::PrivateSetRegisterValue (uint32_t reg, StringExtractor &response) 125 { 126 const RegisterInfo *reg_info = GetRegisterInfoAtIndex (reg); 127 if (reg_info == NULL) 128 return false; 129 130 // Invalidate if needed 131 InvalidateIfNeeded(false); 132 133 const uint32_t reg_byte_size = reg_info->byte_size; 134 const size_t bytes_copied = response.GetHexBytes (const_cast<uint8_t*>(m_reg_data.PeekData(reg_info->byte_offset, reg_byte_size)), reg_byte_size, '\xcc'); 135 bool success = bytes_copied == reg_byte_size; 136 if (success) 137 { 138 SetRegisterIsValid(reg, true); 139 } 140 else if (bytes_copied > 0) 141 { 142 // Only set register is valid to false if we copied some bytes, else 143 // leave it as it was. 144 SetRegisterIsValid(reg, false); 145 } 146 return success; 147 } 148 149 // Helper function for GDBRemoteRegisterContext::ReadRegisterBytes(). 150 bool 151 GDBRemoteRegisterContext::GetPrimordialRegister(const lldb_private::RegisterInfo *reg_info, 152 GDBRemoteCommunicationClient &gdb_comm) 153 { 154 char packet[64]; 155 StringExtractorGDBRemote response; 156 int packet_len = 0; 157 const uint32_t reg = reg_info->kinds[eRegisterKindLLDB]; 158 if (gdb_comm.GetThreadSuffixSupported()) 159 packet_len = ::snprintf (packet, sizeof(packet), "p%x;thread:%4.4" PRIx64 ";", reg, m_thread.GetProtocolID()); 160 else 161 packet_len = ::snprintf (packet, sizeof(packet), "p%x", reg); 162 assert (packet_len < ((int)sizeof(packet) - 1)); 163 if (gdb_comm.SendPacketAndWaitForResponse(packet, response, false)) 164 return PrivateSetRegisterValue (reg, response); 165 166 return false; 167 } 168 bool 169 GDBRemoteRegisterContext::ReadRegisterBytes (const RegisterInfo *reg_info, DataExtractor &data) 170 { 171 ExecutionContext exe_ctx (CalculateThread()); 172 173 Process *process = exe_ctx.GetProcessPtr(); 174 Thread *thread = exe_ctx.GetThreadPtr(); 175 if (process == NULL || thread == NULL) 176 return false; 177 178 GDBRemoteCommunicationClient &gdb_comm (((ProcessGDBRemote *)process)->GetGDBRemote()); 179 180 InvalidateIfNeeded(false); 181 182 const uint32_t reg = reg_info->kinds[eRegisterKindLLDB]; 183 184 if (!GetRegisterIsValid(reg)) 185 { 186 Mutex::Locker locker; 187 if (gdb_comm.GetSequenceMutex (locker, "Didn't get sequence mutex for read register.")) 188 { 189 const bool thread_suffix_supported = gdb_comm.GetThreadSuffixSupported(); 190 ProcessSP process_sp (m_thread.GetProcess()); 191 if (thread_suffix_supported || static_cast<ProcessGDBRemote *>(process_sp.get())->GetGDBRemote().SetCurrentThread(m_thread.GetProtocolID())) 192 { 193 char packet[64]; 194 StringExtractorGDBRemote response; 195 int packet_len = 0; 196 if (m_read_all_at_once) 197 { 198 // Get all registers in one packet 199 if (thread_suffix_supported) 200 packet_len = ::snprintf (packet, sizeof(packet), "g;thread:%4.4" PRIx64 ";", m_thread.GetProtocolID()); 201 else 202 packet_len = ::snprintf (packet, sizeof(packet), "g"); 203 assert (packet_len < ((int)sizeof(packet) - 1)); 204 if (gdb_comm.SendPacketAndWaitForResponse(packet, response, false)) 205 { 206 if (response.IsNormalResponse()) 207 if (response.GetHexBytes ((void *)m_reg_data.GetDataStart(), m_reg_data.GetByteSize(), '\xcc') == m_reg_data.GetByteSize()) 208 SetAllRegisterValid (true); 209 } 210 } 211 else if (reg_info->value_regs) 212 { 213 // Process this composite register request by delegating to the constituent 214 // primordial registers. 215 216 // Index of the primordial register. 217 bool success = true; 218 for (uint32_t idx = 0; success; ++idx) 219 { 220 const uint32_t prim_reg = reg_info->value_regs[idx]; 221 if (prim_reg == LLDB_INVALID_REGNUM) 222 break; 223 // We have a valid primordial regsiter as our constituent. 224 // Grab the corresponding register info. 225 const RegisterInfo *prim_reg_info = GetRegisterInfoAtIndex(prim_reg); 226 if (prim_reg_info == NULL) 227 success = false; 228 else 229 { 230 // Read the containing register if it hasn't already been read 231 if (!GetRegisterIsValid(prim_reg)) 232 success = GetPrimordialRegister(prim_reg_info, gdb_comm); 233 } 234 } 235 236 if (success) 237 { 238 // If we reach this point, all primordial register requests have succeeded. 239 // Validate this composite register. 240 SetRegisterIsValid (reg_info, true); 241 } 242 } 243 else 244 { 245 // Get each register individually 246 GetPrimordialRegister(reg_info, gdb_comm); 247 } 248 } 249 } 250 else 251 { 252 #if LLDB_CONFIGURATION_DEBUG 253 StreamString strm; 254 gdb_comm.DumpHistory(strm); 255 Host::SetCrashDescription (strm.GetData()); 256 assert (!"Didn't get sequence mutex for read register."); 257 #else 258 Log *log (ProcessGDBRemoteLog::GetLogIfAnyCategoryIsSet (GDBR_LOG_THREAD | GDBR_LOG_PACKETS)); 259 if (log) 260 { 261 if (log->GetVerbose()) 262 { 263 StreamString strm; 264 gdb_comm.DumpHistory(strm); 265 log->Printf("error: failed to get packet sequence mutex, not sending read register for \"%s\":\n%s", reg_info->name, strm.GetData()); 266 } 267 else 268 { 269 log->Printf("error: failed to get packet sequence mutex, not sending read register for \"%s\"", reg_info->name); 270 } 271 } 272 #endif 273 } 274 275 // Make sure we got a valid register value after reading it 276 if (!GetRegisterIsValid(reg)) 277 return false; 278 } 279 280 if (&data != &m_reg_data) 281 { 282 // If we aren't extracting into our own buffer (which 283 // only happens when this function is called from 284 // ReadRegisterValue(uint32_t, Scalar&)) then 285 // we transfer bytes from our buffer into the data 286 // buffer that was passed in 287 data.SetByteOrder (m_reg_data.GetByteOrder()); 288 data.SetData (m_reg_data, reg_info->byte_offset, reg_info->byte_size); 289 } 290 return true; 291 } 292 293 bool 294 GDBRemoteRegisterContext::WriteRegister (const RegisterInfo *reg_info, 295 const RegisterValue &value) 296 { 297 DataExtractor data; 298 if (value.GetData (data)) 299 return WriteRegisterBytes (reg_info, data, 0); 300 return false; 301 } 302 303 // Helper function for GDBRemoteRegisterContext::WriteRegisterBytes(). 304 bool 305 GDBRemoteRegisterContext::SetPrimordialRegister(const lldb_private::RegisterInfo *reg_info, 306 GDBRemoteCommunicationClient &gdb_comm) 307 { 308 StreamString packet; 309 StringExtractorGDBRemote response; 310 const uint32_t reg = reg_info->kinds[eRegisterKindLLDB]; 311 packet.Printf ("P%x=", reg); 312 packet.PutBytesAsRawHex8 (m_reg_data.PeekData(reg_info->byte_offset, reg_info->byte_size), 313 reg_info->byte_size, 314 lldb::endian::InlHostByteOrder(), 315 lldb::endian::InlHostByteOrder()); 316 317 if (gdb_comm.GetThreadSuffixSupported()) 318 packet.Printf (";thread:%4.4" PRIx64 ";", m_thread.GetProtocolID()); 319 320 // Invalidate just this register 321 SetRegisterIsValid(reg, false); 322 if (gdb_comm.SendPacketAndWaitForResponse(packet.GetString().c_str(), 323 packet.GetString().size(), 324 response, 325 false)) 326 { 327 if (response.IsOKResponse()) 328 return true; 329 } 330 return false; 331 } 332 333 void 334 GDBRemoteRegisterContext::SyncThreadState(Process *process) 335 { 336 // NB. We assume our caller has locked the sequence mutex. 337 338 GDBRemoteCommunicationClient &gdb_comm (((ProcessGDBRemote *) process)->GetGDBRemote()); 339 if (!gdb_comm.GetSyncThreadStateSupported()) 340 return; 341 342 StreamString packet; 343 StringExtractorGDBRemote response; 344 packet.Printf ("QSyncThreadState:%4.4" PRIx64 ";", m_thread.GetProtocolID()); 345 if (gdb_comm.SendPacketAndWaitForResponse(packet.GetString().c_str(), 346 packet.GetString().size(), 347 response, 348 false)) 349 { 350 if (response.IsOKResponse()) 351 InvalidateAllRegisters(); 352 } 353 } 354 355 bool 356 GDBRemoteRegisterContext::WriteRegisterBytes (const lldb_private::RegisterInfo *reg_info, DataExtractor &data, uint32_t data_offset) 357 { 358 ExecutionContext exe_ctx (CalculateThread()); 359 360 Process *process = exe_ctx.GetProcessPtr(); 361 Thread *thread = exe_ctx.GetThreadPtr(); 362 if (process == NULL || thread == NULL) 363 return false; 364 365 GDBRemoteCommunicationClient &gdb_comm (((ProcessGDBRemote *)process)->GetGDBRemote()); 366 // FIXME: This check isn't right because IsRunning checks the Public state, but this 367 // is work you need to do - for instance in ShouldStop & friends - before the public 368 // state has been changed. 369 // if (gdb_comm.IsRunning()) 370 // return false; 371 372 // Grab a pointer to where we are going to put this register 373 uint8_t *dst = const_cast<uint8_t*>(m_reg_data.PeekData(reg_info->byte_offset, reg_info->byte_size)); 374 375 if (dst == NULL) 376 return false; 377 378 379 if (data.CopyByteOrderedData (data_offset, // src offset 380 reg_info->byte_size, // src length 381 dst, // dst 382 reg_info->byte_size, // dst length 383 m_reg_data.GetByteOrder())) // dst byte order 384 { 385 Mutex::Locker locker; 386 if (gdb_comm.GetSequenceMutex (locker, "Didn't get sequence mutex for write register.")) 387 { 388 const bool thread_suffix_supported = gdb_comm.GetThreadSuffixSupported(); 389 ProcessSP process_sp (m_thread.GetProcess()); 390 if (thread_suffix_supported || static_cast<ProcessGDBRemote *>(process_sp.get())->GetGDBRemote().SetCurrentThread(m_thread.GetProtocolID())) 391 { 392 StreamString packet; 393 StringExtractorGDBRemote response; 394 395 if (m_read_all_at_once) 396 { 397 // Set all registers in one packet 398 packet.PutChar ('G'); 399 packet.PutBytesAsRawHex8 (m_reg_data.GetDataStart(), 400 m_reg_data.GetByteSize(), 401 lldb::endian::InlHostByteOrder(), 402 lldb::endian::InlHostByteOrder()); 403 404 if (thread_suffix_supported) 405 packet.Printf (";thread:%4.4" PRIx64 ";", m_thread.GetProtocolID()); 406 407 // Invalidate all register values 408 InvalidateIfNeeded (true); 409 410 if (gdb_comm.SendPacketAndWaitForResponse(packet.GetString().c_str(), 411 packet.GetString().size(), 412 response, 413 false)) 414 { 415 SetAllRegisterValid (false); 416 if (response.IsOKResponse()) 417 { 418 return true; 419 } 420 } 421 } 422 else 423 { 424 bool success = true; 425 426 if (reg_info->value_regs) 427 { 428 // This register is part of another register. In this case we read the actual 429 // register data for any "value_regs", and once all that data is read, we will 430 // have enough data in our register context bytes for the value of this register 431 432 // Invalidate this composite register first. 433 434 for (uint32_t idx = 0; success; ++idx) 435 { 436 const uint32_t reg = reg_info->value_regs[idx]; 437 if (reg == LLDB_INVALID_REGNUM) 438 break; 439 // We have a valid primordial regsiter as our constituent. 440 // Grab the corresponding register info. 441 const RegisterInfo *value_reg_info = GetRegisterInfoAtIndex(reg); 442 if (value_reg_info == NULL) 443 success = false; 444 else 445 success = SetPrimordialRegister(value_reg_info, gdb_comm); 446 } 447 } 448 else 449 { 450 // This is an actual register, write it 451 success = SetPrimordialRegister(reg_info, gdb_comm); 452 } 453 454 // Check if writing this register will invalidate any other register values? 455 // If so, invalidate them 456 if (reg_info->invalidate_regs) 457 { 458 for (uint32_t idx = 0, reg = reg_info->invalidate_regs[0]; 459 reg != LLDB_INVALID_REGNUM; 460 reg = reg_info->invalidate_regs[++idx]) 461 { 462 SetRegisterIsValid(reg, false); 463 } 464 } 465 466 return success; 467 } 468 } 469 } 470 else 471 { 472 Log *log (ProcessGDBRemoteLog::GetLogIfAnyCategoryIsSet (GDBR_LOG_THREAD | GDBR_LOG_PACKETS)); 473 if (log) 474 { 475 if (log->GetVerbose()) 476 { 477 StreamString strm; 478 gdb_comm.DumpHistory(strm); 479 log->Printf("error: failed to get packet sequence mutex, not sending write register for \"%s\":\n%s", reg_info->name, strm.GetData()); 480 } 481 else 482 log->Printf("error: failed to get packet sequence mutex, not sending write register for \"%s\"", reg_info->name); 483 } 484 } 485 } 486 return false; 487 } 488 489 490 bool 491 GDBRemoteRegisterContext::ReadAllRegisterValues (lldb::DataBufferSP &data_sp) 492 { 493 ExecutionContext exe_ctx (CalculateThread()); 494 495 Process *process = exe_ctx.GetProcessPtr(); 496 Thread *thread = exe_ctx.GetThreadPtr(); 497 if (process == NULL || thread == NULL) 498 return false; 499 500 GDBRemoteCommunicationClient &gdb_comm (((ProcessGDBRemote *)process)->GetGDBRemote()); 501 502 StringExtractorGDBRemote response; 503 504 Mutex::Locker locker; 505 if (gdb_comm.GetSequenceMutex (locker, "Didn't get sequence mutex for read all registers.")) 506 { 507 SyncThreadState(process); 508 509 char packet[32]; 510 const bool thread_suffix_supported = gdb_comm.GetThreadSuffixSupported(); 511 ProcessSP process_sp (m_thread.GetProcess()); 512 if (thread_suffix_supported || static_cast<ProcessGDBRemote *>(process_sp.get())->GetGDBRemote().SetCurrentThread(m_thread.GetProtocolID())) 513 { 514 int packet_len = 0; 515 if (thread_suffix_supported) 516 packet_len = ::snprintf (packet, sizeof(packet), "g;thread:%4.4" PRIx64, m_thread.GetProtocolID()); 517 else 518 packet_len = ::snprintf (packet, sizeof(packet), "g"); 519 assert (packet_len < ((int)sizeof(packet) - 1)); 520 521 if (gdb_comm.SendPacketAndWaitForResponse(packet, packet_len, response, false)) 522 { 523 if (response.IsErrorResponse()) 524 return false; 525 526 std::string &response_str = response.GetStringRef(); 527 if (isxdigit(response_str[0])) 528 { 529 response_str.insert(0, 1, 'G'); 530 if (thread_suffix_supported) 531 { 532 char thread_id_cstr[64]; 533 ::snprintf (thread_id_cstr, sizeof(thread_id_cstr), ";thread:%4.4" PRIx64 ";", m_thread.GetProtocolID()); 534 response_str.append (thread_id_cstr); 535 } 536 data_sp.reset (new DataBufferHeap (response_str.c_str(), response_str.size())); 537 return true; 538 } 539 } 540 } 541 } 542 else 543 { 544 Log *log (ProcessGDBRemoteLog::GetLogIfAnyCategoryIsSet (GDBR_LOG_THREAD | GDBR_LOG_PACKETS)); 545 if (log) 546 { 547 if (log->GetVerbose()) 548 { 549 StreamString strm; 550 gdb_comm.DumpHistory(strm); 551 log->Printf("error: failed to get packet sequence mutex, not sending read all registers:\n%s", strm.GetData()); 552 } 553 else 554 log->Printf("error: failed to get packet sequence mutex, not sending read all registers"); 555 } 556 } 557 558 data_sp.reset(); 559 return false; 560 } 561 562 bool 563 GDBRemoteRegisterContext::WriteAllRegisterValues (const lldb::DataBufferSP &data_sp) 564 { 565 if (!data_sp || data_sp->GetBytes() == NULL || data_sp->GetByteSize() == 0) 566 return false; 567 568 ExecutionContext exe_ctx (CalculateThread()); 569 570 Process *process = exe_ctx.GetProcessPtr(); 571 Thread *thread = exe_ctx.GetThreadPtr(); 572 if (process == NULL || thread == NULL) 573 return false; 574 575 GDBRemoteCommunicationClient &gdb_comm (((ProcessGDBRemote *)process)->GetGDBRemote()); 576 577 StringExtractorGDBRemote response; 578 Mutex::Locker locker; 579 if (gdb_comm.GetSequenceMutex (locker, "Didn't get sequence mutex for write all registers.")) 580 { 581 const bool thread_suffix_supported = gdb_comm.GetThreadSuffixSupported(); 582 ProcessSP process_sp (m_thread.GetProcess()); 583 if (thread_suffix_supported || static_cast<ProcessGDBRemote *>(process_sp.get())->GetGDBRemote().SetCurrentThread(m_thread.GetProtocolID())) 584 { 585 // The data_sp contains the entire G response packet including the 586 // G, and if the thread suffix is supported, it has the thread suffix 587 // as well. 588 const char *G_packet = (const char *)data_sp->GetBytes(); 589 size_t G_packet_len = data_sp->GetByteSize(); 590 if (gdb_comm.SendPacketAndWaitForResponse (G_packet, 591 G_packet_len, 592 response, 593 false)) 594 { 595 if (response.IsOKResponse()) 596 return true; 597 else if (response.IsErrorResponse()) 598 { 599 uint32_t num_restored = 0; 600 // We need to manually go through all of the registers and 601 // restore them manually 602 603 response.GetStringRef().assign (G_packet, G_packet_len); 604 response.SetFilePos(1); // Skip the leading 'G' 605 DataBufferHeap buffer (m_reg_data.GetByteSize(), 0); 606 DataExtractor restore_data (buffer.GetBytes(), 607 buffer.GetByteSize(), 608 m_reg_data.GetByteOrder(), 609 m_reg_data.GetAddressByteSize()); 610 611 const uint32_t bytes_extracted = response.GetHexBytes ((void *)restore_data.GetDataStart(), 612 restore_data.GetByteSize(), 613 '\xcc'); 614 615 if (bytes_extracted < restore_data.GetByteSize()) 616 restore_data.SetData(restore_data.GetDataStart(), bytes_extracted, m_reg_data.GetByteOrder()); 617 618 //ReadRegisterBytes (const RegisterInfo *reg_info, RegisterValue &value, DataExtractor &data) 619 const RegisterInfo *reg_info; 620 // We have to march the offset of each register along in the 621 // buffer to make sure we get the right offset. 622 uint32_t reg_byte_offset = 0; 623 for (uint32_t reg_idx=0; (reg_info = GetRegisterInfoAtIndex (reg_idx)) != NULL; ++reg_idx, reg_byte_offset += reg_info->byte_size) 624 { 625 const uint32_t reg = reg_info->kinds[eRegisterKindLLDB]; 626 627 // Skip composite registers. 628 if (reg_info->value_regs) 629 continue; 630 631 // Only write down the registers that need to be written 632 // if we are going to be doing registers individually. 633 bool write_reg = true; 634 const uint32_t reg_byte_size = reg_info->byte_size; 635 636 const char *restore_src = (const char *)restore_data.PeekData(reg_byte_offset, reg_byte_size); 637 if (restore_src) 638 { 639 if (GetRegisterIsValid(reg)) 640 { 641 const char *current_src = (const char *)m_reg_data.PeekData(reg_byte_offset, reg_byte_size); 642 if (current_src) 643 write_reg = memcmp (current_src, restore_src, reg_byte_size) != 0; 644 } 645 646 if (write_reg) 647 { 648 StreamString packet; 649 packet.Printf ("P%x=", reg); 650 packet.PutBytesAsRawHex8 (restore_src, 651 reg_byte_size, 652 lldb::endian::InlHostByteOrder(), 653 lldb::endian::InlHostByteOrder()); 654 655 if (thread_suffix_supported) 656 packet.Printf (";thread:%4.4" PRIx64 ";", m_thread.GetProtocolID()); 657 658 SetRegisterIsValid(reg, false); 659 if (gdb_comm.SendPacketAndWaitForResponse(packet.GetString().c_str(), 660 packet.GetString().size(), 661 response, 662 false)) 663 { 664 if (response.IsOKResponse()) 665 ++num_restored; 666 } 667 } 668 } 669 } 670 return num_restored > 0; 671 } 672 } 673 } 674 } 675 else 676 { 677 Log *log (ProcessGDBRemoteLog::GetLogIfAnyCategoryIsSet (GDBR_LOG_THREAD | GDBR_LOG_PACKETS)); 678 if (log) 679 { 680 if (log->GetVerbose()) 681 { 682 StreamString strm; 683 gdb_comm.DumpHistory(strm); 684 log->Printf("error: failed to get packet sequence mutex, not sending write all registers:\n%s", strm.GetData()); 685 } 686 else 687 log->Printf("error: failed to get packet sequence mutex, not sending write all registers"); 688 } 689 } 690 return false; 691 } 692 693 694 uint32_t 695 GDBRemoteRegisterContext::ConvertRegisterKindToRegisterNumber (uint32_t kind, uint32_t num) 696 { 697 return m_reg_info.ConvertRegisterKindToRegisterNumber (kind, num); 698 } 699 700 size_t 701 GDBRemoteDynamicRegisterInfo::SetRegisterInfo (const lldb_private::PythonDictionary &dict) 702 { 703 #ifndef LLDB_DISABLE_PYTHON 704 PythonList sets (dict.GetItemForKey("sets")); 705 if (sets) 706 { 707 const uint32_t num_sets = sets.GetSize(); 708 for (uint32_t i=0; i<num_sets; ++i) 709 { 710 PythonString py_set_name(sets.GetItemAtIndex(i)); 711 ConstString set_name; 712 if (py_set_name) 713 set_name.SetCString(py_set_name.GetString()); 714 if (set_name) 715 { 716 RegisterSet new_set = { set_name.AsCString(), NULL, 0, NULL }; 717 m_sets.push_back (new_set); 718 } 719 else 720 { 721 Clear(); 722 return 0; 723 } 724 } 725 m_set_reg_nums.resize(m_sets.size()); 726 } 727 PythonList regs (dict.GetItemForKey("registers")); 728 if (regs) 729 { 730 const uint32_t num_regs = regs.GetSize(); 731 PythonString name_pystr("name"); 732 PythonString altname_pystr("alt-name"); 733 PythonString bitsize_pystr("bitsize"); 734 PythonString offset_pystr("offset"); 735 PythonString encoding_pystr("encoding"); 736 PythonString format_pystr("format"); 737 PythonString set_pystr("set"); 738 PythonString gcc_pystr("gcc"); 739 PythonString gdb_pystr("gdb"); 740 PythonString dwarf_pystr("dwarf"); 741 PythonString generic_pystr("generic"); 742 for (uint32_t i=0; i<num_regs; ++i) 743 { 744 PythonDictionary reg_info_dict(regs.GetItemAtIndex(i)); 745 if (reg_info_dict) 746 { 747 // { 'name':'rcx' , 'bitsize' : 64, 'offset' : 16, 'encoding':'uint' , 'format':'hex' , 'set': 0, 'gcc' : 2, 'dwarf' : 2, 'generic':'arg4', 'alt-name':'arg4', }, 748 RegisterInfo reg_info; 749 bzero (®_info, sizeof(reg_info)); 750 751 reg_info.name = ConstString (reg_info_dict.GetItemForKeyAsString(name_pystr)).GetCString(); 752 if (reg_info.name == NULL) 753 { 754 Clear(); 755 return 0; 756 } 757 758 reg_info.alt_name = ConstString (reg_info_dict.GetItemForKeyAsString(altname_pystr)).GetCString(); 759 760 reg_info.byte_offset = reg_info_dict.GetItemForKeyAsInteger(offset_pystr, UINT32_MAX); 761 762 if (reg_info.byte_offset == UINT32_MAX) 763 { 764 Clear(); 765 return 0; 766 } 767 reg_info.byte_size = reg_info_dict.GetItemForKeyAsInteger(bitsize_pystr, 0) / 8; 768 769 if (reg_info.byte_size == 0) 770 { 771 Clear(); 772 return 0; 773 } 774 775 const char *format_cstr = reg_info_dict.GetItemForKeyAsString(format_pystr); 776 if (format_cstr) 777 { 778 if (Args::StringToFormat(format_cstr, reg_info.format, NULL).Fail()) 779 { 780 Clear(); 781 return 0; 782 } 783 } 784 else 785 { 786 reg_info.format = (Format)reg_info_dict.GetItemForKeyAsInteger (format_pystr, eFormatHex); 787 } 788 789 const char *encoding_cstr = reg_info_dict.GetItemForKeyAsString(encoding_pystr); 790 if (encoding_cstr) 791 reg_info.encoding = Args::StringToEncoding (encoding_cstr, eEncodingUint); 792 else 793 reg_info.encoding = (Encoding)reg_info_dict.GetItemForKeyAsInteger (encoding_pystr, eEncodingUint); 794 795 const int64_t set = reg_info_dict.GetItemForKeyAsInteger(set_pystr, -1); 796 if (set >= m_sets.size()) 797 { 798 Clear(); 799 return 0; 800 } 801 802 reg_info.kinds[lldb::eRegisterKindLLDB] = i; 803 reg_info.kinds[lldb::eRegisterKindGDB] = reg_info_dict.GetItemForKeyAsInteger(gdb_pystr , LLDB_INVALID_REGNUM); 804 reg_info.kinds[lldb::eRegisterKindGCC] = reg_info_dict.GetItemForKeyAsInteger(gcc_pystr , LLDB_INVALID_REGNUM); 805 reg_info.kinds[lldb::eRegisterKindDWARF] = reg_info_dict.GetItemForKeyAsInteger(dwarf_pystr , LLDB_INVALID_REGNUM); 806 const char *generic_cstr = reg_info_dict.GetItemForKeyAsString(generic_pystr); 807 if (generic_cstr) 808 reg_info.kinds[lldb::eRegisterKindGeneric] = Args::StringToGenericRegister (generic_cstr); 809 else 810 reg_info.kinds[lldb::eRegisterKindGeneric] = reg_info_dict.GetItemForKeyAsInteger(generic_pystr, LLDB_INVALID_REGNUM); 811 const size_t end_reg_offset = reg_info.byte_offset + reg_info.byte_size; 812 if (m_reg_data_byte_size < end_reg_offset) 813 m_reg_data_byte_size = end_reg_offset; 814 815 m_regs.push_back (reg_info); 816 m_set_reg_nums[set].push_back(i); 817 818 } 819 else 820 { 821 Clear(); 822 return 0; 823 } 824 } 825 Finalize (); 826 } 827 #endif 828 return 0; 829 } 830 831 void 832 GDBRemoteDynamicRegisterInfo::HardcodeARMRegisters(bool from_scratch) 833 { 834 // For Advanced SIMD and VFP register mapping. 835 static uint32_t g_d0_regs[] = { 26, 27, LLDB_INVALID_REGNUM }; // (s0, s1) 836 static uint32_t g_d1_regs[] = { 28, 29, LLDB_INVALID_REGNUM }; // (s2, s3) 837 static uint32_t g_d2_regs[] = { 30, 31, LLDB_INVALID_REGNUM }; // (s4, s5) 838 static uint32_t g_d3_regs[] = { 32, 33, LLDB_INVALID_REGNUM }; // (s6, s7) 839 static uint32_t g_d4_regs[] = { 34, 35, LLDB_INVALID_REGNUM }; // (s8, s9) 840 static uint32_t g_d5_regs[] = { 36, 37, LLDB_INVALID_REGNUM }; // (s10, s11) 841 static uint32_t g_d6_regs[] = { 38, 39, LLDB_INVALID_REGNUM }; // (s12, s13) 842 static uint32_t g_d7_regs[] = { 40, 41, LLDB_INVALID_REGNUM }; // (s14, s15) 843 static uint32_t g_d8_regs[] = { 42, 43, LLDB_INVALID_REGNUM }; // (s16, s17) 844 static uint32_t g_d9_regs[] = { 44, 45, LLDB_INVALID_REGNUM }; // (s18, s19) 845 static uint32_t g_d10_regs[] = { 46, 47, LLDB_INVALID_REGNUM }; // (s20, s21) 846 static uint32_t g_d11_regs[] = { 48, 49, LLDB_INVALID_REGNUM }; // (s22, s23) 847 static uint32_t g_d12_regs[] = { 50, 51, LLDB_INVALID_REGNUM }; // (s24, s25) 848 static uint32_t g_d13_regs[] = { 52, 53, LLDB_INVALID_REGNUM }; // (s26, s27) 849 static uint32_t g_d14_regs[] = { 54, 55, LLDB_INVALID_REGNUM }; // (s28, s29) 850 static uint32_t g_d15_regs[] = { 56, 57, LLDB_INVALID_REGNUM }; // (s30, s31) 851 static uint32_t g_q0_regs[] = { 26, 27, 28, 29, LLDB_INVALID_REGNUM }; // (d0, d1) -> (s0, s1, s2, s3) 852 static uint32_t g_q1_regs[] = { 30, 31, 32, 33, LLDB_INVALID_REGNUM }; // (d2, d3) -> (s4, s5, s6, s7) 853 static uint32_t g_q2_regs[] = { 34, 35, 36, 37, LLDB_INVALID_REGNUM }; // (d4, d5) -> (s8, s9, s10, s11) 854 static uint32_t g_q3_regs[] = { 38, 39, 40, 41, LLDB_INVALID_REGNUM }; // (d6, d7) -> (s12, s13, s14, s15) 855 static uint32_t g_q4_regs[] = { 42, 43, 44, 45, LLDB_INVALID_REGNUM }; // (d8, d9) -> (s16, s17, s18, s19) 856 static uint32_t g_q5_regs[] = { 46, 47, 48, 49, LLDB_INVALID_REGNUM }; // (d10, d11) -> (s20, s21, s22, s23) 857 static uint32_t g_q6_regs[] = { 50, 51, 52, 53, LLDB_INVALID_REGNUM }; // (d12, d13) -> (s24, s25, s26, s27) 858 static uint32_t g_q7_regs[] = { 54, 55, 56, 57, LLDB_INVALID_REGNUM }; // (d14, d15) -> (s28, s29, s30, s31) 859 static uint32_t g_q8_regs[] = { 59, 60, LLDB_INVALID_REGNUM }; // (d16, d17) 860 static uint32_t g_q9_regs[] = { 61, 62, LLDB_INVALID_REGNUM }; // (d18, d19) 861 static uint32_t g_q10_regs[] = { 63, 64, LLDB_INVALID_REGNUM }; // (d20, d21) 862 static uint32_t g_q11_regs[] = { 65, 66, LLDB_INVALID_REGNUM }; // (d22, d23) 863 static uint32_t g_q12_regs[] = { 67, 68, LLDB_INVALID_REGNUM }; // (d24, d25) 864 static uint32_t g_q13_regs[] = { 69, 70, LLDB_INVALID_REGNUM }; // (d26, d27) 865 static uint32_t g_q14_regs[] = { 71, 72, LLDB_INVALID_REGNUM }; // (d28, d29) 866 static uint32_t g_q15_regs[] = { 73, 74, LLDB_INVALID_REGNUM }; // (d30, d31) 867 868 // This is our array of composite registers, with each element coming from the above register mappings. 869 static uint32_t *g_composites[] = { 870 g_d0_regs, g_d1_regs, g_d2_regs, g_d3_regs, g_d4_regs, g_d5_regs, g_d6_regs, g_d7_regs, 871 g_d8_regs, g_d9_regs, g_d10_regs, g_d11_regs, g_d12_regs, g_d13_regs, g_d14_regs, g_d15_regs, 872 g_q0_regs, g_q1_regs, g_q2_regs, g_q3_regs, g_q4_regs, g_q5_regs, g_q6_regs, g_q7_regs, 873 g_q8_regs, g_q9_regs, g_q10_regs, g_q11_regs, g_q12_regs, g_q13_regs, g_q14_regs, g_q15_regs 874 }; 875 876 static RegisterInfo g_register_infos[] = { 877 // NAME ALT SZ OFF ENCODING FORMAT COMPILER DWARF GENERIC GDB LLDB VALUE REGS INVALIDATE REGS 878 // ====== ====== === === ============= ============ =================== =================== ====================== === ==== ========== =============== 879 { "r0", "arg1", 4, 0, eEncodingUint, eFormatHex, { gcc_r0, dwarf_r0, LLDB_REGNUM_GENERIC_ARG1,0, 0 }, NULL, NULL}, 880 { "r1", "arg2", 4, 0, eEncodingUint, eFormatHex, { gcc_r1, dwarf_r1, LLDB_REGNUM_GENERIC_ARG2,1, 1 }, NULL, NULL}, 881 { "r2", "arg3", 4, 0, eEncodingUint, eFormatHex, { gcc_r2, dwarf_r2, LLDB_REGNUM_GENERIC_ARG3,2, 2 }, NULL, NULL}, 882 { "r3", "arg4", 4, 0, eEncodingUint, eFormatHex, { gcc_r3, dwarf_r3, LLDB_REGNUM_GENERIC_ARG4,3, 3 }, NULL, NULL}, 883 { "r4", NULL, 4, 0, eEncodingUint, eFormatHex, { gcc_r4, dwarf_r4, LLDB_INVALID_REGNUM, 4, 4 }, NULL, NULL}, 884 { "r5", NULL, 4, 0, eEncodingUint, eFormatHex, { gcc_r5, dwarf_r5, LLDB_INVALID_REGNUM, 5, 5 }, NULL, NULL}, 885 { "r6", NULL, 4, 0, eEncodingUint, eFormatHex, { gcc_r6, dwarf_r6, LLDB_INVALID_REGNUM, 6, 6 }, NULL, NULL}, 886 { "r7", "fp", 4, 0, eEncodingUint, eFormatHex, { gcc_r7, dwarf_r7, LLDB_REGNUM_GENERIC_FP, 7, 7 }, NULL, NULL}, 887 { "r8", NULL, 4, 0, eEncodingUint, eFormatHex, { gcc_r8, dwarf_r8, LLDB_INVALID_REGNUM, 8, 8 }, NULL, NULL}, 888 { "r9", NULL, 4, 0, eEncodingUint, eFormatHex, { gcc_r9, dwarf_r9, LLDB_INVALID_REGNUM, 9, 9 }, NULL, NULL}, 889 { "r10", NULL, 4, 0, eEncodingUint, eFormatHex, { gcc_r10, dwarf_r10, LLDB_INVALID_REGNUM, 10, 10 }, NULL, NULL}, 890 { "r11", NULL, 4, 0, eEncodingUint, eFormatHex, { gcc_r11, dwarf_r11, LLDB_INVALID_REGNUM, 11, 11 }, NULL, NULL}, 891 { "r12", NULL, 4, 0, eEncodingUint, eFormatHex, { gcc_r12, dwarf_r12, LLDB_INVALID_REGNUM, 12, 12 }, NULL, NULL}, 892 { "sp", "r13", 4, 0, eEncodingUint, eFormatHex, { gcc_sp, dwarf_sp, LLDB_REGNUM_GENERIC_SP, 13, 13 }, NULL, NULL}, 893 { "lr", "r14", 4, 0, eEncodingUint, eFormatHex, { gcc_lr, dwarf_lr, LLDB_REGNUM_GENERIC_RA, 14, 14 }, NULL, NULL}, 894 { "pc", "r15", 4, 0, eEncodingUint, eFormatHex, { gcc_pc, dwarf_pc, LLDB_REGNUM_GENERIC_PC, 15, 15 }, NULL, NULL}, 895 { "f0", NULL, 12, 0, eEncodingUint, eFormatHex, { LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM, 16, 16 }, NULL, NULL}, 896 { "f1", NULL, 12, 0, eEncodingUint, eFormatHex, { LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM, 17, 17 }, NULL, NULL}, 897 { "f2", NULL, 12, 0, eEncodingUint, eFormatHex, { LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM, 18, 18 }, NULL, NULL}, 898 { "f3", NULL, 12, 0, eEncodingUint, eFormatHex, { LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM, 19, 19 }, NULL, NULL}, 899 { "f4", NULL, 12, 0, eEncodingUint, eFormatHex, { LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM, 20, 20 }, NULL, NULL}, 900 { "f5", NULL, 12, 0, eEncodingUint, eFormatHex, { LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM, 21, 21 }, NULL, NULL}, 901 { "f6", NULL, 12, 0, eEncodingUint, eFormatHex, { LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM, 22, 22 }, NULL, NULL}, 902 { "f7", NULL, 12, 0, eEncodingUint, eFormatHex, { LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM, 23, 23 }, NULL, NULL}, 903 { "fps", NULL, 4, 0, eEncodingUint, eFormatHex, { LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM, 24, 24 }, NULL, NULL}, 904 { "cpsr","flags", 4, 0, eEncodingUint, eFormatHex, { gcc_cpsr, dwarf_cpsr, LLDB_INVALID_REGNUM, 25, 25 }, NULL, NULL}, 905 { "s0", NULL, 4, 0, eEncodingIEEE754, eFormatFloat, { LLDB_INVALID_REGNUM, dwarf_s0, LLDB_INVALID_REGNUM, 26, 26 }, NULL, NULL}, 906 { "s1", NULL, 4, 0, eEncodingIEEE754, eFormatFloat, { LLDB_INVALID_REGNUM, dwarf_s1, LLDB_INVALID_REGNUM, 27, 27 }, NULL, NULL}, 907 { "s2", NULL, 4, 0, eEncodingIEEE754, eFormatFloat, { LLDB_INVALID_REGNUM, dwarf_s2, LLDB_INVALID_REGNUM, 28, 28 }, NULL, NULL}, 908 { "s3", NULL, 4, 0, eEncodingIEEE754, eFormatFloat, { LLDB_INVALID_REGNUM, dwarf_s3, LLDB_INVALID_REGNUM, 29, 29 }, NULL, NULL}, 909 { "s4", NULL, 4, 0, eEncodingIEEE754, eFormatFloat, { LLDB_INVALID_REGNUM, dwarf_s4, LLDB_INVALID_REGNUM, 30, 30 }, NULL, NULL}, 910 { "s5", NULL, 4, 0, eEncodingIEEE754, eFormatFloat, { LLDB_INVALID_REGNUM, dwarf_s5, LLDB_INVALID_REGNUM, 31, 31 }, NULL, NULL}, 911 { "s6", NULL, 4, 0, eEncodingIEEE754, eFormatFloat, { LLDB_INVALID_REGNUM, dwarf_s6, LLDB_INVALID_REGNUM, 32, 32 }, NULL, NULL}, 912 { "s7", NULL, 4, 0, eEncodingIEEE754, eFormatFloat, { LLDB_INVALID_REGNUM, dwarf_s7, LLDB_INVALID_REGNUM, 33, 33 }, NULL, NULL}, 913 { "s8", NULL, 4, 0, eEncodingIEEE754, eFormatFloat, { LLDB_INVALID_REGNUM, dwarf_s8, LLDB_INVALID_REGNUM, 34, 34 }, NULL, NULL}, 914 { "s9", NULL, 4, 0, eEncodingIEEE754, eFormatFloat, { LLDB_INVALID_REGNUM, dwarf_s9, LLDB_INVALID_REGNUM, 35, 35 }, NULL, NULL}, 915 { "s10", NULL, 4, 0, eEncodingIEEE754, eFormatFloat, { LLDB_INVALID_REGNUM, dwarf_s10, LLDB_INVALID_REGNUM, 36, 36 }, NULL, NULL}, 916 { "s11", NULL, 4, 0, eEncodingIEEE754, eFormatFloat, { LLDB_INVALID_REGNUM, dwarf_s11, LLDB_INVALID_REGNUM, 37, 37 }, NULL, NULL}, 917 { "s12", NULL, 4, 0, eEncodingIEEE754, eFormatFloat, { LLDB_INVALID_REGNUM, dwarf_s12, LLDB_INVALID_REGNUM, 38, 38 }, NULL, NULL}, 918 { "s13", NULL, 4, 0, eEncodingIEEE754, eFormatFloat, { LLDB_INVALID_REGNUM, dwarf_s13, LLDB_INVALID_REGNUM, 39, 39 }, NULL, NULL}, 919 { "s14", NULL, 4, 0, eEncodingIEEE754, eFormatFloat, { LLDB_INVALID_REGNUM, dwarf_s14, LLDB_INVALID_REGNUM, 40, 40 }, NULL, NULL}, 920 { "s15", NULL, 4, 0, eEncodingIEEE754, eFormatFloat, { LLDB_INVALID_REGNUM, dwarf_s15, LLDB_INVALID_REGNUM, 41, 41 }, NULL, NULL}, 921 { "s16", NULL, 4, 0, eEncodingIEEE754, eFormatFloat, { LLDB_INVALID_REGNUM, dwarf_s16, LLDB_INVALID_REGNUM, 42, 42 }, NULL, NULL}, 922 { "s17", NULL, 4, 0, eEncodingIEEE754, eFormatFloat, { LLDB_INVALID_REGNUM, dwarf_s17, LLDB_INVALID_REGNUM, 43, 43 }, NULL, NULL}, 923 { "s18", NULL, 4, 0, eEncodingIEEE754, eFormatFloat, { LLDB_INVALID_REGNUM, dwarf_s18, LLDB_INVALID_REGNUM, 44, 44 }, NULL, NULL}, 924 { "s19", NULL, 4, 0, eEncodingIEEE754, eFormatFloat, { LLDB_INVALID_REGNUM, dwarf_s19, LLDB_INVALID_REGNUM, 45, 45 }, NULL, NULL}, 925 { "s20", NULL, 4, 0, eEncodingIEEE754, eFormatFloat, { LLDB_INVALID_REGNUM, dwarf_s20, LLDB_INVALID_REGNUM, 46, 46 }, NULL, NULL}, 926 { "s21", NULL, 4, 0, eEncodingIEEE754, eFormatFloat, { LLDB_INVALID_REGNUM, dwarf_s21, LLDB_INVALID_REGNUM, 47, 47 }, NULL, NULL}, 927 { "s22", NULL, 4, 0, eEncodingIEEE754, eFormatFloat, { LLDB_INVALID_REGNUM, dwarf_s22, LLDB_INVALID_REGNUM, 48, 48 }, NULL, NULL}, 928 { "s23", NULL, 4, 0, eEncodingIEEE754, eFormatFloat, { LLDB_INVALID_REGNUM, dwarf_s23, LLDB_INVALID_REGNUM, 49, 49 }, NULL, NULL}, 929 { "s24", NULL, 4, 0, eEncodingIEEE754, eFormatFloat, { LLDB_INVALID_REGNUM, dwarf_s24, LLDB_INVALID_REGNUM, 50, 50 }, NULL, NULL}, 930 { "s25", NULL, 4, 0, eEncodingIEEE754, eFormatFloat, { LLDB_INVALID_REGNUM, dwarf_s25, LLDB_INVALID_REGNUM, 51, 51 }, NULL, NULL}, 931 { "s26", NULL, 4, 0, eEncodingIEEE754, eFormatFloat, { LLDB_INVALID_REGNUM, dwarf_s26, LLDB_INVALID_REGNUM, 52, 52 }, NULL, NULL}, 932 { "s27", NULL, 4, 0, eEncodingIEEE754, eFormatFloat, { LLDB_INVALID_REGNUM, dwarf_s27, LLDB_INVALID_REGNUM, 53, 53 }, NULL, NULL}, 933 { "s28", NULL, 4, 0, eEncodingIEEE754, eFormatFloat, { LLDB_INVALID_REGNUM, dwarf_s28, LLDB_INVALID_REGNUM, 54, 54 }, NULL, NULL}, 934 { "s29", NULL, 4, 0, eEncodingIEEE754, eFormatFloat, { LLDB_INVALID_REGNUM, dwarf_s29, LLDB_INVALID_REGNUM, 55, 55 }, NULL, NULL}, 935 { "s30", NULL, 4, 0, eEncodingIEEE754, eFormatFloat, { LLDB_INVALID_REGNUM, dwarf_s30, LLDB_INVALID_REGNUM, 56, 56 }, NULL, NULL}, 936 { "s31", NULL, 4, 0, eEncodingIEEE754, eFormatFloat, { LLDB_INVALID_REGNUM, dwarf_s31, LLDB_INVALID_REGNUM, 57, 57 }, NULL, NULL}, 937 { "fpscr",NULL, 4, 0, eEncodingUint, eFormatHex, { LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM, 58, 58 }, NULL, NULL}, 938 { "d16", NULL, 8, 0, eEncodingIEEE754, eFormatFloat, { LLDB_INVALID_REGNUM, dwarf_d16, LLDB_INVALID_REGNUM, 59, 59 }, NULL, NULL}, 939 { "d17", NULL, 8, 0, eEncodingIEEE754, eFormatFloat, { LLDB_INVALID_REGNUM, dwarf_d17, LLDB_INVALID_REGNUM, 60, 60 }, NULL, NULL}, 940 { "d18", NULL, 8, 0, eEncodingIEEE754, eFormatFloat, { LLDB_INVALID_REGNUM, dwarf_d18, LLDB_INVALID_REGNUM, 61, 61 }, NULL, NULL}, 941 { "d19", NULL, 8, 0, eEncodingIEEE754, eFormatFloat, { LLDB_INVALID_REGNUM, dwarf_d19, LLDB_INVALID_REGNUM, 62, 62 }, NULL, NULL}, 942 { "d20", NULL, 8, 0, eEncodingIEEE754, eFormatFloat, { LLDB_INVALID_REGNUM, dwarf_d20, LLDB_INVALID_REGNUM, 63, 63 }, NULL, NULL}, 943 { "d21", NULL, 8, 0, eEncodingIEEE754, eFormatFloat, { LLDB_INVALID_REGNUM, dwarf_d21, LLDB_INVALID_REGNUM, 64, 64 }, NULL, NULL}, 944 { "d22", NULL, 8, 0, eEncodingIEEE754, eFormatFloat, { LLDB_INVALID_REGNUM, dwarf_d22, LLDB_INVALID_REGNUM, 65, 65 }, NULL, NULL}, 945 { "d23", NULL, 8, 0, eEncodingIEEE754, eFormatFloat, { LLDB_INVALID_REGNUM, dwarf_d23, LLDB_INVALID_REGNUM, 66, 66 }, NULL, NULL}, 946 { "d24", NULL, 8, 0, eEncodingIEEE754, eFormatFloat, { LLDB_INVALID_REGNUM, dwarf_d24, LLDB_INVALID_REGNUM, 67, 67 }, NULL, NULL}, 947 { "d25", NULL, 8, 0, eEncodingIEEE754, eFormatFloat, { LLDB_INVALID_REGNUM, dwarf_d25, LLDB_INVALID_REGNUM, 68, 68 }, NULL, NULL}, 948 { "d26", NULL, 8, 0, eEncodingIEEE754, eFormatFloat, { LLDB_INVALID_REGNUM, dwarf_d26, LLDB_INVALID_REGNUM, 69, 69 }, NULL, NULL}, 949 { "d27", NULL, 8, 0, eEncodingIEEE754, eFormatFloat, { LLDB_INVALID_REGNUM, dwarf_d27, LLDB_INVALID_REGNUM, 70, 70 }, NULL, NULL}, 950 { "d28", NULL, 8, 0, eEncodingIEEE754, eFormatFloat, { LLDB_INVALID_REGNUM, dwarf_d28, LLDB_INVALID_REGNUM, 71, 71 }, NULL, NULL}, 951 { "d29", NULL, 8, 0, eEncodingIEEE754, eFormatFloat, { LLDB_INVALID_REGNUM, dwarf_d29, LLDB_INVALID_REGNUM, 72, 72 }, NULL, NULL}, 952 { "d30", NULL, 8, 0, eEncodingIEEE754, eFormatFloat, { LLDB_INVALID_REGNUM, dwarf_d30, LLDB_INVALID_REGNUM, 73, 73 }, NULL, NULL}, 953 { "d31", NULL, 8, 0, eEncodingIEEE754, eFormatFloat, { LLDB_INVALID_REGNUM, dwarf_d31, LLDB_INVALID_REGNUM, 74, 74 }, NULL, NULL}, 954 { "d0", NULL, 8, 0, eEncodingIEEE754, eFormatFloat, { LLDB_INVALID_REGNUM, dwarf_d0, LLDB_INVALID_REGNUM, 75, 75 }, g_d0_regs, NULL}, 955 { "d1", NULL, 8, 0, eEncodingIEEE754, eFormatFloat, { LLDB_INVALID_REGNUM, dwarf_d1, LLDB_INVALID_REGNUM, 76, 76 }, g_d1_regs, NULL}, 956 { "d2", NULL, 8, 0, eEncodingIEEE754, eFormatFloat, { LLDB_INVALID_REGNUM, dwarf_d2, LLDB_INVALID_REGNUM, 77, 77 }, g_d2_regs, NULL}, 957 { "d3", NULL, 8, 0, eEncodingIEEE754, eFormatFloat, { LLDB_INVALID_REGNUM, dwarf_d3, LLDB_INVALID_REGNUM, 78, 78 }, g_d3_regs, NULL}, 958 { "d4", NULL, 8, 0, eEncodingIEEE754, eFormatFloat, { LLDB_INVALID_REGNUM, dwarf_d4, LLDB_INVALID_REGNUM, 79, 79 }, g_d4_regs, NULL}, 959 { "d5", NULL, 8, 0, eEncodingIEEE754, eFormatFloat, { LLDB_INVALID_REGNUM, dwarf_d5, LLDB_INVALID_REGNUM, 80, 80 }, g_d5_regs, NULL}, 960 { "d6", NULL, 8, 0, eEncodingIEEE754, eFormatFloat, { LLDB_INVALID_REGNUM, dwarf_d6, LLDB_INVALID_REGNUM, 81, 81 }, g_d6_regs, NULL}, 961 { "d7", NULL, 8, 0, eEncodingIEEE754, eFormatFloat, { LLDB_INVALID_REGNUM, dwarf_d7, LLDB_INVALID_REGNUM, 82, 82 }, g_d7_regs, NULL}, 962 { "d8", NULL, 8, 0, eEncodingIEEE754, eFormatFloat, { LLDB_INVALID_REGNUM, dwarf_d8, LLDB_INVALID_REGNUM, 83, 83 }, g_d8_regs, NULL}, 963 { "d9", NULL, 8, 0, eEncodingIEEE754, eFormatFloat, { LLDB_INVALID_REGNUM, dwarf_d9, LLDB_INVALID_REGNUM, 84, 84 }, g_d9_regs, NULL}, 964 { "d10", NULL, 8, 0, eEncodingIEEE754, eFormatFloat, { LLDB_INVALID_REGNUM, dwarf_d10, LLDB_INVALID_REGNUM, 85, 85 }, g_d10_regs, NULL}, 965 { "d11", NULL, 8, 0, eEncodingIEEE754, eFormatFloat, { LLDB_INVALID_REGNUM, dwarf_d11, LLDB_INVALID_REGNUM, 86, 86 }, g_d11_regs, NULL}, 966 { "d12", NULL, 8, 0, eEncodingIEEE754, eFormatFloat, { LLDB_INVALID_REGNUM, dwarf_d12, LLDB_INVALID_REGNUM, 87, 87 }, g_d12_regs, NULL}, 967 { "d13", NULL, 8, 0, eEncodingIEEE754, eFormatFloat, { LLDB_INVALID_REGNUM, dwarf_d13, LLDB_INVALID_REGNUM, 88, 88 }, g_d13_regs, NULL}, 968 { "d14", NULL, 8, 0, eEncodingIEEE754, eFormatFloat, { LLDB_INVALID_REGNUM, dwarf_d14, LLDB_INVALID_REGNUM, 89, 89 }, g_d14_regs, NULL}, 969 { "d15", NULL, 8, 0, eEncodingIEEE754, eFormatFloat, { LLDB_INVALID_REGNUM, dwarf_d15, LLDB_INVALID_REGNUM, 90, 90 }, g_d15_regs, NULL}, 970 { "q0", NULL, 16, 0, eEncodingVector, eFormatVectorOfUInt8, { LLDB_INVALID_REGNUM, dwarf_q0, LLDB_INVALID_REGNUM, 91, 91 }, g_q0_regs, NULL}, 971 { "q1", NULL, 16, 0, eEncodingVector, eFormatVectorOfUInt8, { LLDB_INVALID_REGNUM, dwarf_q1, LLDB_INVALID_REGNUM, 92, 92 }, g_q1_regs, NULL}, 972 { "q2", NULL, 16, 0, eEncodingVector, eFormatVectorOfUInt8, { LLDB_INVALID_REGNUM, dwarf_q2, LLDB_INVALID_REGNUM, 93, 93 }, g_q2_regs, NULL}, 973 { "q3", NULL, 16, 0, eEncodingVector, eFormatVectorOfUInt8, { LLDB_INVALID_REGNUM, dwarf_q3, LLDB_INVALID_REGNUM, 94, 94 }, g_q3_regs, NULL}, 974 { "q4", NULL, 16, 0, eEncodingVector, eFormatVectorOfUInt8, { LLDB_INVALID_REGNUM, dwarf_q4, LLDB_INVALID_REGNUM, 95, 95 }, g_q4_regs, NULL}, 975 { "q5", NULL, 16, 0, eEncodingVector, eFormatVectorOfUInt8, { LLDB_INVALID_REGNUM, dwarf_q5, LLDB_INVALID_REGNUM, 96, 96 }, g_q5_regs, NULL}, 976 { "q6", NULL, 16, 0, eEncodingVector, eFormatVectorOfUInt8, { LLDB_INVALID_REGNUM, dwarf_q6, LLDB_INVALID_REGNUM, 97, 97 }, g_q6_regs, NULL}, 977 { "q7", NULL, 16, 0, eEncodingVector, eFormatVectorOfUInt8, { LLDB_INVALID_REGNUM, dwarf_q7, LLDB_INVALID_REGNUM, 98, 98 }, g_q7_regs, NULL}, 978 { "q8", NULL, 16, 0, eEncodingVector, eFormatVectorOfUInt8, { LLDB_INVALID_REGNUM, dwarf_q8, LLDB_INVALID_REGNUM, 99, 99 }, g_q8_regs, NULL}, 979 { "q9", NULL, 16, 0, eEncodingVector, eFormatVectorOfUInt8, { LLDB_INVALID_REGNUM, dwarf_q9, LLDB_INVALID_REGNUM, 100, 100 }, g_q9_regs, NULL}, 980 { "q10", NULL, 16, 0, eEncodingVector, eFormatVectorOfUInt8, { LLDB_INVALID_REGNUM, dwarf_q10, LLDB_INVALID_REGNUM, 101, 101 }, g_q10_regs, NULL}, 981 { "q11", NULL, 16, 0, eEncodingVector, eFormatVectorOfUInt8, { LLDB_INVALID_REGNUM, dwarf_q11, LLDB_INVALID_REGNUM, 102, 102 }, g_q11_regs, NULL}, 982 { "q12", NULL, 16, 0, eEncodingVector, eFormatVectorOfUInt8, { LLDB_INVALID_REGNUM, dwarf_q12, LLDB_INVALID_REGNUM, 103, 103 }, g_q12_regs, NULL}, 983 { "q13", NULL, 16, 0, eEncodingVector, eFormatVectorOfUInt8, { LLDB_INVALID_REGNUM, dwarf_q13, LLDB_INVALID_REGNUM, 104, 104 }, g_q13_regs, NULL}, 984 { "q14", NULL, 16, 0, eEncodingVector, eFormatVectorOfUInt8, { LLDB_INVALID_REGNUM, dwarf_q14, LLDB_INVALID_REGNUM, 105, 105 }, g_q14_regs, NULL}, 985 { "q15", NULL, 16, 0, eEncodingVector, eFormatVectorOfUInt8, { LLDB_INVALID_REGNUM, dwarf_q15, LLDB_INVALID_REGNUM, 106, 106 }, g_q15_regs, NULL} 986 }; 987 988 static const uint32_t num_registers = llvm::array_lengthof(g_register_infos); 989 static ConstString gpr_reg_set ("General Purpose Registers"); 990 static ConstString sfp_reg_set ("Software Floating Point Registers"); 991 static ConstString vfp_reg_set ("Floating Point Registers"); 992 size_t i; 993 if (from_scratch) 994 { 995 // Calculate the offsets of the registers 996 // Note that the layout of the "composite" registers (d0-d15 and q0-q15) which comes after the 997 // "primordial" registers is important. This enables us to calculate the offset of the composite 998 // register by using the offset of its first primordial register. For example, to calculate the 999 // offset of q0, use s0's offset. 1000 if (g_register_infos[2].byte_offset == 0) 1001 { 1002 uint32_t byte_offset = 0; 1003 for (i=0; i<num_registers; ++i) 1004 { 1005 // For primordial registers, increment the byte_offset by the byte_size to arrive at the 1006 // byte_offset for the next register. Otherwise, we have a composite register whose 1007 // offset can be calculated by consulting the offset of its first primordial register. 1008 if (!g_register_infos[i].value_regs) 1009 { 1010 g_register_infos[i].byte_offset = byte_offset; 1011 byte_offset += g_register_infos[i].byte_size; 1012 } 1013 else 1014 { 1015 const uint32_t first_primordial_reg = g_register_infos[i].value_regs[0]; 1016 g_register_infos[i].byte_offset = g_register_infos[first_primordial_reg].byte_offset; 1017 } 1018 } 1019 } 1020 for (i=0; i<num_registers; ++i) 1021 { 1022 ConstString name; 1023 ConstString alt_name; 1024 if (g_register_infos[i].name && g_register_infos[i].name[0]) 1025 name.SetCString(g_register_infos[i].name); 1026 if (g_register_infos[i].alt_name && g_register_infos[i].alt_name[0]) 1027 alt_name.SetCString(g_register_infos[i].alt_name); 1028 1029 if (i <= 15 || i == 25) 1030 AddRegister (g_register_infos[i], name, alt_name, gpr_reg_set); 1031 else if (i <= 24) 1032 AddRegister (g_register_infos[i], name, alt_name, sfp_reg_set); 1033 else 1034 AddRegister (g_register_infos[i], name, alt_name, vfp_reg_set); 1035 } 1036 } 1037 else 1038 { 1039 // Add composite registers to our primordial registers, then. 1040 const size_t num_composites = llvm::array_lengthof(g_composites); 1041 const size_t num_dynamic_regs = GetNumRegisters(); 1042 const size_t num_common_regs = num_registers - num_composites; 1043 RegisterInfo *g_comp_register_infos = g_register_infos + num_common_regs; 1044 1045 // First we need to validate that all registers that we already have match the non composite regs. 1046 // If so, then we can add the registers, else we need to bail 1047 bool match = true; 1048 if (num_dynamic_regs == num_common_regs) 1049 { 1050 for (i=0; match && i<num_dynamic_regs; ++i) 1051 { 1052 // Make sure all register names match 1053 if (m_regs[i].name && g_register_infos[i].name) 1054 { 1055 if (strcmp(m_regs[i].name, g_register_infos[i].name)) 1056 { 1057 match = false; 1058 break; 1059 } 1060 } 1061 1062 // Make sure all register byte sizes match 1063 if (m_regs[i].byte_size != g_register_infos[i].byte_size) 1064 { 1065 match = false; 1066 break; 1067 } 1068 } 1069 } 1070 else 1071 { 1072 // Wrong number of registers. 1073 match = false; 1074 } 1075 // If "match" is true, then we can add extra registers. 1076 if (match) 1077 { 1078 for (i=0; i<num_composites; ++i) 1079 { 1080 ConstString name; 1081 ConstString alt_name; 1082 const uint32_t first_primordial_reg = g_comp_register_infos[i].value_regs[0]; 1083 const char *reg_name = g_register_infos[first_primordial_reg].name; 1084 if (reg_name && reg_name[0]) 1085 { 1086 for (uint32_t j = 0; j < num_dynamic_regs; ++j) 1087 { 1088 const RegisterInfo *reg_info = GetRegisterInfoAtIndex(j); 1089 // Find a matching primordial register info entry. 1090 if (reg_info && reg_info->name && ::strcasecmp(reg_info->name, reg_name) == 0) 1091 { 1092 // The name matches the existing primordial entry. 1093 // Find and assign the offset, and then add this composite register entry. 1094 g_comp_register_infos[i].byte_offset = reg_info->byte_offset; 1095 name.SetCString(g_comp_register_infos[i].name); 1096 AddRegister(g_comp_register_infos[i], name, alt_name, vfp_reg_set); 1097 } 1098 } 1099 } 1100 } 1101 } 1102 } 1103 } 1104