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