LLDB  mainline
ABISysV_x86_64.cpp
Go to the documentation of this file.
1 //===-- ABISysV_x86_64.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_x86_64.h"
10 
11 #include "llvm/ADT/STLExtras.h"
12 #include "llvm/ADT/StringSwitch.h"
13 #include "llvm/ADT/Triple.h"
14 
15 #include "lldb/Core/Module.h"
17 #include "lldb/Core/Value.h"
21 #include "lldb/Symbol/UnwindPlan.h"
22 #include "lldb/Target/Process.h"
24 #include "lldb/Target/StackFrame.h"
25 #include "lldb/Target/Target.h"
26 #include "lldb/Target/Thread.h"
29 #include "lldb/Utility/Log.h"
31 #include "lldb/Utility/Status.h"
32 
33 using namespace lldb;
34 using namespace lldb_private;
35 
37  dwarf_rax = 0,
94  dwarf_bnd0 = 126,
98 };
99 
100 static RegisterInfo g_register_infos[] = {
101  // NAME ALT SZ OFF ENCODING FORMAT EH_FRAME
102  // DWARF GENERIC PROCESS PLUGIN
103  // LLDB NATIVE
104  // ======== ======= == === ============= ===================
105  // ======================= =====================
106  // =========================== ===================== ======================
107  {"rax",
108  nullptr,
109  8,
110  0,
112  eFormatHex,
114  LLDB_INVALID_REGNUM},
115  nullptr,
116  nullptr,
117  nullptr,
118  0},
119  {"rbx",
120  nullptr,
121  8,
122  0,
124  eFormatHex,
126  LLDB_INVALID_REGNUM},
127  nullptr,
128  nullptr,
129  nullptr,
130  0},
131  {"rcx",
132  "arg4",
133  8,
134  0,
136  eFormatHex,
138  LLDB_INVALID_REGNUM},
139  nullptr,
140  nullptr,
141  nullptr,
142  0},
143  {"rdx",
144  "arg3",
145  8,
146  0,
148  eFormatHex,
150  LLDB_INVALID_REGNUM},
151  nullptr,
152  nullptr,
153  nullptr,
154  0},
155  {"rsi",
156  "arg2",
157  8,
158  0,
160  eFormatHex,
162  LLDB_INVALID_REGNUM},
163  nullptr,
164  nullptr,
165  nullptr,
166  0},
167  {"rdi",
168  "arg1",
169  8,
170  0,
172  eFormatHex,
174  LLDB_INVALID_REGNUM},
175  nullptr,
176  nullptr,
177  nullptr,
178  0},
179  {"rbp",
180  "fp",
181  8,
182  0,
184  eFormatHex,
186  LLDB_INVALID_REGNUM},
187  nullptr,
188  nullptr,
189  nullptr,
190  0},
191  {"rsp",
192  "sp",
193  8,
194  0,
196  eFormatHex,
198  LLDB_INVALID_REGNUM},
199  nullptr,
200  nullptr,
201  nullptr,
202  0},
203  {"r8",
204  "arg5",
205  8,
206  0,
208  eFormatHex,
210  LLDB_INVALID_REGNUM},
211  nullptr,
212  nullptr,
213  nullptr,
214  0},
215  {"r9",
216  "arg6",
217  8,
218  0,
220  eFormatHex,
222  LLDB_INVALID_REGNUM},
223  nullptr,
224  nullptr,
225  nullptr,
226  0},
227  {"r10",
228  nullptr,
229  8,
230  0,
232  eFormatHex,
234  LLDB_INVALID_REGNUM},
235  nullptr,
236  nullptr,
237  nullptr,
238  0},
239  {"r11",
240  nullptr,
241  8,
242  0,
244  eFormatHex,
246  LLDB_INVALID_REGNUM},
247  nullptr,
248  nullptr,
249  nullptr,
250  0},
251  {"r12",
252  nullptr,
253  8,
254  0,
256  eFormatHex,
258  LLDB_INVALID_REGNUM},
259  nullptr,
260  nullptr,
261  nullptr,
262  0},
263  {"r13",
264  nullptr,
265  8,
266  0,
268  eFormatHex,
270  LLDB_INVALID_REGNUM},
271  nullptr,
272  nullptr,
273  nullptr,
274  0},
275  {"r14",
276  nullptr,
277  8,
278  0,
280  eFormatHex,
282  LLDB_INVALID_REGNUM},
283  nullptr,
284  nullptr,
285  nullptr,
286  0},
287  {"r15",
288  nullptr,
289  8,
290  0,
292  eFormatHex,
294  LLDB_INVALID_REGNUM},
295  nullptr,
296  nullptr,
297  nullptr,
298  0},
299  {"rip",
300  "pc",
301  8,
302  0,
304  eFormatHex,
306  LLDB_INVALID_REGNUM},
307  nullptr,
308  nullptr,
309  nullptr,
310  0},
311  {"rflags",
312  nullptr,
313  4,
314  0,
316  eFormatHex,
318  LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM},
319  nullptr,
320  nullptr,
321  nullptr,
322  0},
323  {"cs",
324  nullptr,
325  4,
326  0,
328  eFormatHex,
330  LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM},
331  nullptr,
332  nullptr,
333  nullptr,
334  0},
335  {"ss",
336  nullptr,
337  4,
338  0,
340  eFormatHex,
342  LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM},
343  nullptr,
344  nullptr,
345  nullptr,
346  0},
347  {"ds",
348  nullptr,
349  4,
350  0,
352  eFormatHex,
354  LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM},
355  nullptr,
356  nullptr,
357  nullptr,
358  0},
359  {"es",
360  nullptr,
361  4,
362  0,
364  eFormatHex,
366  LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM},
367  nullptr,
368  nullptr,
369  nullptr,
370  0},
371  {"fs",
372  nullptr,
373  4,
374  0,
376  eFormatHex,
378  LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM},
379  nullptr,
380  nullptr,
381  nullptr,
382  0},
383  {"gs",
384  nullptr,
385  4,
386  0,
388  eFormatHex,
390  LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM},
391  nullptr,
392  nullptr,
393  nullptr,
394  0},
395  {"stmm0",
396  nullptr,
397  10,
398  0,
402  LLDB_INVALID_REGNUM},
403  nullptr,
404  nullptr,
405  nullptr,
406  0},
407  {"stmm1",
408  nullptr,
409  10,
410  0,
414  LLDB_INVALID_REGNUM},
415  nullptr,
416  nullptr,
417  nullptr,
418  0},
419  {"stmm2",
420  nullptr,
421  10,
422  0,
426  LLDB_INVALID_REGNUM},
427  nullptr,
428  nullptr,
429  nullptr,
430  0},
431  {"stmm3",
432  nullptr,
433  10,
434  0,
438  LLDB_INVALID_REGNUM},
439  nullptr,
440  nullptr,
441  nullptr,
442  0},
443  {"stmm4",
444  nullptr,
445  10,
446  0,
450  LLDB_INVALID_REGNUM},
451  nullptr,
452  nullptr,
453  nullptr,
454  0},
455  {"stmm5",
456  nullptr,
457  10,
458  0,
462  LLDB_INVALID_REGNUM},
463  nullptr,
464  nullptr,
465  nullptr,
466  0},
467  {"stmm6",
468  nullptr,
469  10,
470  0,
474  LLDB_INVALID_REGNUM},
475  nullptr,
476  nullptr,
477  nullptr,
478  0},
479  {"stmm7",
480  nullptr,
481  10,
482  0,
486  LLDB_INVALID_REGNUM},
487  nullptr,
488  nullptr,
489  nullptr,
490  0},
491  {"fctrl",
492  nullptr,
493  4,
494  0,
496  eFormatHex,
498  LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM},
499  nullptr,
500  nullptr,
501  nullptr,
502  0},
503  {"fstat",
504  nullptr,
505  4,
506  0,
508  eFormatHex,
510  LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM},
511  nullptr,
512  nullptr,
513  nullptr,
514  0},
515  {"ftag",
516  nullptr,
517  4,
518  0,
520  eFormatHex,
522  LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM},
523  nullptr,
524  nullptr,
525  nullptr,
526  0},
527  {"fiseg",
528  nullptr,
529  4,
530  0,
532  eFormatHex,
534  LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM},
535  nullptr,
536  nullptr,
537  nullptr,
538  0},
539  {"fioff",
540  nullptr,
541  4,
542  0,
544  eFormatHex,
546  LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM},
547  nullptr,
548  nullptr,
549  nullptr,
550  0},
551  {"foseg",
552  nullptr,
553  4,
554  0,
556  eFormatHex,
558  LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM},
559  nullptr,
560  nullptr,
561  nullptr,
562  0},
563  {"fooff",
564  nullptr,
565  4,
566  0,
568  eFormatHex,
570  LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM},
571  nullptr,
572  nullptr,
573  nullptr,
574  0},
575  {"fop",
576  nullptr,
577  4,
578  0,
580  eFormatHex,
582  LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM},
583  nullptr,
584  nullptr,
585  nullptr,
586  0},
587  {"xmm0",
588  nullptr,
589  16,
590  0,
594  LLDB_INVALID_REGNUM},
595  nullptr,
596  nullptr,
597  nullptr,
598  0},
599  {"xmm1",
600  nullptr,
601  16,
602  0,
606  LLDB_INVALID_REGNUM},
607  nullptr,
608  nullptr,
609  nullptr,
610  0},
611  {"xmm2",
612  nullptr,
613  16,
614  0,
618  LLDB_INVALID_REGNUM},
619  nullptr,
620  nullptr,
621  nullptr,
622  0},
623  {"xmm3",
624  nullptr,
625  16,
626  0,
630  LLDB_INVALID_REGNUM},
631  nullptr,
632  nullptr,
633  nullptr,
634  0},
635  {"xmm4",
636  nullptr,
637  16,
638  0,
642  LLDB_INVALID_REGNUM},
643  nullptr,
644  nullptr,
645  nullptr,
646  0},
647  {"xmm5",
648  nullptr,
649  16,
650  0,
654  LLDB_INVALID_REGNUM},
655  nullptr,
656  nullptr,
657  nullptr,
658  0},
659  {"xmm6",
660  nullptr,
661  16,
662  0,
666  LLDB_INVALID_REGNUM},
667  nullptr,
668  nullptr,
669  nullptr,
670  0},
671  {"xmm7",
672  nullptr,
673  16,
674  0,
678  LLDB_INVALID_REGNUM},
679  nullptr,
680  nullptr,
681  nullptr,
682  0},
683  {"xmm8",
684  nullptr,
685  16,
686  0,
690  LLDB_INVALID_REGNUM},
691  nullptr,
692  nullptr,
693  nullptr,
694  0},
695  {"xmm9",
696  nullptr,
697  16,
698  0,
702  LLDB_INVALID_REGNUM},
703  nullptr,
704  nullptr,
705  nullptr,
706  0},
707  {"xmm10",
708  nullptr,
709  16,
710  0,
714  LLDB_INVALID_REGNUM},
715  nullptr,
716  nullptr,
717  nullptr,
718  0},
719  {"xmm11",
720  nullptr,
721  16,
722  0,
726  LLDB_INVALID_REGNUM},
727  nullptr,
728  nullptr,
729  nullptr,
730  0},
731  {"xmm12",
732  nullptr,
733  16,
734  0,
738  LLDB_INVALID_REGNUM},
739  nullptr,
740  nullptr,
741  nullptr,
742  0},
743  {"xmm13",
744  nullptr,
745  16,
746  0,
750  LLDB_INVALID_REGNUM},
751  nullptr,
752  nullptr,
753  nullptr,
754  0},
755  {"xmm14",
756  nullptr,
757  16,
758  0,
762  LLDB_INVALID_REGNUM},
763  nullptr,
764  nullptr,
765  nullptr,
766  0},
767  {"xmm15",
768  nullptr,
769  16,
770  0,
774  LLDB_INVALID_REGNUM},
775  nullptr,
776  nullptr,
777  nullptr,
778  0},
779  {"mxcsr",
780  nullptr,
781  4,
782  0,
784  eFormatHex,
786  LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM},
787  nullptr,
788  nullptr,
789  nullptr,
790  0},
791  {"ymm0",
792  nullptr,
793  32,
794  0,
798  LLDB_INVALID_REGNUM},
799  nullptr,
800  nullptr,
801  nullptr,
802  0},
803  {"ymm1",
804  nullptr,
805  32,
806  0,
810  LLDB_INVALID_REGNUM},
811  nullptr,
812  nullptr,
813  nullptr,
814  0},
815  {"ymm2",
816  nullptr,
817  32,
818  0,
822  LLDB_INVALID_REGNUM},
823  nullptr,
824  nullptr,
825  nullptr,
826  0},
827  {"ymm3",
828  nullptr,
829  32,
830  0,
834  LLDB_INVALID_REGNUM},
835  nullptr,
836  nullptr,
837  nullptr,
838  0},
839  {"ymm4",
840  nullptr,
841  32,
842  0,
846  LLDB_INVALID_REGNUM},
847  nullptr,
848  nullptr,
849  nullptr,
850  0},
851  {"ymm5",
852  nullptr,
853  32,
854  0,
858  LLDB_INVALID_REGNUM},
859  nullptr,
860  nullptr,
861  nullptr,
862  0},
863  {"ymm6",
864  nullptr,
865  32,
866  0,
870  LLDB_INVALID_REGNUM},
871  nullptr,
872  nullptr,
873  nullptr,
874  0},
875  {"ymm7",
876  nullptr,
877  32,
878  0,
882  LLDB_INVALID_REGNUM},
883  nullptr,
884  nullptr,
885  nullptr,
886  0},
887  {"ymm8",
888  nullptr,
889  32,
890  0,
894  LLDB_INVALID_REGNUM},
895  nullptr,
896  nullptr,
897  nullptr,
898  0},
899  {"ymm9",
900  nullptr,
901  32,
902  0,
906  LLDB_INVALID_REGNUM},
907  nullptr,
908  nullptr,
909  nullptr,
910  0},
911  {"ymm10",
912  nullptr,
913  32,
914  0,
918  LLDB_INVALID_REGNUM},
919  nullptr,
920  nullptr,
921  nullptr,
922  0},
923  {"ymm11",
924  nullptr,
925  32,
926  0,
930  LLDB_INVALID_REGNUM},
931  nullptr,
932  nullptr,
933  nullptr,
934  0},
935  {"ymm12",
936  nullptr,
937  32,
938  0,
942  LLDB_INVALID_REGNUM},
943  nullptr,
944  nullptr,
945  nullptr,
946  0},
947  {"ymm13",
948  nullptr,
949  32,
950  0,
954  LLDB_INVALID_REGNUM},
955  nullptr,
956  nullptr,
957  nullptr,
958  0},
959  {"ymm14",
960  nullptr,
961  32,
962  0,
966  LLDB_INVALID_REGNUM},
967  nullptr,
968  nullptr,
969  nullptr,
970  0},
971  {"ymm15",
972  nullptr,
973  32,
974  0,
978  LLDB_INVALID_REGNUM},
979  nullptr,
980  nullptr,
981  nullptr,
982  0},
983  {"bnd0",
984  nullptr,
985  16,
986  0,
990  LLDB_INVALID_REGNUM},
991  nullptr,
992  nullptr,
993  nullptr,
994  0},
995  {"bnd1",
996  nullptr,
997  16,
998  0,
1002  LLDB_INVALID_REGNUM},
1003  nullptr,
1004  nullptr,
1005  nullptr,
1006  0},
1007  {"bnd2",
1008  nullptr,
1009  16,
1010  0,
1014  LLDB_INVALID_REGNUM},
1015  nullptr,
1016  nullptr,
1017  nullptr,
1018  0},
1019  {"bnd3",
1020  nullptr,
1021  16,
1022  0,
1026  LLDB_INVALID_REGNUM},
1027  nullptr,
1028  nullptr,
1029  nullptr,
1030  0},
1031  {"bndcfgu",
1032  nullptr,
1033  8,
1034  0,
1038  LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM},
1039  nullptr,
1040  nullptr,
1041  nullptr,
1042  0},
1043  {"bndstatus",
1044  nullptr,
1045  8,
1046  0,
1050  LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM},
1051  nullptr,
1052  nullptr,
1053  nullptr,
1054  0}};
1055 
1057  llvm::array_lengthof(g_register_infos);
1059 
1060 const lldb_private::RegisterInfo *
1062  // Make the C-string names and alt_names for the register infos into const
1063  // C-string values by having the ConstString unique the names in the global
1064  // constant C-string pool.
1067  for (uint32_t i = 0; i < k_num_register_infos; ++i) {
1068  if (g_register_infos[i].name)
1069  g_register_infos[i].name =
1071  if (g_register_infos[i].alt_name)
1072  g_register_infos[i].alt_name =
1073  ConstString(g_register_infos[i].alt_name).GetCString();
1074  }
1075  }
1076  count = k_num_register_infos;
1077  return g_register_infos;
1078 }
1079 
1081  name = "rax";
1082  return true;
1083 }
1084 
1085 size_t ABISysV_x86_64::GetRedZoneSize() const { return 128; }
1086 
1087 // Static Functions
1088 
1089 ABISP
1090 ABISysV_x86_64::CreateInstance(lldb::ProcessSP process_sp, const ArchSpec &arch) {
1091  if (arch.GetTriple().getArch() == llvm::Triple::x86_64) {
1092  return ABISP(new ABISysV_x86_64(process_sp));
1093  }
1094  return ABISP();
1095 }
1096 
1098  addr_t func_addr, addr_t return_addr,
1099  llvm::ArrayRef<addr_t> args) const {
1101 
1102  if (log) {
1103  StreamString s;
1104  s.Printf("ABISysV_x86_64::PrepareTrivialCall (tid = 0x%" PRIx64
1105  ", sp = 0x%" PRIx64 ", func_addr = 0x%" PRIx64
1106  ", return_addr = 0x%" PRIx64,
1107  thread.GetID(), (uint64_t)sp, (uint64_t)func_addr,
1108  (uint64_t)return_addr);
1109 
1110  for (size_t i = 0; i < args.size(); ++i)
1111  s.Printf(", arg%" PRIu64 " = 0x%" PRIx64, static_cast<uint64_t>(i + 1),
1112  args[i]);
1113  s.PutCString(")");
1114  log->PutString(s.GetString());
1115  }
1116 
1117  RegisterContext *reg_ctx = thread.GetRegisterContext().get();
1118  if (!reg_ctx)
1119  return false;
1120 
1121  const RegisterInfo *reg_info = nullptr;
1122 
1123  if (args.size() > 6) // TODO handle more than 6 arguments
1124  return false;
1125 
1126  for (size_t i = 0; i < args.size(); ++i) {
1127  reg_info = reg_ctx->GetRegisterInfo(eRegisterKindGeneric,
1129  if (log)
1130  log->Printf("About to write arg%" PRIu64 " (0x%" PRIx64 ") into %s",
1131  static_cast<uint64_t>(i + 1), args[i], reg_info->name);
1132  if (!reg_ctx->WriteRegisterFromUnsigned(reg_info, args[i]))
1133  return false;
1134  }
1135 
1136  // First, align the SP
1137 
1138  if (log)
1139  log->Printf("16-byte aligning SP: 0x%" PRIx64 " to 0x%" PRIx64,
1140  (uint64_t)sp, (uint64_t)(sp & ~0xfull));
1141 
1142  sp &= ~(0xfull); // 16-byte alignment
1143 
1144  sp -= 8;
1145 
1146  Status error;
1147  const RegisterInfo *pc_reg_info =
1149  const RegisterInfo *sp_reg_info =
1151  ProcessSP process_sp(thread.GetProcess());
1152 
1153  RegisterValue reg_value;
1154  if (log)
1155  log->Printf("Pushing the return address onto the stack: 0x%" PRIx64
1156  ": 0x%" PRIx64,
1157  (uint64_t)sp, (uint64_t)return_addr);
1158 
1159  // Save return address onto the stack
1160  if (!process_sp->WritePointerToMemory(sp, return_addr, error))
1161  return false;
1162 
1163  // %rsp is set to the actual stack value.
1164 
1165  if (log)
1166  log->Printf("Writing SP: 0x%" PRIx64, (uint64_t)sp);
1167 
1168  if (!reg_ctx->WriteRegisterFromUnsigned(sp_reg_info, sp))
1169  return false;
1170 
1171  // %rip is set to the address of the called function.
1172 
1173  if (log)
1174  log->Printf("Writing IP: 0x%" PRIx64, (uint64_t)func_addr);
1175 
1176  if (!reg_ctx->WriteRegisterFromUnsigned(pc_reg_info, func_addr))
1177  return false;
1178 
1179  return true;
1180 }
1181 
1182 static bool ReadIntegerArgument(Scalar &scalar, unsigned int bit_width,
1183  bool is_signed, Thread &thread,
1184  uint32_t *argument_register_ids,
1185  unsigned int &current_argument_register,
1186  addr_t &current_stack_argument) {
1187  if (bit_width > 64)
1188  return false; // Scalar can't hold large integer arguments
1189 
1190  if (current_argument_register < 6) {
1191  scalar = thread.GetRegisterContext()->ReadRegisterAsUnsigned(
1192  argument_register_ids[current_argument_register], 0);
1193  current_argument_register++;
1194  if (is_signed)
1195  scalar.SignExtend(bit_width);
1196  } else {
1197  uint32_t byte_size = (bit_width + (8 - 1)) / 8;
1198  Status error;
1199  if (thread.GetProcess()->ReadScalarIntegerFromMemory(
1200  current_stack_argument, byte_size, is_signed, scalar, error)) {
1201  current_stack_argument += byte_size;
1202  return true;
1203  }
1204  return false;
1205  }
1206  return true;
1207 }
1208 
1210  ValueList &values) const {
1211  unsigned int num_values = values.GetSize();
1212  unsigned int value_index;
1213 
1214  // Extract the register context so we can read arguments from registers
1215 
1216  RegisterContext *reg_ctx = thread.GetRegisterContext().get();
1217 
1218  if (!reg_ctx)
1219  return false;
1220 
1221  // Get the pointer to the first stack argument so we have a place to start
1222  // when reading data
1223 
1224  addr_t sp = reg_ctx->GetSP(0);
1225 
1226  if (!sp)
1227  return false;
1228 
1229  addr_t current_stack_argument = sp + 8; // jump over return address
1230 
1231  uint32_t argument_register_ids[6];
1232 
1233  argument_register_ids[0] =
1235  ->kinds[eRegisterKindLLDB];
1236  argument_register_ids[1] =
1238  ->kinds[eRegisterKindLLDB];
1239  argument_register_ids[2] =
1241  ->kinds[eRegisterKindLLDB];
1242  argument_register_ids[3] =
1244  ->kinds[eRegisterKindLLDB];
1245  argument_register_ids[4] =
1247  ->kinds[eRegisterKindLLDB];
1248  argument_register_ids[5] =
1250  ->kinds[eRegisterKindLLDB];
1251 
1252  unsigned int current_argument_register = 0;
1253 
1254  for (value_index = 0; value_index < num_values; ++value_index) {
1255  Value *value = values.GetValueAtIndex(value_index);
1256 
1257  if (!value)
1258  return false;
1259 
1260  // We currently only support extracting values with Clang QualTypes. Do we
1261  // care about others?
1262  CompilerType compiler_type = value->GetCompilerType();
1263  llvm::Optional<uint64_t> bit_size = compiler_type.GetBitSize(&thread);
1264  if (!bit_size)
1265  return false;
1266  bool is_signed;
1267 
1268  if (compiler_type.IsIntegerOrEnumerationType(is_signed)) {
1269  ReadIntegerArgument(value->GetScalar(), *bit_size, is_signed, thread,
1270  argument_register_ids, current_argument_register,
1271  current_stack_argument);
1272  } else if (compiler_type.IsPointerType()) {
1273  ReadIntegerArgument(value->GetScalar(), *bit_size, false, thread,
1274  argument_register_ids, current_argument_register,
1275  current_stack_argument);
1276  }
1277  }
1278 
1279  return true;
1280 }
1281 
1282 Status ABISysV_x86_64::SetReturnValueObject(lldb::StackFrameSP &frame_sp,
1283  lldb::ValueObjectSP &new_value_sp) {
1284  Status error;
1285  if (!new_value_sp) {
1286  error.SetErrorString("Empty value object for return value.");
1287  return error;
1288  }
1289 
1290  CompilerType compiler_type = new_value_sp->GetCompilerType();
1291  if (!compiler_type) {
1292  error.SetErrorString("Null clang type for return value.");
1293  return error;
1294  }
1295 
1296  Thread *thread = frame_sp->GetThread().get();
1297 
1298  bool is_signed;
1299  uint32_t count;
1300  bool is_complex;
1301 
1302  RegisterContext *reg_ctx = thread->GetRegisterContext().get();
1303 
1304  bool set_it_simple = false;
1305  if (compiler_type.IsIntegerOrEnumerationType(is_signed) ||
1306  compiler_type.IsPointerType()) {
1307  const RegisterInfo *reg_info = reg_ctx->GetRegisterInfoByName("rax", 0);
1308 
1309  DataExtractor data;
1310  Status data_error;
1311  size_t num_bytes = new_value_sp->GetData(data, data_error);
1312  if (data_error.Fail()) {
1314  "Couldn't convert return value to raw data: %s",
1315  data_error.AsCString());
1316  return error;
1317  }
1318  lldb::offset_t offset = 0;
1319  if (num_bytes <= 8) {
1320  uint64_t raw_value = data.GetMaxU64(&offset, num_bytes);
1321 
1322  if (reg_ctx->WriteRegisterFromUnsigned(reg_info, raw_value))
1323  set_it_simple = true;
1324  } else {
1325  error.SetErrorString("We don't support returning longer than 64 bit "
1326  "integer values at present.");
1327  }
1328  } else if (compiler_type.IsFloatingPointType(count, is_complex)) {
1329  if (is_complex)
1330  error.SetErrorString(
1331  "We don't support returning complex values at present");
1332  else {
1333  llvm::Optional<uint64_t> bit_width =
1334  compiler_type.GetBitSize(frame_sp.get());
1335  if (!bit_width) {
1336  error.SetErrorString("can't get type size");
1337  return error;
1338  }
1339  if (*bit_width <= 64) {
1340  const RegisterInfo *xmm0_info =
1341  reg_ctx->GetRegisterInfoByName("xmm0", 0);
1342  RegisterValue xmm0_value;
1343  DataExtractor data;
1344  Status data_error;
1345  size_t num_bytes = new_value_sp->GetData(data, data_error);
1346  if (data_error.Fail()) {
1348  "Couldn't convert return value to raw data: %s",
1349  data_error.AsCString());
1350  return error;
1351  }
1352 
1353  unsigned char buffer[16];
1354  ByteOrder byte_order = data.GetByteOrder();
1355 
1356  data.CopyByteOrderedData(0, num_bytes, buffer, 16, byte_order);
1357  xmm0_value.SetBytes(buffer, 16, byte_order);
1358  reg_ctx->WriteRegister(xmm0_info, xmm0_value);
1359  set_it_simple = true;
1360  } else {
1361  // FIXME - don't know how to do 80 bit long doubles yet.
1362  error.SetErrorString(
1363  "We don't support returning float values > 64 bits at present");
1364  }
1365  }
1366  }
1367 
1368  if (!set_it_simple) {
1369  // Okay we've got a structure or something that doesn't fit in a simple
1370  // register. We should figure out where it really goes, but we don't
1371  // support this yet.
1372  error.SetErrorString("We only support setting simple integer and float "
1373  "return types at present.");
1374  }
1375 
1376  return error;
1377 }
1378 
1380  Thread &thread, CompilerType &return_compiler_type) const {
1381  ValueObjectSP return_valobj_sp;
1382  Value value;
1383 
1384  if (!return_compiler_type)
1385  return return_valobj_sp;
1386 
1387  // value.SetContext (Value::eContextTypeClangType, return_value_type);
1388  value.SetCompilerType(return_compiler_type);
1389 
1390  RegisterContext *reg_ctx = thread.GetRegisterContext().get();
1391  if (!reg_ctx)
1392  return return_valobj_sp;
1393 
1394  const uint32_t type_flags = return_compiler_type.GetTypeInfo();
1395  if (type_flags & eTypeIsScalar) {
1396  value.SetValueType(Value::eValueTypeScalar);
1397 
1398  bool success = false;
1399  if (type_flags & eTypeIsInteger) {
1400  // Extract the register context so we can read arguments from registers
1401 
1402  llvm::Optional<uint64_t> byte_size =
1403  return_compiler_type.GetByteSize(nullptr);
1404  if (!byte_size)
1405  return return_valobj_sp;
1406  uint64_t raw_value = thread.GetRegisterContext()->ReadRegisterAsUnsigned(
1407  reg_ctx->GetRegisterInfoByName("rax", 0), 0);
1408  const bool is_signed = (type_flags & eTypeIsSigned) != 0;
1409  switch (*byte_size) {
1410  default:
1411  break;
1412 
1413  case sizeof(uint64_t):
1414  if (is_signed)
1415  value.GetScalar() = (int64_t)(raw_value);
1416  else
1417  value.GetScalar() = (uint64_t)(raw_value);
1418  success = true;
1419  break;
1420 
1421  case sizeof(uint32_t):
1422  if (is_signed)
1423  value.GetScalar() = (int32_t)(raw_value & UINT32_MAX);
1424  else
1425  value.GetScalar() = (uint32_t)(raw_value & UINT32_MAX);
1426  success = true;
1427  break;
1428 
1429  case sizeof(uint16_t):
1430  if (is_signed)
1431  value.GetScalar() = (int16_t)(raw_value & UINT16_MAX);
1432  else
1433  value.GetScalar() = (uint16_t)(raw_value & UINT16_MAX);
1434  success = true;
1435  break;
1436 
1437  case sizeof(uint8_t):
1438  if (is_signed)
1439  value.GetScalar() = (int8_t)(raw_value & UINT8_MAX);
1440  else
1441  value.GetScalar() = (uint8_t)(raw_value & UINT8_MAX);
1442  success = true;
1443  break;
1444  }
1445  } else if (type_flags & eTypeIsFloat) {
1446  if (type_flags & eTypeIsComplex) {
1447  // Don't handle complex yet.
1448  } else {
1449  llvm::Optional<uint64_t> byte_size =
1450  return_compiler_type.GetByteSize(nullptr);
1451  if (byte_size && *byte_size <= sizeof(long double)) {
1452  const RegisterInfo *xmm0_info =
1453  reg_ctx->GetRegisterInfoByName("xmm0", 0);
1454  RegisterValue xmm0_value;
1455  if (reg_ctx->ReadRegister(xmm0_info, xmm0_value)) {
1456  DataExtractor data;
1457  if (xmm0_value.GetData(data)) {
1458  lldb::offset_t offset = 0;
1459  if (*byte_size == sizeof(float)) {
1460  value.GetScalar() = (float)data.GetFloat(&offset);
1461  success = true;
1462  } else if (*byte_size == sizeof(double)) {
1463  value.GetScalar() = (double)data.GetDouble(&offset);
1464  success = true;
1465  } else if (*byte_size == sizeof(long double)) {
1466  // Don't handle long double since that can be encoded as 80 bit
1467  // floats...
1468  }
1469  }
1470  }
1471  }
1472  }
1473  }
1474 
1475  if (success)
1476  return_valobj_sp = ValueObjectConstResult::Create(
1477  thread.GetStackFrameAtIndex(0).get(), value, ConstString(""));
1478  } else if (type_flags & eTypeIsPointer) {
1479  unsigned rax_id =
1480  reg_ctx->GetRegisterInfoByName("rax", 0)->kinds[eRegisterKindLLDB];
1481  value.GetScalar() =
1482  (uint64_t)thread.GetRegisterContext()->ReadRegisterAsUnsigned(rax_id,
1483  0);
1484  value.SetValueType(Value::eValueTypeScalar);
1485  return_valobj_sp = ValueObjectConstResult::Create(
1486  thread.GetStackFrameAtIndex(0).get(), value, ConstString(""));
1487  } else if (type_flags & eTypeIsVector) {
1488  llvm::Optional<uint64_t> byte_size =
1489  return_compiler_type.GetByteSize(nullptr);
1490  if (byte_size && *byte_size > 0) {
1491  const RegisterInfo *altivec_reg =
1492  reg_ctx->GetRegisterInfoByName("xmm0", 0);
1493  if (altivec_reg == nullptr)
1494  altivec_reg = reg_ctx->GetRegisterInfoByName("mm0", 0);
1495 
1496  if (altivec_reg) {
1497  if (*byte_size <= altivec_reg->byte_size) {
1498  ProcessSP process_sp(thread.GetProcess());
1499  if (process_sp) {
1500  std::unique_ptr<DataBufferHeap> heap_data_up(
1501  new DataBufferHeap(*byte_size, 0));
1502  const ByteOrder byte_order = process_sp->GetByteOrder();
1503  RegisterValue reg_value;
1504  if (reg_ctx->ReadRegister(altivec_reg, reg_value)) {
1505  Status error;
1506  if (reg_value.GetAsMemoryData(
1507  altivec_reg, heap_data_up->GetBytes(),
1508  heap_data_up->GetByteSize(), byte_order, error)) {
1509  DataExtractor data(DataBufferSP(heap_data_up.release()),
1510  byte_order,
1511  process_sp->GetTarget()
1512  .GetArchitecture()
1513  .GetAddressByteSize());
1514  return_valobj_sp = ValueObjectConstResult::Create(
1515  &thread, return_compiler_type, ConstString(""), data);
1516  }
1517  }
1518  }
1519  } else if (*byte_size <= altivec_reg->byte_size * 2) {
1520  const RegisterInfo *altivec_reg2 =
1521  reg_ctx->GetRegisterInfoByName("xmm1", 0);
1522  if (altivec_reg2) {
1523  ProcessSP process_sp(thread.GetProcess());
1524  if (process_sp) {
1525  std::unique_ptr<DataBufferHeap> heap_data_up(
1526  new DataBufferHeap(*byte_size, 0));
1527  const ByteOrder byte_order = process_sp->GetByteOrder();
1528  RegisterValue reg_value;
1529  RegisterValue reg_value2;
1530  if (reg_ctx->ReadRegister(altivec_reg, reg_value) &&
1531  reg_ctx->ReadRegister(altivec_reg2, reg_value2)) {
1532 
1533  Status error;
1534  if (reg_value.GetAsMemoryData(
1535  altivec_reg, heap_data_up->GetBytes(),
1536  altivec_reg->byte_size, byte_order, error) &&
1537  reg_value2.GetAsMemoryData(
1538  altivec_reg2,
1539  heap_data_up->GetBytes() + altivec_reg->byte_size,
1540  heap_data_up->GetByteSize() - altivec_reg->byte_size,
1541  byte_order, error)) {
1542  DataExtractor data(DataBufferSP(heap_data_up.release()),
1543  byte_order,
1544  process_sp->GetTarget()
1545  .GetArchitecture()
1546  .GetAddressByteSize());
1547  return_valobj_sp = ValueObjectConstResult::Create(
1548  &thread, return_compiler_type, ConstString(""), data);
1549  }
1550  }
1551  }
1552  }
1553  }
1554  }
1555  }
1556  }
1557 
1558  return return_valobj_sp;
1559 }
1560 
1562  Thread &thread, CompilerType &return_compiler_type) const {
1563  ValueObjectSP return_valobj_sp;
1564 
1565  if (!return_compiler_type)
1566  return return_valobj_sp;
1567 
1568  ExecutionContext exe_ctx(thread.shared_from_this());
1569  return_valobj_sp = GetReturnValueObjectSimple(thread, return_compiler_type);
1570  if (return_valobj_sp)
1571  return return_valobj_sp;
1572 
1573  RegisterContextSP reg_ctx_sp = thread.GetRegisterContext();
1574  if (!reg_ctx_sp)
1575  return return_valobj_sp;
1576 
1577  llvm::Optional<uint64_t> bit_width = return_compiler_type.GetBitSize(&thread);
1578  if (!bit_width)
1579  return return_valobj_sp;
1580  if (return_compiler_type.IsAggregateType()) {
1581  Target *target = exe_ctx.GetTargetPtr();
1582  bool is_memory = true;
1583  if (*bit_width <= 128) {
1584  ByteOrder target_byte_order = target->GetArchitecture().GetByteOrder();
1585  DataBufferSP data_sp(new DataBufferHeap(16, 0));
1586  DataExtractor return_ext(data_sp, target_byte_order,
1587  target->GetArchitecture().GetAddressByteSize());
1588 
1589  const RegisterInfo *rax_info =
1590  reg_ctx_sp->GetRegisterInfoByName("rax", 0);
1591  const RegisterInfo *rdx_info =
1592  reg_ctx_sp->GetRegisterInfoByName("rdx", 0);
1593  const RegisterInfo *xmm0_info =
1594  reg_ctx_sp->GetRegisterInfoByName("xmm0", 0);
1595  const RegisterInfo *xmm1_info =
1596  reg_ctx_sp->GetRegisterInfoByName("xmm1", 0);
1597 
1598  RegisterValue rax_value, rdx_value, xmm0_value, xmm1_value;
1599  reg_ctx_sp->ReadRegister(rax_info, rax_value);
1600  reg_ctx_sp->ReadRegister(rdx_info, rdx_value);
1601  reg_ctx_sp->ReadRegister(xmm0_info, xmm0_value);
1602  reg_ctx_sp->ReadRegister(xmm1_info, xmm1_value);
1603 
1604  DataExtractor rax_data, rdx_data, xmm0_data, xmm1_data;
1605 
1606  rax_value.GetData(rax_data);
1607  rdx_value.GetData(rdx_data);
1608  xmm0_value.GetData(xmm0_data);
1609  xmm1_value.GetData(xmm1_data);
1610 
1611  uint32_t fp_bytes =
1612  0; // Tracks how much of the xmm registers we've consumed so far
1613  uint32_t integer_bytes =
1614  0; // Tracks how much of the rax/rds registers we've consumed so far
1615 
1616  const uint32_t num_children = return_compiler_type.GetNumFields();
1617 
1618  // Since we are in the small struct regime, assume we are not in memory.
1619  is_memory = false;
1620 
1621  for (uint32_t idx = 0; idx < num_children; idx++) {
1622  std::string name;
1623  uint64_t field_bit_offset = 0;
1624  bool is_signed;
1625  bool is_complex;
1626  uint32_t count;
1627 
1628  CompilerType field_compiler_type = return_compiler_type.GetFieldAtIndex(
1629  idx, name, &field_bit_offset, nullptr, nullptr);
1630  llvm::Optional<uint64_t> field_bit_width =
1631  field_compiler_type.GetBitSize(&thread);
1632 
1633  // if we don't know the size of the field (e.g. invalid type), just
1634  // bail out
1635  if (!field_bit_width || *field_bit_width == 0)
1636  break;
1637 
1638  // If there are any unaligned fields, this is stored in memory.
1639  if (field_bit_offset % *field_bit_width != 0) {
1640  is_memory = true;
1641  break;
1642  }
1643 
1644  uint32_t field_byte_width = *field_bit_width / 8;
1645  uint32_t field_byte_offset = field_bit_offset / 8;
1646 
1647  DataExtractor *copy_from_extractor = nullptr;
1648  uint32_t copy_from_offset = 0;
1649 
1650  if (field_compiler_type.IsIntegerOrEnumerationType(is_signed) ||
1651  field_compiler_type.IsPointerType()) {
1652  if (integer_bytes < 8) {
1653  if (integer_bytes + field_byte_width <= 8) {
1654  // This is in RAX, copy from register to our result structure:
1655  copy_from_extractor = &rax_data;
1656  copy_from_offset = integer_bytes;
1657  integer_bytes += field_byte_width;
1658  } else {
1659  // The next field wouldn't fit in the remaining space, so we
1660  // pushed it to rdx.
1661  copy_from_extractor = &rdx_data;
1662  copy_from_offset = 0;
1663  integer_bytes = 8 + field_byte_width;
1664  }
1665  } else if (integer_bytes + field_byte_width <= 16) {
1666  copy_from_extractor = &rdx_data;
1667  copy_from_offset = integer_bytes - 8;
1668  integer_bytes += field_byte_width;
1669  } else {
1670  // The last field didn't fit. I can't see how that would happen
1671  // w/o the overall size being greater than 16 bytes. For now,
1672  // return a nullptr return value object.
1673  return return_valobj_sp;
1674  }
1675  } else if (field_compiler_type.IsFloatingPointType(count, is_complex)) {
1676  // Structs with long doubles are always passed in memory.
1677  if (*field_bit_width == 128) {
1678  is_memory = true;
1679  break;
1680  } else if (*field_bit_width == 64) {
1681  // These have to be in a single xmm register.
1682  if (fp_bytes == 0)
1683  copy_from_extractor = &xmm0_data;
1684  else
1685  copy_from_extractor = &xmm1_data;
1686 
1687  copy_from_offset = 0;
1688  fp_bytes += field_byte_width;
1689  } else if (*field_bit_width == 32) {
1690  // This one is kind of complicated. If we are in an "eightbyte"
1691  // with another float, we'll be stuffed into an xmm register with
1692  // it. If we are in an "eightbyte" with one or more ints, then we
1693  // will be stuffed into the appropriate GPR with them.
1694  bool in_gpr;
1695  if (field_byte_offset % 8 == 0) {
1696  // We are at the beginning of one of the eightbytes, so check the
1697  // next element (if any)
1698  if (idx == num_children - 1)
1699  in_gpr = false;
1700  else {
1701  uint64_t next_field_bit_offset = 0;
1702  CompilerType next_field_compiler_type =
1703  return_compiler_type.GetFieldAtIndex(idx + 1, name,
1704  &next_field_bit_offset,
1705  nullptr, nullptr);
1706  if (next_field_compiler_type.IsIntegerOrEnumerationType(
1707  is_signed))
1708  in_gpr = true;
1709  else {
1710  copy_from_offset = 0;
1711  in_gpr = false;
1712  }
1713  }
1714  } else if (field_byte_offset % 4 == 0) {
1715  // We are inside of an eightbyte, so see if the field before us
1716  // is floating point: This could happen if somebody put padding
1717  // in the structure.
1718  if (idx == 0)
1719  in_gpr = false;
1720  else {
1721  uint64_t prev_field_bit_offset = 0;
1722  CompilerType prev_field_compiler_type =
1723  return_compiler_type.GetFieldAtIndex(idx - 1, name,
1724  &prev_field_bit_offset,
1725  nullptr, nullptr);
1726  if (prev_field_compiler_type.IsIntegerOrEnumerationType(
1727  is_signed))
1728  in_gpr = true;
1729  else {
1730  copy_from_offset = 4;
1731  in_gpr = false;
1732  }
1733  }
1734  } else {
1735  is_memory = true;
1736  continue;
1737  }
1738 
1739  // Okay, we've figured out whether we are in GPR or XMM, now figure
1740  // out which one.
1741  if (in_gpr) {
1742  if (integer_bytes < 8) {
1743  // This is in RAX, copy from register to our result structure:
1744  copy_from_extractor = &rax_data;
1745  copy_from_offset = integer_bytes;
1746  integer_bytes += field_byte_width;
1747  } else {
1748  copy_from_extractor = &rdx_data;
1749  copy_from_offset = integer_bytes - 8;
1750  integer_bytes += field_byte_width;
1751  }
1752  } else {
1753  if (fp_bytes < 8)
1754  copy_from_extractor = &xmm0_data;
1755  else
1756  copy_from_extractor = &xmm1_data;
1757 
1758  fp_bytes += field_byte_width;
1759  }
1760  }
1761  }
1762 
1763  // These two tests are just sanity checks. If I somehow get the type
1764  // calculation wrong above it is better to just return nothing than to
1765  // assert or crash.
1766  if (!copy_from_extractor)
1767  return return_valobj_sp;
1768  if (copy_from_offset + field_byte_width >
1769  copy_from_extractor->GetByteSize())
1770  return return_valobj_sp;
1771 
1772  copy_from_extractor->CopyByteOrderedData(
1773  copy_from_offset, field_byte_width,
1774  data_sp->GetBytes() + field_byte_offset, field_byte_width,
1775  target_byte_order);
1776  }
1777 
1778  if (!is_memory) {
1779  // The result is in our data buffer. Let's make a variable object out
1780  // of it:
1781  return_valobj_sp = ValueObjectConstResult::Create(
1782  &thread, return_compiler_type, ConstString(""), return_ext);
1783  }
1784  }
1785 
1786  // FIXME: This is just taking a guess, rax may very well no longer hold the
1787  // return storage location.
1788  // If we are going to do this right, when we make a new frame we should
1789  // check to see if it uses a memory return, and if we are at the first
1790  // instruction and if so stash away the return location. Then we would
1791  // only return the memory return value if we know it is valid.
1792 
1793  if (is_memory) {
1794  unsigned rax_id =
1795  reg_ctx_sp->GetRegisterInfoByName("rax", 0)->kinds[eRegisterKindLLDB];
1796  lldb::addr_t storage_addr =
1797  (uint64_t)thread.GetRegisterContext()->ReadRegisterAsUnsigned(rax_id,
1798  0);
1799  return_valobj_sp = ValueObjectMemory::Create(
1800  &thread, "", Address(storage_addr, nullptr), return_compiler_type);
1801  }
1802  }
1803 
1804  return return_valobj_sp;
1805 }
1806 
1807 // This defines the CFA as rsp+8
1808 // the saved pc is at CFA-8 (i.e. rsp+0)
1809 // The saved rsp is CFA+0
1810 
1812  unwind_plan.Clear();
1813  unwind_plan.SetRegisterKind(eRegisterKindDWARF);
1814 
1815  uint32_t sp_reg_num = dwarf_rsp;
1816  uint32_t pc_reg_num = dwarf_rip;
1817 
1819  row->GetCFAValue().SetIsRegisterPlusOffset(sp_reg_num, 8);
1820  row->SetRegisterLocationToAtCFAPlusOffset(pc_reg_num, -8, false);
1821  row->SetRegisterLocationToIsCFAPlusOffset(sp_reg_num, 0, true);
1822  unwind_plan.AppendRow(row);
1823  unwind_plan.SetSourceName("x86_64 at-func-entry default");
1824  unwind_plan.SetSourcedFromCompiler(eLazyBoolNo);
1825  return true;
1826 }
1827 
1828 // This defines the CFA as rbp+16
1829 // The saved pc is at CFA-8 (i.e. rbp+8)
1830 // The saved rbp is at CFA-16 (i.e. rbp+0)
1831 // The saved rsp is CFA+0
1832 
1834  unwind_plan.Clear();
1835  unwind_plan.SetRegisterKind(eRegisterKindDWARF);
1836 
1837  uint32_t fp_reg_num = dwarf_rbp;
1838  uint32_t sp_reg_num = dwarf_rsp;
1839  uint32_t pc_reg_num = dwarf_rip;
1840 
1842 
1843  const int32_t ptr_size = 8;
1844  row->GetCFAValue().SetIsRegisterPlusOffset(dwarf_rbp, 2 * ptr_size);
1845  row->SetOffset(0);
1846 
1847  row->SetRegisterLocationToAtCFAPlusOffset(fp_reg_num, ptr_size * -2, true);
1848  row->SetRegisterLocationToAtCFAPlusOffset(pc_reg_num, ptr_size * -1, true);
1849  row->SetRegisterLocationToIsCFAPlusOffset(sp_reg_num, 0, true);
1850 
1851  unwind_plan.AppendRow(row);
1852  unwind_plan.SetSourceName("x86_64 default unwind plan");
1853  unwind_plan.SetSourcedFromCompiler(eLazyBoolNo);
1855  return true;
1856 }
1857 
1858 bool ABISysV_x86_64::RegisterIsVolatile(const RegisterInfo *reg_info) {
1859  return !RegisterIsCalleeSaved(reg_info);
1860 }
1861 
1862 // See "Register Usage" in the
1863 // "System V Application Binary Interface"
1864 // "AMD64 Architecture Processor Supplement" (or "x86-64(tm) Architecture
1865 // Processor Supplement" in earlier revisions) (this doc is also commonly
1866 // referred to as the x86-64/AMD64 psABI) Edited by Michael Matz, Jan Hubicka,
1867 // Andreas Jaeger, and Mark Mitchell current version is 0.99.6 released
1868 // 2012-07-02 at http://refspecs.linuxfoundation.org/elf/x86-64-abi-0.99.pdf
1869 // It's being revised & updated at https://github.com/hjl-tools/x86-psABI/
1870 
1871 bool ABISysV_x86_64::RegisterIsCalleeSaved(const RegisterInfo *reg_info) {
1872  if (!reg_info)
1873  return false;
1874  assert(reg_info->name != nullptr && "unnamed register?");
1875  std::string Name = std::string(reg_info->name);
1876  bool IsCalleeSaved =
1877  llvm::StringSwitch<bool>(Name)
1878  .Cases("r12", "r13", "r14", "r15", "rbp", "ebp", "rbx", "ebx", true)
1879  .Cases("rip", "eip", "rsp", "esp", "sp", "fp", "pc", true)
1880  .Default(false);
1881  return IsCalleeSaved;
1882 }
1883 
1885  PluginManager::RegisterPlugin(
1886  GetPluginNameStatic(), "System V ABI for x86_64 targets", CreateInstance);
1887 }
1888 
1890  PluginManager::UnregisterPlugin(CreateInstance);
1891 }
1892 
1894  static ConstString g_name("sysv-x86_64");
1895  return g_name;
1896 }
1897 
1898 // PluginInterface protocol
1899 
1901  return GetPluginNameStatic();
1902 }
1903 
lldb::ValueObjectSP GetReturnValueObjectSimple(lldb_private::Thread &thread, lldb_private::CompilerType &ast_type) const
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
static lldb::ABISP CreateInstance(lldb::ProcessSP process_sp, const lldb_private::ArchSpec &arch)
#define LLDB_REGNUM_GENERIC_ARG6
Definition: lldb-defines.h:78
bool CreateDefaultUnwindPlan(lldb_private::UnwindPlan &unwind_plan) override
bool RegisterIsVolatile(const lldb_private::RegisterInfo *reg_info) override
lldb_private::ConstString GetPluginName() override
void SetSourceName(const char *)
Definition: UnwindPlan.cpp:542
Enumerations for broadcasting.
Definition: SBLaunchInfo.h:14
const ArchSpec & GetArchitecture() const
Definition: Target.h:941
bool CreateFunctionEntryUnwindPlan(lldb_private::UnwindPlan &unwind_plan) override
lldb_private::Status SetReturnValueObject(lldb::StackFrameSP &frame_sp, lldb::ValueObjectSP &new_value) override
uint32_t GetAddressByteSize() const
Returns the size in bytes of an address of the current architecture.
Definition: ArchSpec.cpp:742
static bool g_register_info_names_constified
#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
uint64_t GetSP(uint64_t fail_value=LLDB_INVALID_ADDRESS)
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
#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.
#define LLDB_REGNUM_GENERIC_SP
Definition: lldb-defines.h:64
uint32_t GetPluginVersion() override
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.
uint32_t GetNumFields() const
A subclass of DataBuffer that stores a data buffer on the heap.
#define LLDB_REGNUM_GENERIC_ARG1
Definition: lldb-defines.h:68
bool IsPointerType(CompilerType *pointee_type=nullptr) const
llvm::Triple & GetTriple()
Architecture triple accessor.
Definition: ArchSpec.h:431
static bool ReadIntegerArgument(Scalar &scalar, unsigned int bit_width, bool is_signed, Thread &thread, uint32_t *argument_register_ids, unsigned int &current_argument_register, addr_t &current_stack_argument)
bool SignExtend(uint32_t bit_pos)
Definition: Scalar.cpp:2609
#define LLDB_REGNUM_GENERIC_FP
Definition: lldb-defines.h:65
#define UINT32_MAX
Definition: lldb-defines.h:31
bool GetArgumentValues(lldb_private::Thread &thread, lldb_private::ValueList &values) const override
size_t GetRedZoneSize() const override
bool IsFloatingPointType(uint32_t &count, bool &is_complex) const
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
lldb::ByteOrder GetByteOrder() const
Get the current byte order value.
llvm::StringRef GetString() const
lldb::ValueObjectSP GetReturnValueObjectImpl(lldb_private::Thread &thread, lldb_private::CompilerType &type) const override
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
lldb::ByteOrder GetByteOrder() const
Returns the byte order for the architecture specification.
Definition: ArchSpec.cpp:788
double GetDouble(lldb::offset_t *offset_ptr) const
#define LLDB_REGNUM_GENERIC_FLAGS
Definition: lldb-defines.h:67
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
const CompilerType & GetCompilerType()
Definition: Value.cpp:239
void SetRegisterKind(lldb::RegisterKind kind)
Definition: UnwindPlan.h:408
A section + offset based address class.
Definition: Address.h:80
static lldb_private::ConstString GetPluginNameStatic()
bool WriteRegisterFromUnsigned(uint32_t reg, uint64_t uval)
lldb::ProcessSP GetProcess() const
Definition: Thread.h:154
dwarf_regnums
bool GetPointerReturnRegister(const char *&name) override
uint64_t GetMaxU64(lldb::offset_t *offset_ptr, size_t byte_size) const
Extract an unsigned integer of size byte_size from *offset_ptr.
uint64_t GetByteSize() const
Get the number of bytes contained in this object.
static const uint32_t k_num_register_infos
static void Initialize()
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::offset_t CopyByteOrderedData(lldb::offset_t src_offset, lldb::offset_t src_len, void *dst, lldb::offset_t dst_len, lldb::ByteOrder dst_byte_order) const
Copy dst_len bytes from *offset_ptr and ensure the copied data is treated as a value that can be swap...
uint64_t addr_t
Definition: lldb-types.h:83
static RegisterInfo g_register_infos[]
bool GetData(DataExtractor &data) const
A uniqued constant string class.
Definition: ConstString.h:38
static void Terminate()
bool Fail() const
Test for error condition.
Definition: Status.cpp:181
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 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
void SetBytes(const void *bytes, size_t length, lldb::ByteOrder byte_order)
bool RegisterIsCalleeSaved(const lldb_private::RegisterInfo *reg_info)
CompilerType GetFieldAtIndex(size_t idx, std::string &name, uint64_t *bit_offset_ptr, uint32_t *bitfield_bit_size_ptr, bool *is_bitfield_ptr) 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
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
void Printf(const char *format,...) __attribute__((format(printf
Definition: Log.cpp:113
void SetSourcedFromCompiler(lldb_private::LazyBool from_compiler)
Definition: UnwindPlan.h:449
const lldb_private::RegisterInfo * GetRegisterInfoArray(uint32_t &count) override
An error handling class.
Definition: Status.h:44
#define LLDB_INVALID_REGNUM
Definition: lldb-defines.h:90