LLDB  mainline
ABIMacOSX_arm64.cpp
Go to the documentation of this file.
1 //===-- ABIMacOSX_arm64.cpp -------------------------------------*- C++ -*-===//
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_arm64.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"
18 #include "lldb/Core/Value.h"
20 #include "lldb/Symbol/UnwindPlan.h"
21 #include "lldb/Target/Process.h"
23 #include "lldb/Target/Target.h"
24 #include "lldb/Target/Thread.h"
26 #include "lldb/Utility/Log.h"
28 #include "lldb/Utility/Scalar.h"
29 #include "lldb/Utility/Status.h"
30 
32 
33 using namespace lldb;
34 using namespace lldb_private;
35 
36 static const char *pluginDesc = "Mac OS X ABI for arm64 targets";
37 
38 static RegisterInfo g_register_infos[] = {
39  // NAME ALT SZ OFF ENCODING FORMAT
40  // EH_FRAME DWARF GENERIC
41  // PROCESS PLUGIN LLDB NATIVE
42  // ========== ======= == === ============= ===================
43  // =================== ====================== ===========================
44  // ======================= ======================
45  {"x0",
46  nullptr,
47  8,
48  0,
50  eFormatHex,
52  LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM},
53  nullptr,
54  nullptr,
55  nullptr,
56  0},
57  {"x1",
58  nullptr,
59  8,
60  0,
62  eFormatHex,
64  LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM},
65  nullptr,
66  nullptr,
67  nullptr,
68  0},
69  {"x2",
70  nullptr,
71  8,
72  0,
74  eFormatHex,
76  LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM},
77  nullptr,
78  nullptr,
79  nullptr,
80  0},
81  {"x3",
82  nullptr,
83  8,
84  0,
86  eFormatHex,
88  LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM},
89  nullptr,
90  nullptr,
91  nullptr,
92  0},
93  {"x4",
94  nullptr,
95  8,
96  0,
98  eFormatHex,
100  LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM},
101  nullptr,
102  nullptr,
103  nullptr,
104  0},
105  {"x5",
106  nullptr,
107  8,
108  0,
110  eFormatHex,
112  LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM},
113  nullptr,
114  nullptr,
115  nullptr,
116  0},
117  {"x6",
118  nullptr,
119  8,
120  0,
122  eFormatHex,
124  LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM},
125  nullptr,
126  nullptr,
127  nullptr,
128  0},
129  {"x7",
130  nullptr,
131  8,
132  0,
134  eFormatHex,
136  LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM},
137  nullptr,
138  nullptr,
139  nullptr,
140  0},
141  {"x8",
142  nullptr,
143  8,
144  0,
146  eFormatHex,
148  LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM},
149  nullptr,
150  nullptr,
151  nullptr,
152  0},
153  {"x9",
154  nullptr,
155  8,
156  0,
158  eFormatHex,
160  LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM},
161  nullptr,
162  nullptr,
163  nullptr,
164  0},
165  {"x10",
166  nullptr,
167  8,
168  0,
170  eFormatHex,
172  LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM},
173  nullptr,
174  nullptr,
175  nullptr,
176  0},
177  {"x11",
178  nullptr,
179  8,
180  0,
182  eFormatHex,
184  LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM},
185  nullptr,
186  nullptr,
187  nullptr,
188  0},
189  {"x12",
190  nullptr,
191  8,
192  0,
194  eFormatHex,
196  LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM},
197  nullptr,
198  nullptr,
199  nullptr,
200  0},
201  {"x13",
202  nullptr,
203  8,
204  0,
206  eFormatHex,
208  LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM},
209  nullptr,
210  nullptr,
211  nullptr,
212  0},
213  {"x14",
214  nullptr,
215  8,
216  0,
218  eFormatHex,
220  LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM},
221  nullptr,
222  nullptr,
223  nullptr,
224  0},
225  {"x15",
226  nullptr,
227  8,
228  0,
230  eFormatHex,
232  LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM},
233  nullptr,
234  nullptr,
235  nullptr,
236  0},
237  {"x16",
238  nullptr,
239  8,
240  0,
242  eFormatHex,
244  LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM},
245  nullptr,
246  nullptr,
247  nullptr,
248  0},
249  {"x17",
250  nullptr,
251  8,
252  0,
254  eFormatHex,
256  LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM},
257  nullptr,
258  nullptr,
259  nullptr,
260  0},
261  {"x18",
262  nullptr,
263  8,
264  0,
266  eFormatHex,
268  LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM},
269  nullptr,
270  nullptr,
271  nullptr,
272  0},
273  {"x19",
274  nullptr,
275  8,
276  0,
278  eFormatHex,
280  LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM},
281  nullptr,
282  nullptr,
283  nullptr,
284  0},
285  {"x20",
286  nullptr,
287  8,
288  0,
290  eFormatHex,
292  LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM},
293  nullptr,
294  nullptr,
295  nullptr,
296  0},
297  {"x21",
298  nullptr,
299  8,
300  0,
302  eFormatHex,
304  LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM},
305  nullptr,
306  nullptr,
307  nullptr,
308  0},
309  {"x22",
310  nullptr,
311  8,
312  0,
314  eFormatHex,
316  LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM},
317  nullptr,
318  nullptr,
319  nullptr,
320  0},
321  {"x23",
322  nullptr,
323  8,
324  0,
326  eFormatHex,
328  LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM},
329  nullptr,
330  nullptr,
331  nullptr,
332  0},
333  {"x24",
334  nullptr,
335  8,
336  0,
338  eFormatHex,
340  LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM},
341  nullptr,
342  nullptr,
343  nullptr,
344  0},
345  {"x25",
346  nullptr,
347  8,
348  0,
350  eFormatHex,
352  LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM},
353  nullptr,
354  nullptr,
355  nullptr,
356  0},
357  {"x26",
358  nullptr,
359  8,
360  0,
362  eFormatHex,
364  LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM},
365  nullptr,
366  nullptr,
367  nullptr,
368  0},
369  {"x27",
370  nullptr,
371  8,
372  0,
374  eFormatHex,
376  LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM},
377  nullptr,
378  nullptr,
379  nullptr,
380  0},
381  {"x28",
382  nullptr,
383  8,
384  0,
386  eFormatHex,
388  LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM},
389  nullptr,
390  nullptr,
391  nullptr,
392  0},
393  {"fp",
394  "x29",
395  8,
396  0,
398  eFormatHex,
400  LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM},
401  nullptr,
402  nullptr,
403  nullptr,
404  0},
405  {"lr",
406  "x30",
407  8,
408  0,
410  eFormatHex,
412  LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM},
413  nullptr,
414  nullptr,
415  nullptr,
416  0},
417  {"sp",
418  "x31",
419  8,
420  0,
422  eFormatHex,
424  LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM},
425  nullptr,
426  nullptr,
427  nullptr,
428  0},
429  {"pc",
430  nullptr,
431  8,
432  0,
434  eFormatHex,
436  LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM},
437  nullptr,
438  nullptr,
439  nullptr,
440  0},
441  {"cpsr",
442  "psr",
443  4,
444  0,
446  eFormatHex,
448  LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM},
449  nullptr,
450  nullptr,
451  nullptr,
452  0},
453 
454  {"v0",
455  nullptr,
456  16,
457  0,
461  LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM},
462  nullptr,
463  nullptr,
464  nullptr,
465  0},
466  {"v1",
467  nullptr,
468  16,
469  0,
473  LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM},
474  nullptr,
475  nullptr,
476  nullptr,
477  0},
478  {"v2",
479  nullptr,
480  16,
481  0,
485  LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM},
486  nullptr,
487  nullptr,
488  nullptr,
489  0},
490  {"v3",
491  nullptr,
492  16,
493  0,
497  LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM},
498  nullptr,
499  nullptr,
500  nullptr,
501  0},
502  {"v4",
503  nullptr,
504  16,
505  0,
509  LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM},
510  nullptr,
511  nullptr,
512  nullptr,
513  0},
514  {"v5",
515  nullptr,
516  16,
517  0,
521  LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM},
522  nullptr,
523  nullptr,
524  nullptr,
525  0},
526  {"v6",
527  nullptr,
528  16,
529  0,
533  LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM},
534  nullptr,
535  nullptr,
536  nullptr,
537  0},
538  {"v7",
539  nullptr,
540  16,
541  0,
545  LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM},
546  nullptr,
547  nullptr,
548  nullptr,
549  0},
550  {"v8",
551  nullptr,
552  16,
553  0,
557  LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM},
558  nullptr,
559  nullptr,
560  nullptr,
561  0},
562  {"v9",
563  nullptr,
564  16,
565  0,
569  LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM},
570  nullptr,
571  nullptr,
572  nullptr,
573  0},
574  {"v10",
575  nullptr,
576  16,
577  0,
581  LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM},
582  nullptr,
583  nullptr,
584  nullptr,
585  0},
586  {"v11",
587  nullptr,
588  16,
589  0,
593  LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM},
594  nullptr,
595  nullptr,
596  nullptr,
597  0},
598  {"v12",
599  nullptr,
600  16,
601  0,
605  LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM},
606  nullptr,
607  nullptr,
608  nullptr,
609  0},
610  {"v13",
611  nullptr,
612  16,
613  0,
617  LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM},
618  nullptr,
619  nullptr,
620  nullptr,
621  0},
622  {"v14",
623  nullptr,
624  16,
625  0,
629  LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM},
630  nullptr,
631  nullptr,
632  nullptr,
633  0},
634  {"v15",
635  nullptr,
636  16,
637  0,
641  LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM},
642  nullptr,
643  nullptr,
644  nullptr,
645  0},
646  {"v16",
647  nullptr,
648  16,
649  0,
653  LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM},
654  nullptr,
655  nullptr,
656  nullptr,
657  0},
658  {"v17",
659  nullptr,
660  16,
661  0,
665  LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM},
666  nullptr,
667  nullptr,
668  nullptr,
669  0},
670  {"v18",
671  nullptr,
672  16,
673  0,
677  LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM},
678  nullptr,
679  nullptr,
680  nullptr,
681  0},
682  {"v19",
683  nullptr,
684  16,
685  0,
689  LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM},
690  nullptr,
691  nullptr,
692  nullptr,
693  0},
694  {"v20",
695  nullptr,
696  16,
697  0,
701  LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM},
702  nullptr,
703  nullptr,
704  nullptr,
705  0},
706  {"v21",
707  nullptr,
708  16,
709  0,
713  LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM},
714  nullptr,
715  nullptr,
716  nullptr,
717  0},
718  {"v22",
719  nullptr,
720  16,
721  0,
725  LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM},
726  nullptr,
727  nullptr,
728  nullptr,
729  0},
730  {"v23",
731  nullptr,
732  16,
733  0,
737  LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM},
738  nullptr,
739  nullptr,
740  nullptr,
741  0},
742  {"v24",
743  nullptr,
744  16,
745  0,
749  LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM},
750  nullptr,
751  nullptr,
752  nullptr,
753  0},
754  {"v25",
755  nullptr,
756  16,
757  0,
761  LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM},
762  nullptr,
763  nullptr,
764  nullptr,
765  0},
766  {"v26",
767  nullptr,
768  16,
769  0,
773  LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM},
774  nullptr,
775  nullptr,
776  nullptr,
777  0},
778  {"v27",
779  nullptr,
780  16,
781  0,
785  LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM},
786  nullptr,
787  nullptr,
788  nullptr,
789  0},
790  {"v28",
791  nullptr,
792  16,
793  0,
797  LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM},
798  nullptr,
799  nullptr,
800  nullptr,
801  0},
802  {"v29",
803  nullptr,
804  16,
805  0,
809  LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM},
810  nullptr,
811  nullptr,
812  nullptr,
813  0},
814  {"v30",
815  nullptr,
816  16,
817  0,
821  LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM},
822  nullptr,
823  nullptr,
824  nullptr,
825  0},
826  {"v31",
827  nullptr,
828  16,
829  0,
833  LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM},
834  nullptr,
835  nullptr,
836  nullptr,
837  0},
838 
839  {"fpsr",
840  nullptr,
841  4,
842  0,
844  eFormatHex,
846  LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM},
847  nullptr,
848  nullptr,
849  nullptr,
850  0},
851  {"fpcr",
852  nullptr,
853  4,
854  0,
856  eFormatHex,
858  LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM},
859  nullptr,
860  nullptr,
861  nullptr,
862  0},
863 
864  {"s0",
865  nullptr,
866  4,
867  0,
869  eFormatFloat,
871  LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM},
872  nullptr,
873  nullptr,
874  nullptr,
875  0},
876  {"s1",
877  nullptr,
878  4,
879  0,
881  eFormatFloat,
883  LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM},
884  nullptr,
885  nullptr,
886  nullptr,
887  0},
888  {"s2",
889  nullptr,
890  4,
891  0,
893  eFormatFloat,
895  LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM},
896  nullptr,
897  nullptr,
898  nullptr,
899  0},
900  {"s3",
901  nullptr,
902  4,
903  0,
905  eFormatFloat,
907  LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM},
908  nullptr,
909  nullptr,
910  nullptr,
911  0},
912  {"s4",
913  nullptr,
914  4,
915  0,
917  eFormatFloat,
919  LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM},
920  nullptr,
921  nullptr,
922  nullptr,
923  0},
924  {"s5",
925  nullptr,
926  4,
927  0,
929  eFormatFloat,
931  LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM},
932  nullptr,
933  nullptr,
934  nullptr,
935  0},
936  {"s6",
937  nullptr,
938  4,
939  0,
941  eFormatFloat,
943  LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM},
944  nullptr,
945  nullptr,
946  nullptr,
947  0},
948  {"s7",
949  nullptr,
950  4,
951  0,
953  eFormatFloat,
955  LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM},
956  nullptr,
957  nullptr,
958  nullptr,
959  0},
960  {"s8",
961  nullptr,
962  4,
963  0,
965  eFormatFloat,
967  LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM},
968  nullptr,
969  nullptr,
970  nullptr,
971  0},
972  {"s9",
973  nullptr,
974  4,
975  0,
977  eFormatFloat,
979  LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM},
980  nullptr,
981  nullptr,
982  nullptr,
983  0},
984  {"s10",
985  nullptr,
986  4,
987  0,
989  eFormatFloat,
991  LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM},
992  nullptr,
993  nullptr,
994  nullptr,
995  0},
996  {"s11",
997  nullptr,
998  4,
999  0,
1001  eFormatFloat,
1003  LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM},
1004  nullptr,
1005  nullptr,
1006  nullptr,
1007  0},
1008  {"s12",
1009  nullptr,
1010  4,
1011  0,
1013  eFormatFloat,
1015  LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM},
1016  nullptr,
1017  nullptr,
1018  nullptr,
1019  0},
1020  {"s13",
1021  nullptr,
1022  4,
1023  0,
1025  eFormatFloat,
1027  LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM},
1028  nullptr,
1029  nullptr,
1030  nullptr,
1031  0},
1032  {"s14",
1033  nullptr,
1034  4,
1035  0,
1037  eFormatFloat,
1039  LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM},
1040  nullptr,
1041  nullptr,
1042  nullptr,
1043  0},
1044  {"s15",
1045  nullptr,
1046  4,
1047  0,
1049  eFormatFloat,
1051  LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM},
1052  nullptr,
1053  nullptr,
1054  nullptr,
1055  0},
1056  {"s16",
1057  nullptr,
1058  4,
1059  0,
1061  eFormatFloat,
1063  LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM},
1064  nullptr,
1065  nullptr,
1066  nullptr,
1067  0},
1068  {"s17",
1069  nullptr,
1070  4,
1071  0,
1073  eFormatFloat,
1075  LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM},
1076  nullptr,
1077  nullptr,
1078  nullptr,
1079  0},
1080  {"s18",
1081  nullptr,
1082  4,
1083  0,
1085  eFormatFloat,
1087  LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM},
1088  nullptr,
1089  nullptr,
1090  nullptr,
1091  0},
1092  {"s19",
1093  nullptr,
1094  4,
1095  0,
1097  eFormatFloat,
1099  LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM},
1100  nullptr,
1101  nullptr,
1102  nullptr,
1103  0},
1104  {"s20",
1105  nullptr,
1106  4,
1107  0,
1109  eFormatFloat,
1111  LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM},
1112  nullptr,
1113  nullptr,
1114  nullptr,
1115  0},
1116  {"s21",
1117  nullptr,
1118  4,
1119  0,
1121  eFormatFloat,
1123  LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM},
1124  nullptr,
1125  nullptr,
1126  nullptr,
1127  0},
1128  {"s22",
1129  nullptr,
1130  4,
1131  0,
1133  eFormatFloat,
1135  LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM},
1136  nullptr,
1137  nullptr,
1138  nullptr,
1139  0},
1140  {"s23",
1141  nullptr,
1142  4,
1143  0,
1145  eFormatFloat,
1147  LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM},
1148  nullptr,
1149  nullptr,
1150  nullptr,
1151  0},
1152  {"s24",
1153  nullptr,
1154  4,
1155  0,
1157  eFormatFloat,
1159  LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM},
1160  nullptr,
1161  nullptr,
1162  nullptr,
1163  0},
1164  {"s25",
1165  nullptr,
1166  4,
1167  0,
1169  eFormatFloat,
1171  LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM},
1172  nullptr,
1173  nullptr,
1174  nullptr,
1175  0},
1176  {"s26",
1177  nullptr,
1178  4,
1179  0,
1181  eFormatFloat,
1183  LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM},
1184  nullptr,
1185  nullptr,
1186  nullptr,
1187  0},
1188  {"s27",
1189  nullptr,
1190  4,
1191  0,
1193  eFormatFloat,
1195  LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM},
1196  nullptr,
1197  nullptr,
1198  nullptr,
1199  0},
1200  {"s28",
1201  nullptr,
1202  4,
1203  0,
1205  eFormatFloat,
1207  LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM},
1208  nullptr,
1209  nullptr,
1210  nullptr,
1211  0},
1212  {"s29",
1213  nullptr,
1214  4,
1215  0,
1217  eFormatFloat,
1219  LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM},
1220  nullptr,
1221  nullptr,
1222  nullptr,
1223  0},
1224  {"s30",
1225  nullptr,
1226  4,
1227  0,
1229  eFormatFloat,
1231  LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM},
1232  nullptr,
1233  nullptr,
1234  nullptr,
1235  0},
1236  {"s31",
1237  nullptr,
1238  4,
1239  0,
1241  eFormatFloat,
1243  LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM},
1244  nullptr,
1245  nullptr,
1246  nullptr,
1247  0},
1248 
1249  {"d0",
1250  nullptr,
1251  8,
1252  0,
1254  eFormatFloat,
1256  LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM},
1257  nullptr,
1258  nullptr,
1259  nullptr,
1260  0},
1261  {"d1",
1262  nullptr,
1263  8,
1264  0,
1266  eFormatFloat,
1268  LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM},
1269  nullptr,
1270  nullptr,
1271  nullptr,
1272  0},
1273  {"d2",
1274  nullptr,
1275  8,
1276  0,
1278  eFormatFloat,
1280  LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM},
1281  nullptr,
1282  nullptr,
1283  nullptr,
1284  0},
1285  {"d3",
1286  nullptr,
1287  8,
1288  0,
1290  eFormatFloat,
1292  LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM},
1293  nullptr,
1294  nullptr,
1295  nullptr,
1296  0},
1297  {"d4",
1298  nullptr,
1299  8,
1300  0,
1302  eFormatFloat,
1304  LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM},
1305  nullptr,
1306  nullptr,
1307  nullptr,
1308  0},
1309  {"d5",
1310  nullptr,
1311  8,
1312  0,
1314  eFormatFloat,
1316  LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM},
1317  nullptr,
1318  nullptr,
1319  nullptr,
1320  0},
1321  {"d6",
1322  nullptr,
1323  8,
1324  0,
1326  eFormatFloat,
1328  LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM},
1329  nullptr,
1330  nullptr,
1331  nullptr,
1332  0},
1333  {"d7",
1334  nullptr,
1335  8,
1336  0,
1338  eFormatFloat,
1340  LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM},
1341  nullptr,
1342  nullptr,
1343  nullptr,
1344  0},
1345  {"d8",
1346  nullptr,
1347  8,
1348  0,
1350  eFormatFloat,
1352  LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM},
1353  nullptr,
1354  nullptr,
1355  nullptr,
1356  0},
1357  {"d9",
1358  nullptr,
1359  8,
1360  0,
1362  eFormatFloat,
1364  LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM},
1365  nullptr,
1366  nullptr,
1367  nullptr,
1368  0},
1369  {"d10",
1370  nullptr,
1371  8,
1372  0,
1374  eFormatFloat,
1376  LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM},
1377  nullptr,
1378  nullptr,
1379  nullptr,
1380  0},
1381  {"d11",
1382  nullptr,
1383  8,
1384  0,
1386  eFormatFloat,
1388  LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM},
1389  nullptr,
1390  nullptr,
1391  nullptr,
1392  0},
1393  {"d12",
1394  nullptr,
1395  8,
1396  0,
1398  eFormatFloat,
1400  LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM},
1401  nullptr,
1402  nullptr,
1403  nullptr,
1404  0},
1405  {"d13",
1406  nullptr,
1407  8,
1408  0,
1410  eFormatFloat,
1412  LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM},
1413  nullptr,
1414  nullptr,
1415  nullptr,
1416  0},
1417  {"d14",
1418  nullptr,
1419  8,
1420  0,
1422  eFormatFloat,
1424  LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM},
1425  nullptr,
1426  nullptr,
1427  nullptr,
1428  0},
1429  {"d15",
1430  nullptr,
1431  8,
1432  0,
1434  eFormatFloat,
1436  LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM},
1437  nullptr,
1438  nullptr,
1439  nullptr,
1440  0},
1441  {"d16",
1442  nullptr,
1443  8,
1444  0,
1446  eFormatFloat,
1448  LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM},
1449  nullptr,
1450  nullptr,
1451  nullptr,
1452  0},
1453  {"d17",
1454  nullptr,
1455  8,
1456  0,
1458  eFormatFloat,
1460  LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM},
1461  nullptr,
1462  nullptr,
1463  nullptr,
1464  0},
1465  {"d18",
1466  nullptr,
1467  8,
1468  0,
1470  eFormatFloat,
1472  LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM},
1473  nullptr,
1474  nullptr,
1475  nullptr,
1476  0},
1477  {"d19",
1478  nullptr,
1479  8,
1480  0,
1482  eFormatFloat,
1484  LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM},
1485  nullptr,
1486  nullptr,
1487  nullptr,
1488  0},
1489  {"d20",
1490  nullptr,
1491  8,
1492  0,
1494  eFormatFloat,
1496  LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM},
1497  nullptr,
1498  nullptr,
1499  nullptr,
1500  0},
1501  {"d21",
1502  nullptr,
1503  8,
1504  0,
1506  eFormatFloat,
1508  LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM},
1509  nullptr,
1510  nullptr,
1511  nullptr,
1512  0},
1513  {"d22",
1514  nullptr,
1515  8,
1516  0,
1518  eFormatFloat,
1520  LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM},
1521  nullptr,
1522  nullptr,
1523  nullptr,
1524  0},
1525  {"d23",
1526  nullptr,
1527  8,
1528  0,
1530  eFormatFloat,
1532  LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM},
1533  nullptr,
1534  nullptr,
1535  nullptr,
1536  0},
1537  {"d24",
1538  nullptr,
1539  8,
1540  0,
1542  eFormatFloat,
1544  LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM},
1545  nullptr,
1546  nullptr,
1547  nullptr,
1548  0},
1549  {"d25",
1550  nullptr,
1551  8,
1552  0,
1554  eFormatFloat,
1556  LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM},
1557  nullptr,
1558  nullptr,
1559  nullptr,
1560  0},
1561  {"d26",
1562  nullptr,
1563  8,
1564  0,
1566  eFormatFloat,
1568  LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM},
1569  nullptr,
1570  nullptr,
1571  nullptr,
1572  0},
1573  {"d27",
1574  nullptr,
1575  8,
1576  0,
1578  eFormatFloat,
1580  LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM},
1581  nullptr,
1582  nullptr,
1583  nullptr,
1584  0},
1585  {"d28",
1586  nullptr,
1587  8,
1588  0,
1590  eFormatFloat,
1592  LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM},
1593  nullptr,
1594  nullptr,
1595  nullptr,
1596  0},
1597  {"d29",
1598  nullptr,
1599  8,
1600  0,
1602  eFormatFloat,
1604  LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM},
1605  nullptr,
1606  nullptr,
1607  nullptr,
1608  0},
1609  {"d30",
1610  nullptr,
1611  8,
1612  0,
1614  eFormatFloat,
1616  LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM},
1617  nullptr,
1618  nullptr,
1619  nullptr,
1620  0},
1621  {"d31",
1622  nullptr,
1623  8,
1624  0,
1626  eFormatFloat,
1628  LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM},
1629  nullptr,
1630  nullptr,
1631  nullptr,
1632  0}};
1633 
1635  llvm::array_lengthof(g_register_infos);
1637 
1638 const lldb_private::RegisterInfo *
1640  // Make the C-string names and alt_names for the register infos into const
1641  // C-string values by having the ConstString unique the names in the global
1642  // constant C-string pool.
1645  for (uint32_t i = 0; i < k_num_register_infos; ++i) {
1646  if (g_register_infos[i].name)
1647  g_register_infos[i].name =
1649  if (g_register_infos[i].alt_name)
1650  g_register_infos[i].alt_name =
1651  ConstString(g_register_infos[i].alt_name).GetCString();
1652  }
1653  }
1654  count = k_num_register_infos;
1655  return g_register_infos;
1656 }
1657 
1658 size_t ABIMacOSX_arm64::GetRedZoneSize() const { return 128; }
1659 
1660 // Static Functions
1661 
1662 ABISP
1663 ABIMacOSX_arm64::CreateInstance(ProcessSP process_sp, const ArchSpec &arch) {
1664  const llvm::Triple::ArchType arch_type = arch.GetTriple().getArch();
1665  const llvm::Triple::VendorType vendor_type = arch.GetTriple().getVendor();
1666 
1667  if (vendor_type == llvm::Triple::Apple) {
1668  if (arch_type == llvm::Triple::aarch64) {
1669  return ABISP(new ABIMacOSX_arm64(process_sp));
1670  }
1671  }
1672 
1673  return ABISP();
1674 }
1675 
1677  Thread &thread, lldb::addr_t sp, lldb::addr_t func_addr,
1678  lldb::addr_t return_addr, llvm::ArrayRef<lldb::addr_t> args) const {
1679  RegisterContext *reg_ctx = thread.GetRegisterContext().get();
1680  if (!reg_ctx)
1681  return false;
1682 
1684 
1685  if (log) {
1686  StreamString s;
1687  s.Printf("ABISysV_x86_64::PrepareTrivialCall (tid = 0x%" PRIx64
1688  ", sp = 0x%" PRIx64 ", func_addr = 0x%" PRIx64
1689  ", return_addr = 0x%" PRIx64,
1690  thread.GetID(), (uint64_t)sp, (uint64_t)func_addr,
1691  (uint64_t)return_addr);
1692 
1693  for (size_t i = 0; i < args.size(); ++i)
1694  s.Printf(", arg%d = 0x%" PRIx64, static_cast<int>(i + 1), args[i]);
1695  s.PutCString(")");
1696  log->PutString(s.GetString());
1697  }
1698 
1699  const uint32_t pc_reg_num = reg_ctx->ConvertRegisterKindToRegisterNumber(
1701  const uint32_t sp_reg_num = reg_ctx->ConvertRegisterKindToRegisterNumber(
1703  const uint32_t ra_reg_num = reg_ctx->ConvertRegisterKindToRegisterNumber(
1705 
1706  // x0 - x7 contain first 8 simple args
1707  if (args.size() > 8) // TODO handle more than 6 arguments
1708  return false;
1709 
1710  for (size_t i = 0; i < args.size(); ++i) {
1711  const RegisterInfo *reg_info = reg_ctx->GetRegisterInfo(
1713  if (log)
1714  log->Printf("About to write arg%d (0x%" PRIx64 ") into %s",
1715  static_cast<int>(i + 1), args[i], reg_info->name);
1716  if (!reg_ctx->WriteRegisterFromUnsigned(reg_info, args[i]))
1717  return false;
1718  }
1719 
1720  // Set "lr" to the return address
1721  if (!reg_ctx->WriteRegisterFromUnsigned(
1722  reg_ctx->GetRegisterInfoAtIndex(ra_reg_num), return_addr))
1723  return false;
1724 
1725  // Set "sp" to the requested value
1726  if (!reg_ctx->WriteRegisterFromUnsigned(
1727  reg_ctx->GetRegisterInfoAtIndex(sp_reg_num), sp))
1728  return false;
1729 
1730  // Set "pc" to the address requested
1731  if (!reg_ctx->WriteRegisterFromUnsigned(
1732  reg_ctx->GetRegisterInfoAtIndex(pc_reg_num), func_addr))
1733  return false;
1734 
1735  return true;
1736 }
1737 
1739  ValueList &values) const {
1740  uint32_t num_values = values.GetSize();
1741 
1742  ExecutionContext exe_ctx(thread.shared_from_this());
1743 
1744  // Extract the register context so we can read arguments from registers
1745 
1746  RegisterContext *reg_ctx = thread.GetRegisterContext().get();
1747 
1748  if (!reg_ctx)
1749  return false;
1750 
1751  addr_t sp = 0;
1752 
1753  for (uint32_t value_idx = 0; value_idx < num_values; ++value_idx) {
1754  // We currently only support extracting values with Clang QualTypes. Do we
1755  // care about others?
1756  Value *value = values.GetValueAtIndex(value_idx);
1757 
1758  if (!value)
1759  return false;
1760 
1761  CompilerType value_type = value->GetCompilerType();
1762  llvm::Optional<uint64_t> bit_size = value_type.GetBitSize(&thread);
1763  if (!bit_size)
1764  return false;
1765 
1766  bool is_signed = false;
1767  size_t bit_width = 0;
1768  if (value_type.IsIntegerOrEnumerationType(is_signed)) {
1769  bit_width = *bit_size;
1770  } else if (value_type.IsPointerOrReferenceType()) {
1771  bit_width = *bit_size;
1772  } else {
1773  // We only handle integer, pointer and reference types currently...
1774  return false;
1775  }
1776 
1777  if (bit_width <= (exe_ctx.GetProcessRef().GetAddressByteSize() * 8)) {
1778  if (value_idx < 8) {
1779  // Arguments 1-6 are in x0-x5...
1780  const RegisterInfo *reg_info = nullptr;
1781  // Search by generic ID first, then fall back to by name
1782  uint32_t arg_reg_num = reg_ctx->ConvertRegisterKindToRegisterNumber(
1784  if (arg_reg_num != LLDB_INVALID_REGNUM) {
1785  reg_info = reg_ctx->GetRegisterInfoAtIndex(arg_reg_num);
1786  } else {
1787  switch (value_idx) {
1788  case 0:
1789  reg_info = reg_ctx->GetRegisterInfoByName("x0");
1790  break;
1791  case 1:
1792  reg_info = reg_ctx->GetRegisterInfoByName("x1");
1793  break;
1794  case 2:
1795  reg_info = reg_ctx->GetRegisterInfoByName("x2");
1796  break;
1797  case 3:
1798  reg_info = reg_ctx->GetRegisterInfoByName("x3");
1799  break;
1800  case 4:
1801  reg_info = reg_ctx->GetRegisterInfoByName("x4");
1802  break;
1803  case 5:
1804  reg_info = reg_ctx->GetRegisterInfoByName("x5");
1805  break;
1806  case 6:
1807  reg_info = reg_ctx->GetRegisterInfoByName("x6");
1808  break;
1809  case 7:
1810  reg_info = reg_ctx->GetRegisterInfoByName("x7");
1811  break;
1812  }
1813  }
1814 
1815  if (reg_info) {
1816  RegisterValue reg_value;
1817 
1818  if (reg_ctx->ReadRegister(reg_info, reg_value)) {
1819  if (is_signed)
1820  reg_value.SignExtend(bit_width);
1821  if (!reg_value.GetScalarValue(value->GetScalar()))
1822  return false;
1823  continue;
1824  }
1825  }
1826  return false;
1827  } else {
1828  if (sp == 0) {
1829  // Read the stack pointer if we already haven't read it
1830  sp = reg_ctx->GetSP(0);
1831  if (sp == 0)
1832  return false;
1833  }
1834 
1835  // Arguments 5 on up are on the stack
1836  const uint32_t arg_byte_size = (bit_width + (8 - 1)) / 8;
1837  Status error;
1838  if (!exe_ctx.GetProcessRef().ReadScalarIntegerFromMemory(
1839  sp, arg_byte_size, is_signed, value->GetScalar(), error))
1840  return false;
1841 
1842  sp += arg_byte_size;
1843  // Align up to the next 8 byte boundary if needed
1844  if (sp % 8) {
1845  sp >>= 3;
1846  sp += 1;
1847  sp <<= 3;
1848  }
1849  }
1850  }
1851  }
1852  return true;
1853 }
1854 
1855 Status
1856 ABIMacOSX_arm64::SetReturnValueObject(lldb::StackFrameSP &frame_sp,
1857  lldb::ValueObjectSP &new_value_sp) {
1858  Status error;
1859  if (!new_value_sp) {
1860  error.SetErrorString("Empty value object for return value.");
1861  return error;
1862  }
1863 
1864  CompilerType return_value_type = new_value_sp->GetCompilerType();
1865  if (!return_value_type) {
1866  error.SetErrorString("Null clang type for return value.");
1867  return error;
1868  }
1869 
1870  Thread *thread = frame_sp->GetThread().get();
1871 
1872  RegisterContext *reg_ctx = thread->GetRegisterContext().get();
1873 
1874  if (reg_ctx) {
1875  DataExtractor data;
1876  Status data_error;
1877  const uint64_t byte_size = new_value_sp->GetData(data, data_error);
1878  if (data_error.Fail()) {
1880  "Couldn't convert return value to raw data: %s",
1881  data_error.AsCString());
1882  return error;
1883  }
1884 
1885  const uint32_t type_flags = return_value_type.GetTypeInfo(nullptr);
1886  if (type_flags & eTypeIsScalar || type_flags & eTypeIsPointer) {
1887  if (type_flags & eTypeIsInteger || type_flags & eTypeIsPointer) {
1888  // Extract the register context so we can read arguments from registers
1889  lldb::offset_t offset = 0;
1890  if (byte_size <= 16) {
1891  const RegisterInfo *x0_info = reg_ctx->GetRegisterInfoByName("x0", 0);
1892  if (byte_size <= 8) {
1893  uint64_t raw_value = data.GetMaxU64(&offset, byte_size);
1894 
1895  if (!reg_ctx->WriteRegisterFromUnsigned(x0_info, raw_value))
1896  error.SetErrorString("failed to write register x0");
1897  } else {
1898  uint64_t raw_value = data.GetMaxU64(&offset, 8);
1899 
1900  if (reg_ctx->WriteRegisterFromUnsigned(x0_info, raw_value)) {
1901  const RegisterInfo *x1_info =
1902  reg_ctx->GetRegisterInfoByName("x1", 0);
1903  raw_value = data.GetMaxU64(&offset, byte_size - offset);
1904 
1905  if (!reg_ctx->WriteRegisterFromUnsigned(x1_info, raw_value))
1906  error.SetErrorString("failed to write register x1");
1907  }
1908  }
1909  } else {
1910  error.SetErrorString("We don't support returning longer than 128 bit "
1911  "integer values at present.");
1912  }
1913  } else if (type_flags & eTypeIsFloat) {
1914  if (type_flags & eTypeIsComplex) {
1915  // Don't handle complex yet.
1916  error.SetErrorString(
1917  "returning complex float values are not supported");
1918  } else {
1919  const RegisterInfo *v0_info = reg_ctx->GetRegisterInfoByName("v0", 0);
1920 
1921  if (v0_info) {
1922  if (byte_size <= 16) {
1923  if (byte_size <= RegisterValue::GetMaxByteSize()) {
1924  RegisterValue reg_value;
1925  error = reg_value.SetValueFromData(v0_info, data, 0, true);
1926  if (error.Success()) {
1927  if (!reg_ctx->WriteRegister(v0_info, reg_value))
1928  error.SetErrorString("failed to write register v0");
1929  }
1930  } else {
1932  "returning float values with a byte size of %" PRIu64
1933  " are not supported",
1934  byte_size);
1935  }
1936  } else {
1937  error.SetErrorString("returning float values longer than 128 "
1938  "bits are not supported");
1939  }
1940  } else {
1941  error.SetErrorString("v0 register is not available on this target");
1942  }
1943  }
1944  }
1945  } else if (type_flags & eTypeIsVector) {
1946  if (byte_size > 0) {
1947  const RegisterInfo *v0_info = reg_ctx->GetRegisterInfoByName("v0", 0);
1948 
1949  if (v0_info) {
1950  if (byte_size <= v0_info->byte_size) {
1951  RegisterValue reg_value;
1952  error = reg_value.SetValueFromData(v0_info, data, 0, true);
1953  if (error.Success()) {
1954  if (!reg_ctx->WriteRegister(v0_info, reg_value))
1955  error.SetErrorString("failed to write register v0");
1956  }
1957  }
1958  }
1959  }
1960  }
1961  } else {
1962  error.SetErrorString("no registers are available");
1963  }
1964 
1965  return error;
1966 }
1967 
1969  unwind_plan.Clear();
1970  unwind_plan.SetRegisterKind(eRegisterKindDWARF);
1971 
1972  uint32_t lr_reg_num = arm64_dwarf::lr;
1973  uint32_t sp_reg_num = arm64_dwarf::sp;
1974  uint32_t pc_reg_num = arm64_dwarf::pc;
1975 
1977 
1978  // Our previous Call Frame Address is the stack pointer
1979  row->GetCFAValue().SetIsRegisterPlusOffset(sp_reg_num, 0);
1980 
1981  // Our previous PC is in the LR
1982  row->SetRegisterLocationToRegister(pc_reg_num, lr_reg_num, true);
1983 
1984  unwind_plan.AppendRow(row);
1985 
1986  // All other registers are the same.
1987 
1988  unwind_plan.SetSourceName("arm64 at-func-entry default");
1989  unwind_plan.SetSourcedFromCompiler(eLazyBoolNo);
1990 
1991  return true;
1992 }
1993 
1995  unwind_plan.Clear();
1996  unwind_plan.SetRegisterKind(eRegisterKindDWARF);
1997 
1998  uint32_t fp_reg_num = arm64_dwarf::fp;
1999  uint32_t pc_reg_num = arm64_dwarf::pc;
2000 
2002  const int32_t ptr_size = 8;
2003 
2004  row->GetCFAValue().SetIsRegisterPlusOffset(fp_reg_num, 2 * ptr_size);
2005  row->SetOffset(0);
2006 
2007  row->SetRegisterLocationToAtCFAPlusOffset(fp_reg_num, ptr_size * -2, true);
2008  row->SetRegisterLocationToAtCFAPlusOffset(pc_reg_num, ptr_size * -1, true);
2009 
2010  unwind_plan.AppendRow(row);
2011  unwind_plan.SetSourceName("arm64-apple-darwin default unwind plan");
2012  unwind_plan.SetSourcedFromCompiler(eLazyBoolNo);
2014  return true;
2015 }
2016 
2017 // AAPCS64 (Procedure Call Standard for the ARM 64-bit Architecture) says
2018 // registers x19 through x28 and sp are callee preserved. v8-v15 are non-
2019 // volatile (and specifically only the lower 8 bytes of these regs), the rest
2020 // of the fp/SIMD registers are volatile.
2021 
2022 // We treat x29 as callee preserved also, else the unwinder won't try to
2023 // retrieve fp saves.
2024 
2025 bool ABIMacOSX_arm64::RegisterIsVolatile(const RegisterInfo *reg_info) {
2026  if (reg_info) {
2027  const char *name = reg_info->name;
2028 
2029  // Sometimes we'll be called with the "alternate" name for these registers;
2030  // recognize them as non-volatile.
2031 
2032  if (name[0] == 'p' && name[1] == 'c') // pc
2033  return false;
2034  if (name[0] == 'f' && name[1] == 'p') // fp
2035  return false;
2036  if (name[0] == 's' && name[1] == 'p') // sp
2037  return false;
2038  if (name[0] == 'l' && name[1] == 'r') // lr
2039  return false;
2040 
2041  if (name[0] == 'x') {
2042  // Volatile registers: x0-x18, x30 (lr)
2043  // Return false for the non-volatile gpr regs, true for everything else
2044  switch (name[1]) {
2045  case '1':
2046  switch (name[2]) {
2047  case '9':
2048  return false; // x19 is non-volatile
2049  default:
2050  return true;
2051  }
2052  break;
2053  case '2':
2054  switch (name[2]) {
2055  case '0':
2056  case '1':
2057  case '2':
2058  case '3':
2059  case '4':
2060  case '5':
2061  case '6':
2062  case '7':
2063  case '8':
2064  return false; // x20 - 28 are non-volatile
2065  case '9':
2066  return false; // x29 aka fp treat as non-volatile on Darwin
2067  default:
2068  return true;
2069  }
2070  case '3': // x30 aka lr treat as non-volatile
2071  if (name[2] == '0')
2072  return false;
2073  break;
2074  default:
2075  return true;
2076  }
2077  } else if (name[0] == 'v' || name[0] == 's' || name[0] == 'd') {
2078  // Volatile registers: v0-7, v16-v31
2079  // Return false for non-volatile fp/SIMD regs, true for everything else
2080  switch (name[1]) {
2081  case '8':
2082  case '9':
2083  return false; // v8-v9 are non-volatile
2084  case '1':
2085  switch (name[2]) {
2086  case '0':
2087  case '1':
2088  case '2':
2089  case '3':
2090  case '4':
2091  case '5':
2092  return false; // v10-v15 are non-volatile
2093  default:
2094  return true;
2095  }
2096  default:
2097  return true;
2098  }
2099  }
2100  }
2101  return true;
2102 }
2103 
2105  ExecutionContext &exe_ctx, RegisterContext *reg_ctx,
2106  const CompilerType &value_type,
2107  bool is_return_value, // false => parameter, true => return value
2108  uint32_t &NGRN, // NGRN (see ABI documentation)
2109  uint32_t &NSRN, // NSRN (see ABI documentation)
2110  DataExtractor &data) {
2111  llvm::Optional<uint64_t> byte_size = value_type.GetByteSize(nullptr);
2112  if (!byte_size || *byte_size == 0)
2113  return false;
2114 
2115  std::unique_ptr<DataBufferHeap> heap_data_up(
2116  new DataBufferHeap(*byte_size, 0));
2117  const ByteOrder byte_order = exe_ctx.GetProcessRef().GetByteOrder();
2118  Status error;
2119 
2120  CompilerType base_type;
2121  const uint32_t homogeneous_count =
2122  value_type.IsHomogeneousAggregate(&base_type);
2123  if (homogeneous_count > 0 && homogeneous_count <= 8) {
2124  // Make sure we have enough registers
2125  if (NSRN < 8 && (8 - NSRN) >= homogeneous_count) {
2126  if (!base_type)
2127  return false;
2128  llvm::Optional<uint64_t> base_byte_size = base_type.GetByteSize(nullptr);
2129  if (!base_byte_size)
2130  return false;
2131  uint32_t data_offset = 0;
2132 
2133  for (uint32_t i = 0; i < homogeneous_count; ++i) {
2134  char v_name[8];
2135  ::snprintf(v_name, sizeof(v_name), "v%u", NSRN);
2136  const RegisterInfo *reg_info =
2137  reg_ctx->GetRegisterInfoByName(v_name, 0);
2138  if (reg_info == nullptr)
2139  return false;
2140 
2141  if (*base_byte_size > reg_info->byte_size)
2142  return false;
2143 
2144  RegisterValue reg_value;
2145 
2146  if (!reg_ctx->ReadRegister(reg_info, reg_value))
2147  return false;
2148 
2149  // Make sure we have enough room in "heap_data_up"
2150  if ((data_offset + *base_byte_size) <= heap_data_up->GetByteSize()) {
2151  const size_t bytes_copied = reg_value.GetAsMemoryData(
2152  reg_info, heap_data_up->GetBytes() + data_offset, *base_byte_size,
2153  byte_order, error);
2154  if (bytes_copied != *base_byte_size)
2155  return false;
2156  data_offset += bytes_copied;
2157  ++NSRN;
2158  } else
2159  return false;
2160  }
2161  data.SetByteOrder(byte_order);
2163  data.SetData(DataBufferSP(heap_data_up.release()));
2164  return true;
2165  }
2166  }
2167 
2168  const size_t max_reg_byte_size = 16;
2169  if (*byte_size <= max_reg_byte_size) {
2170  size_t bytes_left = *byte_size;
2171  uint32_t data_offset = 0;
2172  while (data_offset < *byte_size) {
2173  if (NGRN >= 8)
2174  return false;
2175 
2176  uint32_t reg_num = reg_ctx->ConvertRegisterKindToRegisterNumber(
2178  if (reg_num == LLDB_INVALID_REGNUM)
2179  return false;
2180 
2181  const RegisterInfo *reg_info = reg_ctx->GetRegisterInfoAtIndex(reg_num);
2182  if (reg_info == nullptr)
2183  return false;
2184 
2185  RegisterValue reg_value;
2186 
2187  if (!reg_ctx->ReadRegister(reg_info, reg_value))
2188  return false;
2189 
2190  const size_t curr_byte_size = std::min<size_t>(8, bytes_left);
2191  const size_t bytes_copied = reg_value.GetAsMemoryData(
2192  reg_info, heap_data_up->GetBytes() + data_offset, curr_byte_size,
2193  byte_order, error);
2194  if (bytes_copied == 0)
2195  return false;
2196  if (bytes_copied >= bytes_left)
2197  break;
2198  data_offset += bytes_copied;
2199  bytes_left -= bytes_copied;
2200  ++NGRN;
2201  }
2202  } else {
2203  const RegisterInfo *reg_info = nullptr;
2204  if (is_return_value) {
2205  // We are assuming we are decoding this immediately after returning from
2206  // a function call and that the address of the structure is in x8
2207  reg_info = reg_ctx->GetRegisterInfoByName("x8", 0);
2208  } else {
2209  // We are assuming we are stopped at the first instruction in a function
2210  // and that the ABI is being respected so all parameters appear where
2211  // they should be (functions with no external linkage can legally violate
2212  // the ABI).
2213  if (NGRN >= 8)
2214  return false;
2215 
2216  uint32_t reg_num = reg_ctx->ConvertRegisterKindToRegisterNumber(
2218  if (reg_num == LLDB_INVALID_REGNUM)
2219  return false;
2220  reg_info = reg_ctx->GetRegisterInfoAtIndex(reg_num);
2221  if (reg_info == nullptr)
2222  return false;
2223  ++NGRN;
2224  }
2225 
2226  if (reg_info == nullptr)
2227  return false;
2228 
2229  const lldb::addr_t value_addr =
2230  reg_ctx->ReadRegisterAsUnsigned(reg_info, LLDB_INVALID_ADDRESS);
2231 
2232  if (value_addr == LLDB_INVALID_ADDRESS)
2233  return false;
2234 
2235  if (exe_ctx.GetProcessRef().ReadMemory(
2236  value_addr, heap_data_up->GetBytes(), heap_data_up->GetByteSize(),
2237  error) != heap_data_up->GetByteSize()) {
2238  return false;
2239  }
2240  }
2241 
2242  data.SetByteOrder(byte_order);
2244  data.SetData(DataBufferSP(heap_data_up.release()));
2245  return true;
2246 }
2247 
2249  Thread &thread, CompilerType &return_compiler_type) const {
2250  ValueObjectSP return_valobj_sp;
2251  Value value;
2252 
2253  ExecutionContext exe_ctx(thread.shared_from_this());
2254  if (exe_ctx.GetTargetPtr() == nullptr || exe_ctx.GetProcessPtr() == nullptr)
2255  return return_valobj_sp;
2256 
2257  // value.SetContext (Value::eContextTypeClangType, return_compiler_type);
2258  value.SetCompilerType(return_compiler_type);
2259 
2260  RegisterContext *reg_ctx = thread.GetRegisterContext().get();
2261  if (!reg_ctx)
2262  return return_valobj_sp;
2263 
2264  llvm::Optional<uint64_t> byte_size =
2265  return_compiler_type.GetByteSize(nullptr);
2266  if (!byte_size)
2267  return return_valobj_sp;
2268 
2269  const uint32_t type_flags = return_compiler_type.GetTypeInfo(nullptr);
2270  if (type_flags & eTypeIsScalar || type_flags & eTypeIsPointer) {
2271  value.SetValueType(Value::eValueTypeScalar);
2272 
2273  bool success = false;
2274  if (type_flags & eTypeIsInteger || type_flags & eTypeIsPointer) {
2275  // Extract the register context so we can read arguments from registers
2276  if (*byte_size <= 8) {
2277  const RegisterInfo *x0_reg_info =
2278  reg_ctx->GetRegisterInfoByName("x0", 0);
2279  if (x0_reg_info) {
2280  uint64_t raw_value =
2281  thread.GetRegisterContext()->ReadRegisterAsUnsigned(x0_reg_info,
2282  0);
2283  const bool is_signed = (type_flags & eTypeIsSigned) != 0;
2284  switch (*byte_size) {
2285  default:
2286  break;
2287  case 16: // uint128_t
2288  // In register x0 and x1
2289  {
2290  const RegisterInfo *x1_reg_info =
2291  reg_ctx->GetRegisterInfoByName("x1", 0);
2292 
2293  if (x1_reg_info) {
2294  if (*byte_size <=
2295  x0_reg_info->byte_size + x1_reg_info->byte_size) {
2296  std::unique_ptr<DataBufferHeap> heap_data_up(
2297  new DataBufferHeap(*byte_size, 0));
2298  const ByteOrder byte_order =
2299  exe_ctx.GetProcessRef().GetByteOrder();
2300  RegisterValue x0_reg_value;
2301  RegisterValue x1_reg_value;
2302  if (reg_ctx->ReadRegister(x0_reg_info, x0_reg_value) &&
2303  reg_ctx->ReadRegister(x1_reg_info, x1_reg_value)) {
2304  Status error;
2305  if (x0_reg_value.GetAsMemoryData(
2306  x0_reg_info, heap_data_up->GetBytes() + 0, 8,
2307  byte_order, error) &&
2308  x1_reg_value.GetAsMemoryData(
2309  x1_reg_info, heap_data_up->GetBytes() + 8, 8,
2310  byte_order, error)) {
2311  DataExtractor data(
2312  DataBufferSP(heap_data_up.release()), byte_order,
2313  exe_ctx.GetProcessRef().GetAddressByteSize());
2314 
2315  return_valobj_sp = ValueObjectConstResult::Create(
2316  &thread, return_compiler_type, ConstString(""), data);
2317  return return_valobj_sp;
2318  }
2319  }
2320  }
2321  }
2322  }
2323  break;
2324  case sizeof(uint64_t):
2325  if (is_signed)
2326  value.GetScalar() = (int64_t)(raw_value);
2327  else
2328  value.GetScalar() = (uint64_t)(raw_value);
2329  success = true;
2330  break;
2331 
2332  case sizeof(uint32_t):
2333  if (is_signed)
2334  value.GetScalar() = (int32_t)(raw_value & UINT32_MAX);
2335  else
2336  value.GetScalar() = (uint32_t)(raw_value & UINT32_MAX);
2337  success = true;
2338  break;
2339 
2340  case sizeof(uint16_t):
2341  if (is_signed)
2342  value.GetScalar() = (int16_t)(raw_value & UINT16_MAX);
2343  else
2344  value.GetScalar() = (uint16_t)(raw_value & UINT16_MAX);
2345  success = true;
2346  break;
2347 
2348  case sizeof(uint8_t):
2349  if (is_signed)
2350  value.GetScalar() = (int8_t)(raw_value & UINT8_MAX);
2351  else
2352  value.GetScalar() = (uint8_t)(raw_value & UINT8_MAX);
2353  success = true;
2354  break;
2355  }
2356  }
2357  }
2358  } else if (type_flags & eTypeIsFloat) {
2359  if (type_flags & eTypeIsComplex) {
2360  // Don't handle complex yet.
2361  } else {
2362  if (*byte_size <= sizeof(long double)) {
2363  const RegisterInfo *v0_reg_info =
2364  reg_ctx->GetRegisterInfoByName("v0", 0);
2365  RegisterValue v0_value;
2366  if (reg_ctx->ReadRegister(v0_reg_info, v0_value)) {
2367  DataExtractor data;
2368  if (v0_value.GetData(data)) {
2369  lldb::offset_t offset = 0;
2370  if (*byte_size == sizeof(float)) {
2371  value.GetScalar() = data.GetFloat(&offset);
2372  success = true;
2373  } else if (*byte_size == sizeof(double)) {
2374  value.GetScalar() = data.GetDouble(&offset);
2375  success = true;
2376  } else if (*byte_size == sizeof(long double)) {
2377  value.GetScalar() = data.GetLongDouble(&offset);
2378  success = true;
2379  }
2380  }
2381  }
2382  }
2383  }
2384  }
2385 
2386  if (success)
2387  return_valobj_sp = ValueObjectConstResult::Create(
2388  thread.GetStackFrameAtIndex(0).get(), value, ConstString(""));
2389  } else if (type_flags & eTypeIsVector) {
2390  if (*byte_size > 0) {
2391 
2392  const RegisterInfo *v0_info = reg_ctx->GetRegisterInfoByName("v0", 0);
2393 
2394  if (v0_info) {
2395  if (*byte_size <= v0_info->byte_size) {
2396  std::unique_ptr<DataBufferHeap> heap_data_up(
2397  new DataBufferHeap(*byte_size, 0));
2398  const ByteOrder byte_order = exe_ctx.GetProcessRef().GetByteOrder();
2399  RegisterValue reg_value;
2400  if (reg_ctx->ReadRegister(v0_info, reg_value)) {
2401  Status error;
2402  if (reg_value.GetAsMemoryData(v0_info, heap_data_up->GetBytes(),
2403  heap_data_up->GetByteSize(),
2404  byte_order, error)) {
2405  DataExtractor data(DataBufferSP(heap_data_up.release()),
2406  byte_order,
2407  exe_ctx.GetProcessRef().GetAddressByteSize());
2408  return_valobj_sp = ValueObjectConstResult::Create(
2409  &thread, return_compiler_type, ConstString(""), data);
2410  }
2411  }
2412  }
2413  }
2414  }
2415  } else if (type_flags & eTypeIsStructUnion || type_flags & eTypeIsClass) {
2416  DataExtractor data;
2417 
2418  uint32_t NGRN = 0; // Search ABI docs for NGRN
2419  uint32_t NSRN = 0; // Search ABI docs for NSRN
2420  const bool is_return_value = true;
2422  exe_ctx, reg_ctx, return_compiler_type, is_return_value, NGRN, NSRN,
2423  data)) {
2424  return_valobj_sp = ValueObjectConstResult::Create(
2425  &thread, return_compiler_type, ConstString(""), data);
2426  }
2427  }
2428  return return_valobj_sp;
2429 }
2430 
2432  PluginManager::RegisterPlugin(GetPluginNameStatic(), pluginDesc,
2433  CreateInstance);
2434 }
2435 
2437  PluginManager::UnregisterPlugin(CreateInstance);
2438 }
2439 
2440 // PluginInterface protocol
2441 
2443  static ConstString g_plugin_name("ABIMacOSX_arm64");
2444  return g_plugin_name;
2445 }
2446 
size_t PutCString(llvm::StringRef cstr)
Output a C string to the stream.
Definition: Stream.cpp:61
#define LLDB_REGNUM_GENERIC_PC
Definition: lldb-defines.h:63
An data extractor class.
Definition: DataExtractor.h:47
#define LLDB_REGNUM_GENERIC_ARG6
Definition: lldb-defines.h:78
void SetSourceName(const char *)
Definition: UnwindPlan.cpp:542
Enumerations for broadcasting.
Definition: SBLaunchInfo.h:14
bool IsPointerOrReferenceType(CompilerType *pointee_type=nullptr) const
bool CreateDefaultUnwindPlan(lldb_private::UnwindPlan &unwind_plan) override
static void Initialize()
bool CreateFunctionEntryUnwindPlan(lldb_private::UnwindPlan &unwind_plan) override
#define LLDB_REGNUM_GENERIC_RA
Definition: lldb-defines.h:66
uint64_t ReadRegisterAsUnsigned(uint32_t reg, uint64_t fail_value)
#define LLDB_REGNUM_GENERIC_ARG4
Definition: lldb-defines.h:74
uint32_t GetAsMemoryData(const RegisterInfo *reg_info, void *dst, uint32_t dst_len, lldb::ByteOrder dst_byte_order, Status &error) const
bool IsIntegerOrEnumerationType(bool &is_signed) const
bool RegisterIsVolatile(const lldb_private::RegisterInfo *reg_info) override
void PutString(llvm::StringRef str)
Definition: Log.cpp:110
lldb::user_id_t GetID() const
Get accessor for the user ID.
Definition: UserID.h:49
lldb::ValueObjectSP GetReturnValueObjectImpl(lldb_private::Thread &thread, lldb_private::CompilerType &ast_type) const override
virtual uint32_t ConvertRegisterKindToRegisterNumber(lldb::RegisterKind kind, uint32_t num)=0
Convert from a given register numbering scheme to the lldb register numbering scheme.
An architecture specification class.
Definition: ArchSpec.h:32
uint32_t IsHomogeneousAggregate(CompilerType *base_type_ptr) const
#define LLDB_REGNUM_GENERIC_ARG2
Definition: lldb-defines.h:70
size_t GetRedZoneSize() const override
virtual bool WriteRegister(const RegisterInfo *reg_info, const RegisterValue &reg_value)=0
uint32_t GetTypeInfo(CompilerType *pointee_or_element_compiler_type=nullptr) const
Value * GetValueAtIndex(size_t idx)
Definition: Value.cpp:701
void SetValueType(ValueType value_type)
Definition: Value.h:154
"lldb/Target/ExecutionContext.h" A class that contains an execution context.
void SetAddressByteSize(uint32_t addr_size)
Set the address byte size.
lldb::ByteOrder GetByteOrder() const
Definition: Process.cpp:3366
#define LLDB_REGNUM_GENERIC_SP
Definition: lldb-defines.h:64
#define LLDB_REGNUM_GENERIC_ARG7
Definition: lldb-defines.h:80
llvm::Optional< uint64_t > GetByteSize(ExecutionContextScope *exe_scope) const
Return the size of the type in bytes.
#define LLDB_REGNUM_GENERIC_ARG5
Definition: lldb-defines.h:76
float GetFloat(lldb::offset_t *offset_ptr) const
Extract a float from *offset_ptr.
static lldb_private::ConstString GetPluginNameStatic()
A subclass of DataBuffer that stores a data buffer on the heap.
#define LLDB_REGNUM_GENERIC_ARG1
Definition: lldb-defines.h:68
static lldb::ABISP CreateInstance(lldb::ProcessSP process_sp, const lldb_private::ArchSpec &arch)
llvm::Triple & GetTriple()
Architecture triple accessor.
Definition: ArchSpec.h:431
static const uint32_t k_num_register_infos
static const char * pluginDesc
long double GetLongDouble(lldb::offset_t *offset_ptr) const
#define LLDB_REGNUM_GENERIC_FP
Definition: lldb-defines.h:65
#define UINT32_MAX
Definition: lldb-defines.h:31
const lldb_private::RegisterInfo * GetRegisterInfoArray(uint32_t &count) override
#define LLDB_INVALID_ADDRESS
Invalid value definitions.
Definition: lldb-defines.h:85
lldb::offset_t SetData(const void *bytes, lldb::offset_t length, lldb::ByteOrder byte_order)
Set data with a buffer that is caller owned.
uint64_t offset_t
Definition: lldb-types.h:87
Log * GetLogIfAllCategoriesSet(uint32_t mask)
Definition: Logging.cpp:57
std::shared_ptr< Row > RowSP
Definition: UnwindPlan.h:366
void AppendRow(const RowSP &row_sp)
Definition: UnwindPlan.cpp:355
uint32_t GetAddressByteSize() const
Definition: Process.cpp:3370
llvm::StringRef GetString() const
virtual lldb::RegisterContextSP GetRegisterContext()=0
static void Terminate()
void SetErrorString(llvm::StringRef err_str)
Set the current error string to err_str.
Definition: Status.cpp:241
virtual const RegisterInfo * GetRegisterInfoAtIndex(size_t reg)=0
virtual bool ReadRegister(const RegisterInfo *reg_info, RegisterValue &reg_value)=0
Status SetValueFromData(const RegisterInfo *reg_info, DataExtractor &data, lldb::offset_t offset, bool partial_data_ok)
double GetDouble(lldb::offset_t *offset_ptr) const
#define LLDB_REGNUM_GENERIC_FLAGS
Definition: lldb-defines.h:67
static bool LoadValueFromConsecutiveGPRRegisters(ExecutionContext &exe_ctx, RegisterContext *reg_ctx, const CompilerType &value_type, bool is_return_value, uint32_t &NGRN, uint32_t &NSRN, DataExtractor &data)
const RegisterInfo * GetRegisterInfoByName(llvm::StringRef reg_name, uint32_t start_idx=0)
size_t Printf(const char *format,...) __attribute__((format(printf
Output printf formatted output to the stream.
Definition: Stream.cpp:106
bool Success() const
Test for success condition.
Definition: Status.cpp:287
const CompilerType & GetCompilerType()
Definition: Value.cpp:239
void SetRegisterKind(lldb::RegisterKind kind)
Definition: UnwindPlan.h:408
bool WriteRegisterFromUnsigned(uint32_t reg, uint64_t uval)
uint64_t GetMaxU64(lldb::offset_t *offset_ptr, size_t byte_size) const
Extract an unsigned integer of size byte_size from *offset_ptr.
bool GetArgumentValues(lldb_private::Thread &thread, lldb_private::ValueList &values) const override
const RegisterInfo * GetRegisterInfo(lldb::RegisterKind reg_kind, uint32_t reg_num)
uint32_t GetPluginVersion() override
void SetUnwindPlanValidAtAllInstructions(lldb_private::LazyBool valid_at_all_insn)
Definition: UnwindPlan.h:461
uint64_t addr_t
Definition: lldb-types.h:83
bool GetData(DataExtractor &data) const
A uniqued constant string class.
Definition: ConstString.h:38
bool Fail() const
Test for error condition.
Definition: Status.cpp:181
#define LLDB_REGNUM_GENERIC_ARG8
Definition: lldb-defines.h:82
const char * GetCString() const
Get the string value as a C string.
Definition: ConstString.h:247
llvm::Optional< uint64_t > GetBitSize(ExecutionContextScope *exe_scope) const
Return the size of the type in bits.
#define LLDB_REGNUM_GENERIC_ARG3
Definition: lldb-defines.h:72
Definition: SBAddress.h:15
bool GetScalarValue(Scalar &scalar) const
int SetErrorStringWithFormat(const char *format,...) __attribute__((format(printf
Set the current error string to a formatted error string.
Definition: Status.cpp:255
void SetCompilerType(const CompilerType &compiler_type)
Definition: Value.cpp:268
static bool g_register_info_names_constified
#define LIBLLDB_LOG_EXPRESSIONS
Definition: Logging.h:22
bool SignExtend(uint32_t sign_bitpos)
const Scalar & GetScalar() const
Definition: Value.h:178
const char * AsCString(const char *default_error_str="unknown error") const
Get the error string associated with the current error.
Definition: Status.cpp:130
bool PrepareTrivialCall(lldb_private::Thread &thread, lldb::addr_t sp, lldb::addr_t functionAddress, lldb::addr_t returnAddress, llvm::ArrayRef< lldb::addr_t > args) const override
virtual lldb::StackFrameSP GetStackFrameAtIndex(uint32_t idx)
Definition: Thread.h:395
Process & GetProcessRef() const
Returns a reference to the process object.
void Printf(const char *format,...) __attribute__((format(printf
Definition: Log.cpp:113
void SetSourcedFromCompiler(lldb_private::LazyBool from_compiler)
Definition: UnwindPlan.h:449
lldb_private::Status SetReturnValueObject(lldb::StackFrameSP &frame_sp, lldb::ValueObjectSP &new_value) override
static RegisterInfo g_register_infos[]
An error handling class.
Definition: Status.h:44
void SetByteOrder(lldb::ByteOrder byte_order)
Set the byte_order value.
#define LLDB_INVALID_REGNUM
Definition: lldb-defines.h:90
virtual size_t ReadMemory(lldb::addr_t vm_addr, void *buf, size_t size, Status &error)
Read of memory from a process.
Definition: Process.cpp:1966