1 //===-- ABIMacOSX_arm.cpp -------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #include "ABIMacOSX_arm.h"
10 
11 #include <vector>
12 
13 #include "llvm/ADT/STLExtras.h"
14 #include "llvm/ADT/Triple.h"
15 
16 #include "lldb/Core/Module.h"
17 #include "lldb/Core/PluginManager.h"
18 #include "lldb/Core/Value.h"
19 #include "lldb/Core/ValueObjectConstResult.h"
20 #include "lldb/Symbol/UnwindPlan.h"
21 #include "lldb/Target/Process.h"
22 #include "lldb/Target/RegisterContext.h"
23 #include "lldb/Target/Target.h"
24 #include "lldb/Target/Thread.h"
25 #include "lldb/Utility/ConstString.h"
26 #include "lldb/Utility/RegisterValue.h"
27 #include "lldb/Utility/Scalar.h"
28 #include "lldb/Utility/Status.h"
29 
30 #include "Plugins/Process/Utility/ARMDefines.h"
31 #include "Utility/ARM_DWARF_Registers.h"
32 #include "Utility/ARM_ehframe_Registers.h"
33 
34 using namespace lldb;
35 using namespace lldb_private;
36 
37 static RegisterInfo g_register_infos[] = {
38     //  NAME       ALT       SZ OFF ENCODING         FORMAT          EH_FRAME
39     //  DWARF               GENERIC                     PROCESS PLUGIN
40     //  LLDB NATIVE
41     //  ========== =======   == === =============    ============
42     //  ======================= =================== ===========================
43     //  ======================= ======================
44     {"r0",
45      "arg1",
46      4,
47      0,
48      eEncodingUint,
49      eFormatHex,
50      {ehframe_r0, dwarf_r0, LLDB_REGNUM_GENERIC_ARG1, LLDB_INVALID_REGNUM,
51       LLDB_INVALID_REGNUM},
52      nullptr,
53      nullptr,
54      nullptr,
55      0},
56     {"r1",
57      "arg2",
58      4,
59      0,
60      eEncodingUint,
61      eFormatHex,
62      {ehframe_r1, dwarf_r1, LLDB_REGNUM_GENERIC_ARG2, LLDB_INVALID_REGNUM,
63       LLDB_INVALID_REGNUM},
64      nullptr,
65      nullptr,
66      nullptr,
67      0},
68     {"r2",
69      "arg3",
70      4,
71      0,
72      eEncodingUint,
73      eFormatHex,
74      {ehframe_r2, dwarf_r2, LLDB_REGNUM_GENERIC_ARG3, LLDB_INVALID_REGNUM,
75       LLDB_INVALID_REGNUM},
76      nullptr,
77      nullptr,
78      nullptr,
79      0},
80     {"r3",
81      "arg4",
82      4,
83      0,
84      eEncodingUint,
85      eFormatHex,
86      {ehframe_r3, dwarf_r3, LLDB_REGNUM_GENERIC_ARG4, LLDB_INVALID_REGNUM,
87       LLDB_INVALID_REGNUM},
88      nullptr,
89      nullptr,
90      nullptr,
91      0},
92     {"r4",
93      nullptr,
94      4,
95      0,
96      eEncodingUint,
97      eFormatHex,
98      {ehframe_r4, dwarf_r4, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM,
99       LLDB_INVALID_REGNUM},
100      nullptr,
101      nullptr,
102      nullptr,
103      0},
104     {"r5",
105      nullptr,
106      4,
107      0,
108      eEncodingUint,
109      eFormatHex,
110      {ehframe_r5, dwarf_r5, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM,
111       LLDB_INVALID_REGNUM},
112      nullptr,
113      nullptr,
114      nullptr,
115      0},
116     {"r6",
117      nullptr,
118      4,
119      0,
120      eEncodingUint,
121      eFormatHex,
122      {ehframe_r6, dwarf_r6, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM,
123       LLDB_INVALID_REGNUM},
124      nullptr,
125      nullptr,
126      nullptr,
127      0},
128     {"r7",
129      nullptr,
130      4,
131      0,
132      eEncodingUint,
133      eFormatHex,
134      {ehframe_r7, dwarf_r7, LLDB_REGNUM_GENERIC_FP, LLDB_INVALID_REGNUM,
135       LLDB_INVALID_REGNUM},
136      nullptr,
137      nullptr,
138      nullptr,
139      0},
140     {"r8",
141      nullptr,
142      4,
143      0,
144      eEncodingUint,
145      eFormatHex,
146      {ehframe_r8, dwarf_r8, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM,
147       LLDB_INVALID_REGNUM},
148      nullptr,
149      nullptr,
150      nullptr,
151      0},
152     {"r9",
153      nullptr,
154      4,
155      0,
156      eEncodingUint,
157      eFormatHex,
158      {ehframe_r9, dwarf_r9, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM,
159       LLDB_INVALID_REGNUM},
160      nullptr,
161      nullptr,
162      nullptr,
163      0},
164     {"r10",
165      nullptr,
166      4,
167      0,
168      eEncodingUint,
169      eFormatHex,
170      {ehframe_r10, dwarf_r10, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM,
171       LLDB_INVALID_REGNUM},
172      nullptr,
173      nullptr,
174      nullptr,
175      0},
176     {"r11",
177      nullptr,
178      4,
179      0,
180      eEncodingUint,
181      eFormatHex,
182      {ehframe_r11, dwarf_r11, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM,
183       LLDB_INVALID_REGNUM},
184      nullptr,
185      nullptr,
186      nullptr,
187      0},
188     {"r12",
189      nullptr,
190      4,
191      0,
192      eEncodingUint,
193      eFormatHex,
194      {ehframe_r12, dwarf_r12, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM,
195       LLDB_INVALID_REGNUM},
196      nullptr,
197      nullptr,
198      nullptr,
199      0},
200     {"sp",
201      "r13",
202      4,
203      0,
204      eEncodingUint,
205      eFormatHex,
206      {ehframe_sp, dwarf_sp, LLDB_REGNUM_GENERIC_SP, LLDB_INVALID_REGNUM,
207       LLDB_INVALID_REGNUM},
208      nullptr,
209      nullptr,
210      nullptr,
211      0},
212     {"lr",
213      "r14",
214      4,
215      0,
216      eEncodingUint,
217      eFormatHex,
218      {ehframe_lr, dwarf_lr, LLDB_REGNUM_GENERIC_RA, LLDB_INVALID_REGNUM,
219       LLDB_INVALID_REGNUM},
220      nullptr,
221      nullptr,
222      nullptr,
223      0},
224     {"pc",
225      "r15",
226      4,
227      0,
228      eEncodingUint,
229      eFormatHex,
230      {ehframe_pc, dwarf_pc, LLDB_REGNUM_GENERIC_PC, LLDB_INVALID_REGNUM,
231       LLDB_INVALID_REGNUM},
232      nullptr,
233      nullptr,
234      nullptr,
235      0},
236     {"cpsr",
237      "psr",
238      4,
239      0,
240      eEncodingUint,
241      eFormatHex,
242      {ehframe_cpsr, dwarf_cpsr, LLDB_REGNUM_GENERIC_FLAGS, LLDB_INVALID_REGNUM,
243       LLDB_INVALID_REGNUM},
244      nullptr,
245      nullptr,
246      nullptr,
247      0},
248     {"s0",
249      nullptr,
250      4,
251      0,
252      eEncodingIEEE754,
253      eFormatFloat,
254      {LLDB_INVALID_REGNUM, dwarf_s0, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM,
255       LLDB_INVALID_REGNUM},
256      nullptr,
257      nullptr,
258      nullptr,
259      0},
260     {"s1",
261      nullptr,
262      4,
263      0,
264      eEncodingIEEE754,
265      eFormatFloat,
266      {LLDB_INVALID_REGNUM, dwarf_s1, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM,
267       LLDB_INVALID_REGNUM},
268      nullptr,
269      nullptr,
270      nullptr,
271      0},
272     {"s2",
273      nullptr,
274      4,
275      0,
276      eEncodingIEEE754,
277      eFormatFloat,
278      {LLDB_INVALID_REGNUM, dwarf_s2, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM,
279       LLDB_INVALID_REGNUM},
280      nullptr,
281      nullptr,
282      nullptr,
283      0},
284     {"s3",
285      nullptr,
286      4,
287      0,
288      eEncodingIEEE754,
289      eFormatFloat,
290      {LLDB_INVALID_REGNUM, dwarf_s3, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM,
291       LLDB_INVALID_REGNUM},
292      nullptr,
293      nullptr,
294      nullptr,
295      0},
296     {"s4",
297      nullptr,
298      4,
299      0,
300      eEncodingIEEE754,
301      eFormatFloat,
302      {LLDB_INVALID_REGNUM, dwarf_s4, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM,
303       LLDB_INVALID_REGNUM},
304      nullptr,
305      nullptr,
306      nullptr,
307      0},
308     {"s5",
309      nullptr,
310      4,
311      0,
312      eEncodingIEEE754,
313      eFormatFloat,
314      {LLDB_INVALID_REGNUM, dwarf_s5, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM,
315       LLDB_INVALID_REGNUM},
316      nullptr,
317      nullptr,
318      nullptr,
319      0},
320     {"s6",
321      nullptr,
322      4,
323      0,
324      eEncodingIEEE754,
325      eFormatFloat,
326      {LLDB_INVALID_REGNUM, dwarf_s6, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM,
327       LLDB_INVALID_REGNUM},
328      nullptr,
329      nullptr,
330      nullptr,
331      0},
332     {"s7",
333      nullptr,
334      4,
335      0,
336      eEncodingIEEE754,
337      eFormatFloat,
338      {LLDB_INVALID_REGNUM, dwarf_s7, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM,
339       LLDB_INVALID_REGNUM},
340      nullptr,
341      nullptr,
342      nullptr,
343      0},
344     {"s8",
345      nullptr,
346      4,
347      0,
348      eEncodingIEEE754,
349      eFormatFloat,
350      {LLDB_INVALID_REGNUM, dwarf_s8, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM,
351       LLDB_INVALID_REGNUM},
352      nullptr,
353      nullptr,
354      nullptr,
355      0},
356     {"s9",
357      nullptr,
358      4,
359      0,
360      eEncodingIEEE754,
361      eFormatFloat,
362      {LLDB_INVALID_REGNUM, dwarf_s9, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM,
363       LLDB_INVALID_REGNUM},
364      nullptr,
365      nullptr,
366      nullptr,
367      0},
368     {"s10",
369      nullptr,
370      4,
371      0,
372      eEncodingIEEE754,
373      eFormatFloat,
374      {LLDB_INVALID_REGNUM, dwarf_s10, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM,
375       LLDB_INVALID_REGNUM},
376      nullptr,
377      nullptr,
378      nullptr,
379      0},
380     {"s11",
381      nullptr,
382      4,
383      0,
384      eEncodingIEEE754,
385      eFormatFloat,
386      {LLDB_INVALID_REGNUM, dwarf_s11, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM,
387       LLDB_INVALID_REGNUM},
388      nullptr,
389      nullptr,
390      nullptr,
391      0},
392     {"s12",
393      nullptr,
394      4,
395      0,
396      eEncodingIEEE754,
397      eFormatFloat,
398      {LLDB_INVALID_REGNUM, dwarf_s12, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM,
399       LLDB_INVALID_REGNUM},
400      nullptr,
401      nullptr,
402      nullptr,
403      0},
404     {"s13",
405      nullptr,
406      4,
407      0,
408      eEncodingIEEE754,
409      eFormatFloat,
410      {LLDB_INVALID_REGNUM, dwarf_s13, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM,
411       LLDB_INVALID_REGNUM},
412      nullptr,
413      nullptr,
414      nullptr,
415      0},
416     {"s14",
417      nullptr,
418      4,
419      0,
420      eEncodingIEEE754,
421      eFormatFloat,
422      {LLDB_INVALID_REGNUM, dwarf_s14, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM,
423       LLDB_INVALID_REGNUM},
424      nullptr,
425      nullptr,
426      nullptr,
427      0},
428     {"s15",
429      nullptr,
430      4,
431      0,
432      eEncodingIEEE754,
433      eFormatFloat,
434      {LLDB_INVALID_REGNUM, dwarf_s15, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM,
435       LLDB_INVALID_REGNUM},
436      nullptr,
437      nullptr,
438      nullptr,
439      0},
440     {"s16",
441      nullptr,
442      4,
443      0,
444      eEncodingIEEE754,
445      eFormatFloat,
446      {LLDB_INVALID_REGNUM, dwarf_s16, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM,
447       LLDB_INVALID_REGNUM},
448      nullptr,
449      nullptr,
450      nullptr,
451      0},
452     {"s17",
453      nullptr,
454      4,
455      0,
456      eEncodingIEEE754,
457      eFormatFloat,
458      {LLDB_INVALID_REGNUM, dwarf_s17, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM,
459       LLDB_INVALID_REGNUM},
460      nullptr,
461      nullptr,
462      nullptr,
463      0},
464     {"s18",
465      nullptr,
466      4,
467      0,
468      eEncodingIEEE754,
469      eFormatFloat,
470      {LLDB_INVALID_REGNUM, dwarf_s18, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM,
471       LLDB_INVALID_REGNUM},
472      nullptr,
473      nullptr,
474      nullptr,
475      0},
476     {"s19",
477      nullptr,
478      4,
479      0,
480      eEncodingIEEE754,
481      eFormatFloat,
482      {LLDB_INVALID_REGNUM, dwarf_s19, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM,
483       LLDB_INVALID_REGNUM},
484      nullptr,
485      nullptr,
486      nullptr,
487      0},
488     {"s20",
489      nullptr,
490      4,
491      0,
492      eEncodingIEEE754,
493      eFormatFloat,
494      {LLDB_INVALID_REGNUM, dwarf_s20, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM,
495       LLDB_INVALID_REGNUM},
496      nullptr,
497      nullptr,
498      nullptr,
499      0},
500     {"s21",
501      nullptr,
502      4,
503      0,
504      eEncodingIEEE754,
505      eFormatFloat,
506      {LLDB_INVALID_REGNUM, dwarf_s21, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM,
507       LLDB_INVALID_REGNUM},
508      nullptr,
509      nullptr,
510      nullptr,
511      0},
512     {"s22",
513      nullptr,
514      4,
515      0,
516      eEncodingIEEE754,
517      eFormatFloat,
518      {LLDB_INVALID_REGNUM, dwarf_s22, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM,
519       LLDB_INVALID_REGNUM},
520      nullptr,
521      nullptr,
522      nullptr,
523      0},
524     {"s23",
525      nullptr,
526      4,
527      0,
528      eEncodingIEEE754,
529      eFormatFloat,
530      {LLDB_INVALID_REGNUM, dwarf_s23, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM,
531       LLDB_INVALID_REGNUM},
532      nullptr,
533      nullptr,
534      nullptr,
535      0},
536     {"s24",
537      nullptr,
538      4,
539      0,
540      eEncodingIEEE754,
541      eFormatFloat,
542      {LLDB_INVALID_REGNUM, dwarf_s24, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM,
543       LLDB_INVALID_REGNUM},
544      nullptr,
545      nullptr,
546      nullptr,
547      0},
548     {"s25",
549      nullptr,
550      4,
551      0,
552      eEncodingIEEE754,
553      eFormatFloat,
554      {LLDB_INVALID_REGNUM, dwarf_s25, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM,
555       LLDB_INVALID_REGNUM},
556      nullptr,
557      nullptr,
558      nullptr,
559      0},
560     {"s26",
561      nullptr,
562      4,
563      0,
564      eEncodingIEEE754,
565      eFormatFloat,
566      {LLDB_INVALID_REGNUM, dwarf_s26, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM,
567       LLDB_INVALID_REGNUM},
568      nullptr,
569      nullptr,
570      nullptr,
571      0},
572     {"s27",
573      nullptr,
574      4,
575      0,
576      eEncodingIEEE754,
577      eFormatFloat,
578      {LLDB_INVALID_REGNUM, dwarf_s27, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM,
579       LLDB_INVALID_REGNUM},
580      nullptr,
581      nullptr,
582      nullptr,
583      0},
584     {"s28",
585      nullptr,
586      4,
587      0,
588      eEncodingIEEE754,
589      eFormatFloat,
590      {LLDB_INVALID_REGNUM, dwarf_s28, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM,
591       LLDB_INVALID_REGNUM},
592      nullptr,
593      nullptr,
594      nullptr,
595      0},
596     {"s29",
597      nullptr,
598      4,
599      0,
600      eEncodingIEEE754,
601      eFormatFloat,
602      {LLDB_INVALID_REGNUM, dwarf_s29, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM,
603       LLDB_INVALID_REGNUM},
604      nullptr,
605      nullptr,
606      nullptr,
607      0},
608     {"s30",
609      nullptr,
610      4,
611      0,
612      eEncodingIEEE754,
613      eFormatFloat,
614      {LLDB_INVALID_REGNUM, dwarf_s30, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM,
615       LLDB_INVALID_REGNUM},
616      nullptr,
617      nullptr,
618      nullptr,
619      0},
620     {"s31",
621      nullptr,
622      4,
623      0,
624      eEncodingIEEE754,
625      eFormatFloat,
626      {LLDB_INVALID_REGNUM, dwarf_s31, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM,
627       LLDB_INVALID_REGNUM},
628      nullptr,
629      nullptr,
630      nullptr,
631      0},
632     {"fpscr",
633      nullptr,
634      4,
635      0,
636      eEncodingUint,
637      eFormatHex,
638      {LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM,
639       LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM},
640      nullptr,
641      nullptr,
642      nullptr,
643      0},
644     {"d0",
645      nullptr,
646      8,
647      0,
648      eEncodingIEEE754,
649      eFormatFloat,
650      {LLDB_INVALID_REGNUM, dwarf_d0, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM,
651       LLDB_INVALID_REGNUM},
652      nullptr,
653      nullptr,
654      nullptr,
655      0},
656     {"d1",
657      nullptr,
658      8,
659      0,
660      eEncodingIEEE754,
661      eFormatFloat,
662      {LLDB_INVALID_REGNUM, dwarf_d1, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM,
663       LLDB_INVALID_REGNUM},
664      nullptr,
665      nullptr,
666      nullptr,
667      0},
668     {"d2",
669      nullptr,
670      8,
671      0,
672      eEncodingIEEE754,
673      eFormatFloat,
674      {LLDB_INVALID_REGNUM, dwarf_d2, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM,
675       LLDB_INVALID_REGNUM},
676      nullptr,
677      nullptr,
678      nullptr,
679      0},
680     {"d3",
681      nullptr,
682      8,
683      0,
684      eEncodingIEEE754,
685      eFormatFloat,
686      {LLDB_INVALID_REGNUM, dwarf_d3, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM,
687       LLDB_INVALID_REGNUM},
688      nullptr,
689      nullptr,
690      nullptr,
691      0},
692     {"d4",
693      nullptr,
694      8,
695      0,
696      eEncodingIEEE754,
697      eFormatFloat,
698      {LLDB_INVALID_REGNUM, dwarf_d4, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM,
699       LLDB_INVALID_REGNUM},
700      nullptr,
701      nullptr,
702      nullptr,
703      0},
704     {"d5",
705      nullptr,
706      8,
707      0,
708      eEncodingIEEE754,
709      eFormatFloat,
710      {LLDB_INVALID_REGNUM, dwarf_d5, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM,
711       LLDB_INVALID_REGNUM},
712      nullptr,
713      nullptr,
714      nullptr,
715      0},
716     {"d6",
717      nullptr,
718      8,
719      0,
720      eEncodingIEEE754,
721      eFormatFloat,
722      {LLDB_INVALID_REGNUM, dwarf_d6, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM,
723       LLDB_INVALID_REGNUM},
724      nullptr,
725      nullptr,
726      nullptr,
727      0},
728     {"d7",
729      nullptr,
730      8,
731      0,
732      eEncodingIEEE754,
733      eFormatFloat,
734      {LLDB_INVALID_REGNUM, dwarf_d7, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM,
735       LLDB_INVALID_REGNUM},
736      nullptr,
737      nullptr,
738      nullptr,
739      0},
740     {"d8",
741      nullptr,
742      8,
743      0,
744      eEncodingIEEE754,
745      eFormatFloat,
746      {LLDB_INVALID_REGNUM, dwarf_d8, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM,
747       LLDB_INVALID_REGNUM},
748      nullptr,
749      nullptr,
750      nullptr,
751      0},
752     {"d9",
753      nullptr,
754      8,
755      0,
756      eEncodingIEEE754,
757      eFormatFloat,
758      {LLDB_INVALID_REGNUM, dwarf_d9, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM,
759       LLDB_INVALID_REGNUM},
760      nullptr,
761      nullptr,
762      nullptr,
763      0},
764     {"d10",
765      nullptr,
766      8,
767      0,
768      eEncodingIEEE754,
769      eFormatFloat,
770      {LLDB_INVALID_REGNUM, dwarf_d10, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM,
771       LLDB_INVALID_REGNUM},
772      nullptr,
773      nullptr,
774      nullptr,
775      0},
776     {"d11",
777      nullptr,
778      8,
779      0,
780      eEncodingIEEE754,
781      eFormatFloat,
782      {LLDB_INVALID_REGNUM, dwarf_d11, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM,
783       LLDB_INVALID_REGNUM},
784      nullptr,
785      nullptr,
786      nullptr,
787      0},
788     {"d12",
789      nullptr,
790      8,
791      0,
792      eEncodingIEEE754,
793      eFormatFloat,
794      {LLDB_INVALID_REGNUM, dwarf_d12, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM,
795       LLDB_INVALID_REGNUM},
796      nullptr,
797      nullptr,
798      nullptr,
799      0},
800     {"d13",
801      nullptr,
802      8,
803      0,
804      eEncodingIEEE754,
805      eFormatFloat,
806      {LLDB_INVALID_REGNUM, dwarf_d13, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM,
807       LLDB_INVALID_REGNUM},
808      nullptr,
809      nullptr,
810      nullptr,
811      0},
812     {"d14",
813      nullptr,
814      8,
815      0,
816      eEncodingIEEE754,
817      eFormatFloat,
818      {LLDB_INVALID_REGNUM, dwarf_d14, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM,
819       LLDB_INVALID_REGNUM},
820      nullptr,
821      nullptr,
822      nullptr,
823      0},
824     {"d15",
825      nullptr,
826      8,
827      0,
828      eEncodingIEEE754,
829      eFormatFloat,
830      {LLDB_INVALID_REGNUM, dwarf_d15, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM,
831       LLDB_INVALID_REGNUM},
832      nullptr,
833      nullptr,
834      nullptr,
835      0},
836     {"d16",
837      nullptr,
838      8,
839      0,
840      eEncodingIEEE754,
841      eFormatFloat,
842      {LLDB_INVALID_REGNUM, dwarf_d16, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM,
843       LLDB_INVALID_REGNUM},
844      nullptr,
845      nullptr,
846      nullptr,
847      0},
848     {"d17",
849      nullptr,
850      8,
851      0,
852      eEncodingIEEE754,
853      eFormatFloat,
854      {LLDB_INVALID_REGNUM, dwarf_d17, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM,
855       LLDB_INVALID_REGNUM},
856      nullptr,
857      nullptr,
858      nullptr,
859      0},
860     {"d18",
861      nullptr,
862      8,
863      0,
864      eEncodingIEEE754,
865      eFormatFloat,
866      {LLDB_INVALID_REGNUM, dwarf_d18, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM,
867       LLDB_INVALID_REGNUM},
868      nullptr,
869      nullptr,
870      nullptr,
871      0},
872     {"d19",
873      nullptr,
874      8,
875      0,
876      eEncodingIEEE754,
877      eFormatFloat,
878      {LLDB_INVALID_REGNUM, dwarf_d19, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM,
879       LLDB_INVALID_REGNUM},
880      nullptr,
881      nullptr,
882      nullptr,
883      0},
884     {"d20",
885      nullptr,
886      8,
887      0,
888      eEncodingIEEE754,
889      eFormatFloat,
890      {LLDB_INVALID_REGNUM, dwarf_d20, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM,
891       LLDB_INVALID_REGNUM},
892      nullptr,
893      nullptr,
894      nullptr,
895      0},
896     {"d21",
897      nullptr,
898      8,
899      0,
900      eEncodingIEEE754,
901      eFormatFloat,
902      {LLDB_INVALID_REGNUM, dwarf_d21, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM,
903       LLDB_INVALID_REGNUM},
904      nullptr,
905      nullptr,
906      nullptr,
907      0},
908     {"d22",
909      nullptr,
910      8,
911      0,
912      eEncodingIEEE754,
913      eFormatFloat,
914      {LLDB_INVALID_REGNUM, dwarf_d22, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM,
915       LLDB_INVALID_REGNUM},
916      nullptr,
917      nullptr,
918      nullptr,
919      0},
920     {"d23",
921      nullptr,
922      8,
923      0,
924      eEncodingIEEE754,
925      eFormatFloat,
926      {LLDB_INVALID_REGNUM, dwarf_d23, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM,
927       LLDB_INVALID_REGNUM},
928      nullptr,
929      nullptr,
930      nullptr,
931      0},
932     {"d24",
933      nullptr,
934      8,
935      0,
936      eEncodingIEEE754,
937      eFormatFloat,
938      {LLDB_INVALID_REGNUM, dwarf_d24, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM,
939       LLDB_INVALID_REGNUM},
940      nullptr,
941      nullptr,
942      nullptr,
943      0},
944     {"d25",
945      nullptr,
946      8,
947      0,
948      eEncodingIEEE754,
949      eFormatFloat,
950      {LLDB_INVALID_REGNUM, dwarf_d25, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM,
951       LLDB_INVALID_REGNUM},
952      nullptr,
953      nullptr,
954      nullptr,
955      0},
956     {"d26",
957      nullptr,
958      8,
959      0,
960      eEncodingIEEE754,
961      eFormatFloat,
962      {LLDB_INVALID_REGNUM, dwarf_d26, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM,
963       LLDB_INVALID_REGNUM},
964      nullptr,
965      nullptr,
966      nullptr,
967      0},
968     {"d27",
969      nullptr,
970      8,
971      0,
972      eEncodingIEEE754,
973      eFormatFloat,
974      {LLDB_INVALID_REGNUM, dwarf_d27, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM,
975       LLDB_INVALID_REGNUM},
976      nullptr,
977      nullptr,
978      nullptr,
979      0},
980     {"d28",
981      nullptr,
982      8,
983      0,
984      eEncodingIEEE754,
985      eFormatFloat,
986      {LLDB_INVALID_REGNUM, dwarf_d28, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM,
987       LLDB_INVALID_REGNUM},
988      nullptr,
989      nullptr,
990      nullptr,
991      0},
992     {"d29",
993      nullptr,
994      8,
995      0,
996      eEncodingIEEE754,
997      eFormatFloat,
998      {LLDB_INVALID_REGNUM, dwarf_d29, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM,
999       LLDB_INVALID_REGNUM},
1000      nullptr,
1001      nullptr,
1002      nullptr,
1003      0},
1004     {"d30",
1005      nullptr,
1006      8,
1007      0,
1008      eEncodingIEEE754,
1009      eFormatFloat,
1010      {LLDB_INVALID_REGNUM, dwarf_d30, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM,
1011       LLDB_INVALID_REGNUM},
1012      nullptr,
1013      nullptr,
1014      nullptr,
1015      0},
1016     {"d31",
1017      nullptr,
1018      8,
1019      0,
1020      eEncodingIEEE754,
1021      eFormatFloat,
1022      {LLDB_INVALID_REGNUM, dwarf_d31, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM,
1023       LLDB_INVALID_REGNUM},
1024      nullptr,
1025      nullptr,
1026      nullptr,
1027      0},
1028     {"r8_usr",
1029      nullptr,
1030      4,
1031      0,
1032      eEncodingUint,
1033      eFormatHex,
1034      {LLDB_INVALID_REGNUM, dwarf_r8_usr, LLDB_INVALID_REGNUM,
1035       LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM},
1036      nullptr,
1037      nullptr,
1038      nullptr,
1039      0},
1040     {"r9_usr",
1041      nullptr,
1042      4,
1043      0,
1044      eEncodingUint,
1045      eFormatHex,
1046      {LLDB_INVALID_REGNUM, dwarf_r9_usr, LLDB_INVALID_REGNUM,
1047       LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM},
1048      nullptr,
1049      nullptr,
1050      nullptr,
1051      0},
1052     {"r10_usr",
1053      nullptr,
1054      4,
1055      0,
1056      eEncodingUint,
1057      eFormatHex,
1058      {LLDB_INVALID_REGNUM, dwarf_r10_usr, LLDB_INVALID_REGNUM,
1059       LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM},
1060      nullptr,
1061      nullptr,
1062      nullptr,
1063      0},
1064     {"r11_usr",
1065      nullptr,
1066      4,
1067      0,
1068      eEncodingUint,
1069      eFormatHex,
1070      {LLDB_INVALID_REGNUM, dwarf_r11_usr, LLDB_INVALID_REGNUM,
1071       LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM},
1072      nullptr,
1073      nullptr,
1074      nullptr,
1075      0},
1076     {"r12_usr",
1077      nullptr,
1078      4,
1079      0,
1080      eEncodingUint,
1081      eFormatHex,
1082      {LLDB_INVALID_REGNUM, dwarf_r12_usr, LLDB_INVALID_REGNUM,
1083       LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM},
1084      nullptr,
1085      nullptr,
1086      nullptr,
1087      0},
1088     {"r13_usr",
1089      "sp_usr",
1090      4,
1091      0,
1092      eEncodingUint,
1093      eFormatHex,
1094      {LLDB_INVALID_REGNUM, dwarf_r13_usr, LLDB_INVALID_REGNUM,
1095       LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM},
1096      nullptr,
1097      nullptr,
1098      nullptr,
1099      0},
1100     {"r14_usr",
1101      "lr_usr",
1102      4,
1103      0,
1104      eEncodingUint,
1105      eFormatHex,
1106      {LLDB_INVALID_REGNUM, dwarf_r14_usr, LLDB_INVALID_REGNUM,
1107       LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM},
1108      nullptr,
1109      nullptr,
1110      nullptr,
1111      0},
1112     {"r8_fiq",
1113      nullptr,
1114      4,
1115      0,
1116      eEncodingUint,
1117      eFormatHex,
1118      {LLDB_INVALID_REGNUM, dwarf_r8_fiq, LLDB_INVALID_REGNUM,
1119       LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM},
1120      nullptr,
1121      nullptr,
1122      nullptr,
1123      0},
1124     {"r9_fiq",
1125      nullptr,
1126      4,
1127      0,
1128      eEncodingUint,
1129      eFormatHex,
1130      {LLDB_INVALID_REGNUM, dwarf_r9_fiq, LLDB_INVALID_REGNUM,
1131       LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM},
1132      nullptr,
1133      nullptr,
1134      nullptr,
1135      0},
1136     {"r10_fiq",
1137      nullptr,
1138      4,
1139      0,
1140      eEncodingUint,
1141      eFormatHex,
1142      {LLDB_INVALID_REGNUM, dwarf_r10_fiq, LLDB_INVALID_REGNUM,
1143       LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM},
1144      nullptr,
1145      nullptr,
1146      nullptr,
1147      0},
1148     {"r11_fiq",
1149      nullptr,
1150      4,
1151      0,
1152      eEncodingUint,
1153      eFormatHex,
1154      {LLDB_INVALID_REGNUM, dwarf_r11_fiq, LLDB_INVALID_REGNUM,
1155       LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM},
1156      nullptr,
1157      nullptr,
1158      nullptr,
1159      0},
1160     {"r12_fiq",
1161      nullptr,
1162      4,
1163      0,
1164      eEncodingUint,
1165      eFormatHex,
1166      {LLDB_INVALID_REGNUM, dwarf_r12_fiq, LLDB_INVALID_REGNUM,
1167       LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM},
1168      nullptr,
1169      nullptr,
1170      nullptr,
1171      0},
1172     {"r13_fiq",
1173      "sp_fiq",
1174      4,
1175      0,
1176      eEncodingUint,
1177      eFormatHex,
1178      {LLDB_INVALID_REGNUM, dwarf_r13_fiq, LLDB_INVALID_REGNUM,
1179       LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM},
1180      nullptr,
1181      nullptr,
1182      nullptr,
1183      0},
1184     {"r14_fiq",
1185      "lr_fiq",
1186      4,
1187      0,
1188      eEncodingUint,
1189      eFormatHex,
1190      {LLDB_INVALID_REGNUM, dwarf_r14_fiq, LLDB_INVALID_REGNUM,
1191       LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM},
1192      nullptr,
1193      nullptr,
1194      nullptr,
1195      0},
1196     {"r13_irq",
1197      "sp_irq",
1198      4,
1199      0,
1200      eEncodingUint,
1201      eFormatHex,
1202      {LLDB_INVALID_REGNUM, dwarf_r13_irq, LLDB_INVALID_REGNUM,
1203       LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM},
1204      nullptr,
1205      nullptr,
1206      nullptr,
1207      0},
1208     {"r14_irq",
1209      "lr_irq",
1210      4,
1211      0,
1212      eEncodingUint,
1213      eFormatHex,
1214      {LLDB_INVALID_REGNUM, dwarf_r14_irq, LLDB_INVALID_REGNUM,
1215       LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM},
1216      nullptr,
1217      nullptr,
1218      nullptr,
1219      0},
1220     {"r13_abt",
1221      "sp_abt",
1222      4,
1223      0,
1224      eEncodingUint,
1225      eFormatHex,
1226      {LLDB_INVALID_REGNUM, dwarf_r13_abt, LLDB_INVALID_REGNUM,
1227       LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM},
1228      nullptr,
1229      nullptr,
1230      nullptr,
1231      0},
1232     {"r14_abt",
1233      "lr_abt",
1234      4,
1235      0,
1236      eEncodingUint,
1237      eFormatHex,
1238      {LLDB_INVALID_REGNUM, dwarf_r14_abt, LLDB_INVALID_REGNUM,
1239       LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM},
1240      nullptr,
1241      nullptr,
1242      nullptr,
1243      0},
1244     {"r13_und",
1245      "sp_und",
1246      4,
1247      0,
1248      eEncodingUint,
1249      eFormatHex,
1250      {LLDB_INVALID_REGNUM, dwarf_r13_und, LLDB_INVALID_REGNUM,
1251       LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM},
1252      nullptr,
1253      nullptr,
1254      nullptr,
1255      0},
1256     {"r14_und",
1257      "lr_und",
1258      4,
1259      0,
1260      eEncodingUint,
1261      eFormatHex,
1262      {LLDB_INVALID_REGNUM, dwarf_r14_und, LLDB_INVALID_REGNUM,
1263       LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM},
1264      nullptr,
1265      nullptr,
1266      nullptr,
1267      0},
1268     {"r13_svc",
1269      "sp_svc",
1270      4,
1271      0,
1272      eEncodingUint,
1273      eFormatHex,
1274      {LLDB_INVALID_REGNUM, dwarf_r13_svc, LLDB_INVALID_REGNUM,
1275       LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM},
1276      nullptr,
1277      nullptr,
1278      nullptr,
1279      0},
1280     {"r14_svc",
1281      "lr_svc",
1282      4,
1283      0,
1284      eEncodingUint,
1285      eFormatHex,
1286      {LLDB_INVALID_REGNUM, dwarf_r14_svc, LLDB_INVALID_REGNUM,
1287       LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM},
1288      nullptr,
1289      nullptr,
1290      nullptr,
1291      0}};
1292 
1293 static const uint32_t k_num_register_infos =
1294     llvm::array_lengthof(g_register_infos);
1295 static bool g_register_info_names_constified = false;
1296 
1297 const lldb_private::RegisterInfo *
1298 ABIMacOSX_arm::GetRegisterInfoArray(uint32_t &count) {
1299   // Make the C-string names and alt_names for the register infos into const
1300   // C-string values by having the ConstString unique the names in the global
1301   // constant C-string pool.
1302   if (!g_register_info_names_constified) {
1303     g_register_info_names_constified = true;
1304     for (uint32_t i = 0; i < k_num_register_infos; ++i) {
1305       if (g_register_infos[i].name)
1306         g_register_infos[i].name =
1307             ConstString(g_register_infos[i].name).GetCString();
1308       if (g_register_infos[i].alt_name)
1309         g_register_infos[i].alt_name =
1310             ConstString(g_register_infos[i].alt_name).GetCString();
1311     }
1312   }
1313   count = k_num_register_infos;
1314   return g_register_infos;
1315 }
1316 
1317 size_t ABIMacOSX_arm::GetRedZoneSize() const { return 0; }
1318 
1319 // Static Functions
1320 
1321 ABISP
1322 ABIMacOSX_arm::CreateInstance(ProcessSP process_sp, const ArchSpec &arch) {
1323   const llvm::Triple::ArchType arch_type = arch.GetTriple().getArch();
1324   const llvm::Triple::VendorType vendor_type = arch.GetTriple().getVendor();
1325 
1326   if (vendor_type == llvm::Triple::Apple) {
1327     if ((arch_type == llvm::Triple::arm) ||
1328         (arch_type == llvm::Triple::thumb)) {
1329       return ABISP(
1330           new ABIMacOSX_arm(std::move(process_sp), MakeMCRegisterInfo(arch)));
1331     }
1332   }
1333 
1334   return ABISP();
1335 }
1336 
1337 bool ABIMacOSX_arm::PrepareTrivialCall(Thread &thread, addr_t sp,
1338                                        addr_t function_addr, addr_t return_addr,
1339                                        llvm::ArrayRef<addr_t> args) const {
1340   RegisterContext *reg_ctx = thread.GetRegisterContext().get();
1341   if (!reg_ctx)
1342     return false;
1343 
1344   const uint32_t pc_reg_num = reg_ctx->ConvertRegisterKindToRegisterNumber(
1345       eRegisterKindGeneric, LLDB_REGNUM_GENERIC_PC);
1346   const uint32_t sp_reg_num = reg_ctx->ConvertRegisterKindToRegisterNumber(
1347       eRegisterKindGeneric, LLDB_REGNUM_GENERIC_SP);
1348   const uint32_t ra_reg_num = reg_ctx->ConvertRegisterKindToRegisterNumber(
1349       eRegisterKindGeneric, LLDB_REGNUM_GENERIC_RA);
1350 
1351   RegisterValue reg_value;
1352 
1353   const char *reg_names[] = {"r0", "r1", "r2", "r3"};
1354 
1355   llvm::ArrayRef<addr_t>::iterator ai = args.begin(), ae = args.end();
1356 
1357   for (size_t i = 0; i < llvm::array_lengthof(reg_names); ++i) {
1358     if (ai == ae)
1359       break;
1360 
1361     reg_value.SetUInt32(*ai);
1362     if (!reg_ctx->WriteRegister(reg_ctx->GetRegisterInfoByName(reg_names[i]),
1363                                 reg_value))
1364       return false;
1365 
1366     ++ai;
1367   }
1368 
1369   if (ai != ae) {
1370     // Spill onto the stack
1371     size_t num_stack_regs = ae - ai;
1372 
1373     sp -= (num_stack_regs * 4);
1374     // Keep the stack 16 byte aligned
1375     sp &= ~(16ull - 1ull);
1376 
1377     // just using arg1 to get the right size
1378     const RegisterInfo *reg_info = reg_ctx->GetRegisterInfo(
1379         eRegisterKindGeneric, LLDB_REGNUM_GENERIC_ARG1);
1380 
1381     addr_t arg_pos = sp;
1382 
1383     for (; ai != ae; ++ai) {
1384       reg_value.SetUInt32(*ai);
1385       if (reg_ctx
1386               ->WriteRegisterValueToMemory(reg_info, arg_pos,
1387                                            reg_info->byte_size, reg_value)
1388               .Fail())
1389         return false;
1390       arg_pos += reg_info->byte_size;
1391     }
1392   }
1393 
1394   TargetSP target_sp(thread.CalculateTarget());
1395   Address so_addr;
1396 
1397   // Figure out if our return address is ARM or Thumb by using the
1398   // Address::GetCallableLoadAddress(Target*) which will figure out the ARM
1399   // thumb-ness and set the correct address bits for us.
1400   so_addr.SetLoadAddress(return_addr, target_sp.get());
1401   return_addr = so_addr.GetCallableLoadAddress(target_sp.get());
1402 
1403   // Set "lr" to the return address
1404   if (!reg_ctx->WriteRegisterFromUnsigned(ra_reg_num, return_addr))
1405     return false;
1406 
1407   // If bit zero or 1 is set, this must be a thumb function, no need to figure
1408   // this out from the symbols.
1409   so_addr.SetLoadAddress(function_addr, target_sp.get());
1410   function_addr = so_addr.GetCallableLoadAddress(target_sp.get());
1411 
1412   const RegisterInfo *cpsr_reg_info = reg_ctx->GetRegisterInfoByName("cpsr");
1413   const uint32_t curr_cpsr = reg_ctx->ReadRegisterAsUnsigned(cpsr_reg_info, 0);
1414 
1415   // Make a new CPSR and mask out any Thumb IT (if/then) bits
1416   uint32_t new_cpsr = curr_cpsr & ~MASK_CPSR_IT_MASK;
1417   // If bit zero or 1 is set, this must be thumb...
1418   if (function_addr & 1ull)
1419     new_cpsr |= MASK_CPSR_T; // Set T bit in CPSR
1420   else
1421     new_cpsr &= ~MASK_CPSR_T; // Clear T bit in CPSR
1422 
1423   if (new_cpsr != curr_cpsr) {
1424     if (!reg_ctx->WriteRegisterFromUnsigned(cpsr_reg_info, new_cpsr))
1425       return false;
1426   }
1427 
1428   function_addr &=
1429       ~1ull; // clear bit zero since the CPSR will take care of the mode for us
1430 
1431   // Update the sp - stack pointer - to be aligned to 16-bytes
1432   sp &= ~(0xfull);
1433   if (!reg_ctx->WriteRegisterFromUnsigned(sp_reg_num, sp))
1434     return false;
1435 
1436   // Set "pc" to the address requested
1437   if (!reg_ctx->WriteRegisterFromUnsigned(pc_reg_num, function_addr))
1438     return false;
1439 
1440   return true;
1441 }
1442 
1443 bool ABIMacOSX_arm::GetArgumentValues(Thread &thread, ValueList &values) const {
1444   uint32_t num_values = values.GetSize();
1445 
1446   ExecutionContext exe_ctx(thread.shared_from_this());
1447   // For now, assume that the types in the AST values come from the Target's
1448   // scratch AST.
1449 
1450   // Extract the register context so we can read arguments from registers
1451 
1452   RegisterContext *reg_ctx = thread.GetRegisterContext().get();
1453 
1454   if (!reg_ctx)
1455     return false;
1456 
1457   addr_t sp = 0;
1458 
1459   for (uint32_t value_idx = 0; value_idx < num_values; ++value_idx) {
1460     // We currently only support extracting values with Clang QualTypes. Do we
1461     // care about others?
1462     Value *value = values.GetValueAtIndex(value_idx);
1463 
1464     if (!value)
1465       return false;
1466 
1467     CompilerType compiler_type = value->GetCompilerType();
1468     if (compiler_type) {
1469       bool is_signed = false;
1470       size_t bit_width = 0;
1471       llvm::Optional<uint64_t> bit_size = compiler_type.GetBitSize(&thread);
1472       if (!bit_size)
1473         return false;
1474       if (compiler_type.IsIntegerOrEnumerationType(is_signed))
1475         bit_width = *bit_size;
1476       else if (compiler_type.IsPointerOrReferenceType())
1477         bit_width = *bit_size;
1478       else
1479         // We only handle integer, pointer and reference types currently...
1480         return false;
1481 
1482       if (bit_width <= (exe_ctx.GetProcessRef().GetAddressByteSize() * 8)) {
1483         if (value_idx < 4) {
1484           // Arguments 1-4 are in r0-r3...
1485           const RegisterInfo *arg_reg_info = nullptr;
1486           // Search by generic ID first, then fall back to by name
1487           uint32_t arg_reg_num = reg_ctx->ConvertRegisterKindToRegisterNumber(
1488               eRegisterKindGeneric, LLDB_REGNUM_GENERIC_ARG1 + value_idx);
1489           if (arg_reg_num != LLDB_INVALID_REGNUM) {
1490             arg_reg_info = reg_ctx->GetRegisterInfoAtIndex(arg_reg_num);
1491           } else {
1492             switch (value_idx) {
1493             case 0:
1494               arg_reg_info = reg_ctx->GetRegisterInfoByName("r0");
1495               break;
1496             case 1:
1497               arg_reg_info = reg_ctx->GetRegisterInfoByName("r1");
1498               break;
1499             case 2:
1500               arg_reg_info = reg_ctx->GetRegisterInfoByName("r2");
1501               break;
1502             case 3:
1503               arg_reg_info = reg_ctx->GetRegisterInfoByName("r3");
1504               break;
1505             }
1506           }
1507 
1508           if (arg_reg_info) {
1509             RegisterValue reg_value;
1510 
1511             if (reg_ctx->ReadRegister(arg_reg_info, reg_value)) {
1512               if (is_signed)
1513                 reg_value.SignExtend(bit_width);
1514               if (!reg_value.GetScalarValue(value->GetScalar()))
1515                 return false;
1516               continue;
1517             }
1518           }
1519           return false;
1520         } else {
1521           if (sp == 0) {
1522             // Read the stack pointer if it already hasn't been read
1523             sp = reg_ctx->GetSP(0);
1524             if (sp == 0)
1525               return false;
1526           }
1527 
1528           // Arguments 5 on up are on the stack
1529           const uint32_t arg_byte_size = (bit_width + (8 - 1)) / 8;
1530           Status error;
1531           if (!exe_ctx.GetProcessRef().ReadScalarIntegerFromMemory(
1532                   sp, arg_byte_size, is_signed, value->GetScalar(), error))
1533             return false;
1534 
1535           sp += arg_byte_size;
1536         }
1537       }
1538     }
1539   }
1540   return true;
1541 }
1542 
1543 bool ABIMacOSX_arm::IsArmv7kProcess() const {
1544   bool is_armv7k = false;
1545   ProcessSP process_sp(GetProcessSP());
1546   if (process_sp) {
1547     const ArchSpec &arch(process_sp->GetTarget().GetArchitecture());
1548     const ArchSpec::Core system_core = arch.GetCore();
1549     if (system_core == ArchSpec::eCore_arm_armv7k) {
1550       is_armv7k = true;
1551     }
1552   }
1553   return is_armv7k;
1554 }
1555 
1556 ValueObjectSP ABIMacOSX_arm::GetReturnValueObjectImpl(
1557     Thread &thread, lldb_private::CompilerType &compiler_type) const {
1558   Value value;
1559   ValueObjectSP return_valobj_sp;
1560 
1561   if (!compiler_type)
1562     return return_valobj_sp;
1563 
1564   value.SetCompilerType(compiler_type);
1565 
1566   RegisterContext *reg_ctx = thread.GetRegisterContext().get();
1567   if (!reg_ctx)
1568     return return_valobj_sp;
1569 
1570   bool is_signed;
1571 
1572   // Get the pointer to the first stack argument so we have a place to start
1573   // when reading data
1574 
1575   const RegisterInfo *r0_reg_info = reg_ctx->GetRegisterInfoByName("r0", 0);
1576   if (compiler_type.IsIntegerOrEnumerationType(is_signed)) {
1577     llvm::Optional<uint64_t> bit_width = compiler_type.GetBitSize(&thread);
1578     if (!bit_width)
1579       return return_valobj_sp;
1580 
1581     switch (*bit_width) {
1582     default:
1583       return return_valobj_sp;
1584     case 128:
1585       if (IsArmv7kProcess()) {
1586         // "A composite type not larger than 16 bytes is returned in r0-r3. The
1587         // format is as if the result had been stored in memory at a word-
1588         // aligned address and then loaded into r0-r3 with an ldm instruction"
1589         {
1590           const RegisterInfo *r1_reg_info =
1591               reg_ctx->GetRegisterInfoByName("r1", 0);
1592           const RegisterInfo *r2_reg_info =
1593               reg_ctx->GetRegisterInfoByName("r2", 0);
1594           const RegisterInfo *r3_reg_info =
1595               reg_ctx->GetRegisterInfoByName("r3", 0);
1596           if (r1_reg_info && r2_reg_info && r3_reg_info) {
1597             llvm::Optional<uint64_t> byte_size =
1598                 compiler_type.GetByteSize(&thread);
1599             if (!byte_size)
1600               return return_valobj_sp;
1601             ProcessSP process_sp(thread.GetProcess());
1602             if (*byte_size <= r0_reg_info->byte_size + r1_reg_info->byte_size +
1603                                   r2_reg_info->byte_size +
1604                                   r3_reg_info->byte_size &&
1605                 process_sp) {
1606               std::unique_ptr<DataBufferHeap> heap_data_up(
1607                   new DataBufferHeap(*byte_size, 0));
1608               const ByteOrder byte_order = process_sp->GetByteOrder();
1609               RegisterValue r0_reg_value;
1610               RegisterValue r1_reg_value;
1611               RegisterValue r2_reg_value;
1612               RegisterValue r3_reg_value;
1613               if (reg_ctx->ReadRegister(r0_reg_info, r0_reg_value) &&
1614                   reg_ctx->ReadRegister(r1_reg_info, r1_reg_value) &&
1615                   reg_ctx->ReadRegister(r2_reg_info, r2_reg_value) &&
1616                   reg_ctx->ReadRegister(r3_reg_info, r3_reg_value)) {
1617                 Status error;
1618                 if (r0_reg_value.GetAsMemoryData(r0_reg_info,
1619                                                  heap_data_up->GetBytes() + 0,
1620                                                  4, byte_order, error) &&
1621                     r1_reg_value.GetAsMemoryData(r1_reg_info,
1622                                                  heap_data_up->GetBytes() + 4,
1623                                                  4, byte_order, error) &&
1624                     r2_reg_value.GetAsMemoryData(r2_reg_info,
1625                                                  heap_data_up->GetBytes() + 8,
1626                                                  4, byte_order, error) &&
1627                     r3_reg_value.GetAsMemoryData(r3_reg_info,
1628                                                  heap_data_up->GetBytes() + 12,
1629                                                  4, byte_order, error)) {
1630                   DataExtractor data(DataBufferSP(heap_data_up.release()),
1631                                      byte_order,
1632                                      process_sp->GetAddressByteSize());
1633 
1634                   return_valobj_sp = ValueObjectConstResult::Create(
1635                       &thread, compiler_type, ConstString(""), data);
1636                   return return_valobj_sp;
1637                 }
1638               }
1639             }
1640           }
1641         }
1642       } else {
1643         return return_valobj_sp;
1644       }
1645       break;
1646     case 64: {
1647       const RegisterInfo *r1_reg_info = reg_ctx->GetRegisterInfoByName("r1", 0);
1648       uint64_t raw_value;
1649       raw_value = reg_ctx->ReadRegisterAsUnsigned(r0_reg_info, 0) & UINT32_MAX;
1650       raw_value |= ((uint64_t)(reg_ctx->ReadRegisterAsUnsigned(r1_reg_info, 0) &
1651                                UINT32_MAX))
1652                    << 32;
1653       if (is_signed)
1654         value.GetScalar() = (int64_t)raw_value;
1655       else
1656         value.GetScalar() = (uint64_t)raw_value;
1657     } break;
1658     case 32:
1659       if (is_signed)
1660         value.GetScalar() = (int32_t)(
1661             reg_ctx->ReadRegisterAsUnsigned(r0_reg_info, 0) & UINT32_MAX);
1662       else
1663         value.GetScalar() = (uint32_t)(
1664             reg_ctx->ReadRegisterAsUnsigned(r0_reg_info, 0) & UINT32_MAX);
1665       break;
1666     case 16:
1667       if (is_signed)
1668         value.GetScalar() = (int16_t)(
1669             reg_ctx->ReadRegisterAsUnsigned(r0_reg_info, 0) & UINT16_MAX);
1670       else
1671         value.GetScalar() = (uint16_t)(
1672             reg_ctx->ReadRegisterAsUnsigned(r0_reg_info, 0) & UINT16_MAX);
1673       break;
1674     case 8:
1675       if (is_signed)
1676         value.GetScalar() = (int8_t)(
1677             reg_ctx->ReadRegisterAsUnsigned(r0_reg_info, 0) & UINT8_MAX);
1678       else
1679         value.GetScalar() = (uint8_t)(
1680             reg_ctx->ReadRegisterAsUnsigned(r0_reg_info, 0) & UINT8_MAX);
1681       break;
1682     }
1683   } else if (compiler_type.IsPointerType()) {
1684     uint32_t ptr =
1685         thread.GetRegisterContext()->ReadRegisterAsUnsigned(r0_reg_info, 0) &
1686         UINT32_MAX;
1687     value.GetScalar() = ptr;
1688   } else {
1689     // not handled yet
1690     return return_valobj_sp;
1691   }
1692 
1693   // If we get here, we have a valid Value, so make our ValueObject out of it:
1694 
1695   return_valobj_sp = ValueObjectConstResult::Create(
1696       thread.GetStackFrameAtIndex(0).get(), value, ConstString(""));
1697   return return_valobj_sp;
1698 }
1699 
1700 Status ABIMacOSX_arm::SetReturnValueObject(lldb::StackFrameSP &frame_sp,
1701                                            lldb::ValueObjectSP &new_value_sp) {
1702   Status error;
1703   if (!new_value_sp) {
1704     error.SetErrorString("Empty value object for return value.");
1705     return error;
1706   }
1707 
1708   CompilerType compiler_type = new_value_sp->GetCompilerType();
1709   if (!compiler_type) {
1710     error.SetErrorString("Null clang type for return value.");
1711     return error;
1712   }
1713 
1714   Thread *thread = frame_sp->GetThread().get();
1715 
1716   bool is_signed;
1717   uint32_t count;
1718   bool is_complex;
1719 
1720   RegisterContext *reg_ctx = thread->GetRegisterContext().get();
1721 
1722   bool set_it_simple = false;
1723   if (compiler_type.IsIntegerOrEnumerationType(is_signed) ||
1724       compiler_type.IsPointerType()) {
1725     DataExtractor data;
1726     Status data_error;
1727     size_t num_bytes = new_value_sp->GetData(data, data_error);
1728     if (data_error.Fail()) {
1729       error.SetErrorStringWithFormat(
1730           "Couldn't convert return value to raw data: %s",
1731           data_error.AsCString());
1732       return error;
1733     }
1734     lldb::offset_t offset = 0;
1735     if (num_bytes <= 8) {
1736       const RegisterInfo *r0_info = reg_ctx->GetRegisterInfoByName("r0", 0);
1737       if (num_bytes <= 4) {
1738         uint32_t raw_value = data.GetMaxU32(&offset, num_bytes);
1739 
1740         if (reg_ctx->WriteRegisterFromUnsigned(r0_info, raw_value))
1741           set_it_simple = true;
1742       } else {
1743         uint32_t raw_value = data.GetMaxU32(&offset, 4);
1744 
1745         if (reg_ctx->WriteRegisterFromUnsigned(r0_info, raw_value)) {
1746           const RegisterInfo *r1_info = reg_ctx->GetRegisterInfoByName("r1", 0);
1747           uint32_t raw_value = data.GetMaxU32(&offset, num_bytes - offset);
1748 
1749           if (reg_ctx->WriteRegisterFromUnsigned(r1_info, raw_value))
1750             set_it_simple = true;
1751         }
1752       }
1753     } else if (num_bytes <= 16 && IsArmv7kProcess()) {
1754       // "A composite type not larger than 16 bytes is returned in r0-r3. The
1755       // format is as if the result had been stored in memory at a word-aligned
1756       // address and then loaded into r0-r3 with an ldm instruction"
1757 
1758       const RegisterInfo *r0_info = reg_ctx->GetRegisterInfoByName("r0", 0);
1759       const RegisterInfo *r1_info = reg_ctx->GetRegisterInfoByName("r1", 0);
1760       const RegisterInfo *r2_info = reg_ctx->GetRegisterInfoByName("r2", 0);
1761       const RegisterInfo *r3_info = reg_ctx->GetRegisterInfoByName("r3", 0);
1762       lldb::offset_t offset = 0;
1763       uint32_t bytes_written = 4;
1764       uint32_t raw_value = data.GetMaxU64(&offset, 4);
1765       if (reg_ctx->WriteRegisterFromUnsigned(r0_info, raw_value) &&
1766           bytes_written <= num_bytes) {
1767         bytes_written += 4;
1768         raw_value = data.GetMaxU64(&offset, 4);
1769         if (bytes_written <= num_bytes &&
1770             reg_ctx->WriteRegisterFromUnsigned(r1_info, raw_value)) {
1771           bytes_written += 4;
1772           raw_value = data.GetMaxU64(&offset, 4);
1773           if (bytes_written <= num_bytes &&
1774               reg_ctx->WriteRegisterFromUnsigned(r2_info, raw_value)) {
1775             bytes_written += 4;
1776             raw_value = data.GetMaxU64(&offset, 4);
1777             if (bytes_written <= num_bytes &&
1778                 reg_ctx->WriteRegisterFromUnsigned(r3_info, raw_value)) {
1779               set_it_simple = true;
1780             }
1781           }
1782         }
1783       }
1784     } else {
1785       error.SetErrorString("We don't support returning longer than 64 bit "
1786                            "integer values at present.");
1787     }
1788   } else if (compiler_type.IsFloatingPointType(count, is_complex)) {
1789     if (is_complex)
1790       error.SetErrorString(
1791           "We don't support returning complex values at present");
1792     else
1793       error.SetErrorString(
1794           "We don't support returning float values at present");
1795   }
1796 
1797   if (!set_it_simple)
1798     error.SetErrorString(
1799         "We only support setting simple integer return types at present.");
1800 
1801   return error;
1802 }
1803 
1804 bool ABIMacOSX_arm::CreateFunctionEntryUnwindPlan(UnwindPlan &unwind_plan) {
1805   unwind_plan.Clear();
1806   unwind_plan.SetRegisterKind(eRegisterKindDWARF);
1807 
1808   uint32_t lr_reg_num = dwarf_lr;
1809   uint32_t sp_reg_num = dwarf_sp;
1810   uint32_t pc_reg_num = dwarf_pc;
1811 
1812   UnwindPlan::RowSP row(new UnwindPlan::Row);
1813 
1814   // Our Call Frame Address is the stack pointer value
1815   row->GetCFAValue().SetIsRegisterPlusOffset(sp_reg_num, 0);
1816 
1817   // The previous PC is in the LR
1818   row->SetRegisterLocationToRegister(pc_reg_num, lr_reg_num, true);
1819   unwind_plan.AppendRow(row);
1820 
1821   // All other registers are the same.
1822 
1823   unwind_plan.SetSourceName("arm at-func-entry default");
1824   unwind_plan.SetSourcedFromCompiler(eLazyBoolNo);
1825 
1826   return true;
1827 }
1828 
1829 bool ABIMacOSX_arm::CreateDefaultUnwindPlan(UnwindPlan &unwind_plan) {
1830   unwind_plan.Clear();
1831   unwind_plan.SetRegisterKind(eRegisterKindDWARF);
1832 
1833   uint32_t fp_reg_num =
1834       dwarf_r7; // apple uses r7 for all frames. Normal arm uses r11
1835   uint32_t pc_reg_num = dwarf_pc;
1836 
1837   UnwindPlan::RowSP row(new UnwindPlan::Row);
1838   const int32_t ptr_size = 4;
1839 
1840   row->GetCFAValue().SetIsRegisterPlusOffset(fp_reg_num, 2 * ptr_size);
1841   row->SetOffset(0);
1842 
1843   row->SetRegisterLocationToAtCFAPlusOffset(fp_reg_num, ptr_size * -2, true);
1844   row->SetRegisterLocationToAtCFAPlusOffset(pc_reg_num, ptr_size * -1, true);
1845 
1846   unwind_plan.AppendRow(row);
1847   unwind_plan.SetSourceName("arm-apple-ios default unwind plan");
1848   unwind_plan.SetSourcedFromCompiler(eLazyBoolNo);
1849   unwind_plan.SetUnwindPlanValidAtAllInstructions(eLazyBoolNo);
1850   unwind_plan.SetUnwindPlanForSignalTrap(eLazyBoolNo);
1851 
1852   return true;
1853 }
1854 
1855 // cf. "ARMv6 Function Calling Conventions"
1856 // https://developer.apple.com/library/ios/documentation/Xcode/Conceptual/iPhoneOSABIReference/Articles/ARMv6FunctionCallingConventions.html
1857 // and "ARMv7 Function Calling Conventions"
1858 // https://developer.apple.com/library/ios/documentation/Xcode/Conceptual/iPhoneOSABIReference/Articles/ARMv7FunctionCallingConventions.html
1859 
1860 // ARMv7 on iOS general purpose reg rules:
1861 //    r0-r3 not preserved  (used for argument passing)
1862 //    r4-r6 preserved
1863 //    r7    preserved (frame pointer)
1864 //    r8    preserved
1865 //    r9    not preserved (usable as volatile scratch register with iOS 3.x and
1866 //    later)
1867 //    r10-r11 preserved
1868 //    r12   not presrved
1869 //    r13   preserved (stack pointer)
1870 //    r14   not preserved (link register)
1871 //    r15   preserved (pc)
1872 //    cpsr  not preserved (different rules for different bits)
1873 
1874 // ARMv7 on iOS floating point rules:
1875 //    d0-d7   not preserved   (aka s0-s15, q0-q3)
1876 //    d8-d15  preserved       (aka s16-s31, q4-q7)
1877 //    d16-d31 not preserved   (aka q8-q15)
1878 
1879 bool ABIMacOSX_arm::RegisterIsVolatile(const RegisterInfo *reg_info) {
1880   if (reg_info) {
1881     // Volatile registers are: r0, r1, r2, r3, r9, r12, r13 (aka sp)
1882     const char *name = reg_info->name;
1883     if (name[0] == 'r') {
1884       switch (name[1]) {
1885       case '0':
1886         return name[2] == '\0'; // r0
1887       case '1':
1888         switch (name[2]) {
1889         case '\0':
1890           return true; // r1
1891         case '2':
1892         case '3':
1893           return name[3] == '\0'; // r12, r13 (sp)
1894         default:
1895           break;
1896         }
1897         break;
1898 
1899       case '2':
1900         return name[2] == '\0'; // r2
1901       case '3':
1902         return name[2] == '\0'; // r3
1903       case '9':
1904         return name[2] == '\0'; // r9 (apple-ios only...)
1905 
1906         break;
1907       }
1908     } else if (name[0] == 'd') {
1909       switch (name[1]) {
1910       case '0':
1911         return name[2] == '\0'; // d0 is volatile
1912 
1913       case '1':
1914         switch (name[2]) {
1915         case '\0':
1916           return true; // d1 is volatile
1917         case '6':
1918         case '7':
1919         case '8':
1920         case '9':
1921           return name[3] == '\0'; // d16 - d19 are volatile
1922         default:
1923           break;
1924         }
1925         break;
1926 
1927       case '2':
1928         switch (name[2]) {
1929         case '\0':
1930           return true; // d2 is volatile
1931         case '0':
1932         case '1':
1933         case '2':
1934         case '3':
1935         case '4':
1936         case '5':
1937         case '6':
1938         case '7':
1939         case '8':
1940         case '9':
1941           return name[3] == '\0'; // d20 - d29 are volatile
1942         default:
1943           break;
1944         }
1945         break;
1946 
1947       case '3':
1948         switch (name[2]) {
1949         case '\0':
1950           return true; // d3 is volatile
1951         case '0':
1952         case '1':
1953           return name[3] == '\0'; // d30 - d31 are volatile
1954         default:
1955           break;
1956         }
1957         break;
1958       case '4':
1959       case '5':
1960       case '6':
1961       case '7':
1962         return name[2] == '\0'; // d4 - d7 are volatile
1963 
1964       default:
1965         break;
1966       }
1967     } else if (name[0] == 's') {
1968       switch (name[1]) {
1969       case '0':
1970         return name[2] == '\0'; // s0 is volatile
1971 
1972       case '1':
1973         switch (name[2]) {
1974         case '\0':
1975           return true; // s1 is volatile
1976         case '0':
1977         case '1':
1978         case '2':
1979         case '3':
1980         case '4':
1981         case '5':
1982           return name[3] == '\0'; // s10 - s15 are volatile
1983         default:
1984           break;
1985         }
1986         break;
1987 
1988       case '2':
1989       case '3':
1990       case '4':
1991       case '5':
1992       case '6':
1993       case '7':
1994       case '8':
1995       case '9':
1996         return name[2] == '\0'; // s2 - s9 are volatile
1997 
1998       default:
1999         break;
2000       }
2001     } else if (name[0] == 'q') {
2002       switch (name[1]) {
2003       case '1':
2004         switch (name[2]) {
2005         case '\0':
2006           return true; // q1 is volatile
2007         case '0':
2008         case '1':
2009         case '2':
2010         case '3':
2011         case '4':
2012         case '5':
2013           return true; // q10-q15 are volatile
2014         default:
2015           break;
2016         };
2017         break;
2018       case '0':
2019       case '2':
2020       case '3':
2021         return name[2] == '\0'; // q0-q3 are volatile
2022       case '8':
2023       case '9':
2024         return name[2] == '\0'; // q8-q9 are volatile
2025       default:
2026         break;
2027       }
2028     } else if (name[0] == 's' && name[1] == 'p' && name[2] == '\0')
2029       return true;
2030   }
2031   return false;
2032 }
2033 
2034 void ABIMacOSX_arm::Initialize() {
2035   PluginManager::RegisterPlugin(GetPluginNameStatic(),
2036                                 "Mac OS X ABI for arm targets", CreateInstance);
2037 }
2038 
2039 void ABIMacOSX_arm::Terminate() {
2040   PluginManager::UnregisterPlugin(CreateInstance);
2041 }
2042 
2043 lldb_private::ConstString ABIMacOSX_arm::GetPluginNameStatic() {
2044   static ConstString g_name("macosx-arm");
2045   return g_name;
2046 }
2047 
2048 // PluginInterface protocol
2049 
2050 lldb_private::ConstString ABIMacOSX_arm::GetPluginName() {
2051   return GetPluginNameStatic();
2052 }
2053 
2054 uint32_t ABIMacOSX_arm::GetPluginVersion() { return 1; }
2055