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