LLDB  mainline
ABIMacOSX_arm64.cpp
Go to the documentation of this file.
1 //===-- ABIMacOSX_arm64.cpp -----------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #include "ABIMacOSX_arm64.h"
10 
11 #include <vector>
12 
13 #include "llvm/ADT/STLExtras.h"
14 #include "llvm/ADT/Triple.h"
15 
16 #include "lldb/Core/Module.h"
18 #include "lldb/Core/Value.h"
20 #include "lldb/Symbol/UnwindPlan.h"
21 #include "lldb/Target/Process.h"
23 #include "lldb/Target/Target.h"
24 #include "lldb/Target/Thread.h"
26 #include "lldb/Utility/Log.h"
28 #include "lldb/Utility/Scalar.h"
29 #include "lldb/Utility/Status.h"
30 
32 
33 using namespace lldb;
34 using namespace lldb_private;
35 
36 static const char *pluginDesc = "Mac OS X ABI for arm64 targets";
37 
38 size_t ABIMacOSX_arm64::GetRedZoneSize() const { return 128; }
39 
40 // Static Functions
41 
42 ABISP
43 ABIMacOSX_arm64::CreateInstance(ProcessSP process_sp, const ArchSpec &arch) {
44  const llvm::Triple::ArchType arch_type = arch.GetTriple().getArch();
45  const llvm::Triple::VendorType vendor_type = arch.GetTriple().getVendor();
46 
47  if (vendor_type == llvm::Triple::Apple) {
48  if (arch_type == llvm::Triple::aarch64 ||
49  arch_type == llvm::Triple::aarch64_32) {
50  return ABISP(
51  new ABIMacOSX_arm64(std::move(process_sp), MakeMCRegisterInfo(arch)));
52  }
53  }
54 
55  return ABISP();
56 }
57 
59  Thread &thread, lldb::addr_t sp, lldb::addr_t func_addr,
60  lldb::addr_t return_addr, llvm::ArrayRef<lldb::addr_t> args) const {
61  RegisterContext *reg_ctx = thread.GetRegisterContext().get();
62  if (!reg_ctx)
63  return false;
64 
66 
67  if (log) {
68  StreamString s;
69  s.Printf("ABIMacOSX_arm64::PrepareTrivialCall (tid = 0x%" PRIx64
70  ", sp = 0x%" PRIx64 ", func_addr = 0x%" PRIx64
71  ", return_addr = 0x%" PRIx64,
72  thread.GetID(), (uint64_t)sp, (uint64_t)func_addr,
73  (uint64_t)return_addr);
74 
75  for (size_t i = 0; i < args.size(); ++i)
76  s.Printf(", arg%d = 0x%" PRIx64, static_cast<int>(i + 1), args[i]);
77  s.PutCString(")");
78  log->PutString(s.GetString());
79  }
80 
81  const uint32_t pc_reg_num = reg_ctx->ConvertRegisterKindToRegisterNumber(
83  const uint32_t sp_reg_num = reg_ctx->ConvertRegisterKindToRegisterNumber(
85  const uint32_t ra_reg_num = reg_ctx->ConvertRegisterKindToRegisterNumber(
87 
88  // x0 - x7 contain first 8 simple args
89  if (args.size() > 8) // TODO handle more than 8 arguments
90  return false;
91 
92  for (size_t i = 0; i < args.size(); ++i) {
93  const RegisterInfo *reg_info = reg_ctx->GetRegisterInfo(
95  LLDB_LOGF(log, "About to write arg%d (0x%" PRIx64 ") into %s",
96  static_cast<int>(i + 1), args[i], reg_info->name);
97  if (!reg_ctx->WriteRegisterFromUnsigned(reg_info, args[i]))
98  return false;
99  }
100 
101  // Set "lr" to the return address
102  if (!reg_ctx->WriteRegisterFromUnsigned(
103  reg_ctx->GetRegisterInfoAtIndex(ra_reg_num), return_addr))
104  return false;
105 
106  // Set "sp" to the requested value
107  if (!reg_ctx->WriteRegisterFromUnsigned(
108  reg_ctx->GetRegisterInfoAtIndex(sp_reg_num), sp))
109  return false;
110 
111  // Set "pc" to the address requested
112  if (!reg_ctx->WriteRegisterFromUnsigned(
113  reg_ctx->GetRegisterInfoAtIndex(pc_reg_num), func_addr))
114  return false;
115 
116  return true;
117 }
118 
120  ValueList &values) const {
121  uint32_t num_values = values.GetSize();
122 
123  ExecutionContext exe_ctx(thread.shared_from_this());
124 
125  // Extract the register context so we can read arguments from registers
126 
127  RegisterContext *reg_ctx = thread.GetRegisterContext().get();
128 
129  if (!reg_ctx)
130  return false;
131 
132  addr_t sp = 0;
133 
134  for (uint32_t value_idx = 0; value_idx < num_values; ++value_idx) {
135  // We currently only support extracting values with Clang QualTypes. Do we
136  // care about others?
137  Value *value = values.GetValueAtIndex(value_idx);
138 
139  if (!value)
140  return false;
141 
142  CompilerType value_type = value->GetCompilerType();
143  llvm::Optional<uint64_t> bit_size = value_type.GetBitSize(&thread);
144  if (!bit_size)
145  return false;
146 
147  bool is_signed = false;
148  size_t bit_width = 0;
149  if (value_type.IsIntegerOrEnumerationType(is_signed)) {
150  bit_width = *bit_size;
151  } else if (value_type.IsPointerOrReferenceType()) {
152  bit_width = *bit_size;
153  } else {
154  // We only handle integer, pointer and reference types currently...
155  return false;
156  }
157 
158  if (bit_width <= (exe_ctx.GetProcessRef().GetAddressByteSize() * 8)) {
159  if (value_idx < 8) {
160  // Arguments 1-6 are in x0-x5...
161  const RegisterInfo *reg_info = nullptr;
162  // Search by generic ID first, then fall back to by name
163  uint32_t arg_reg_num = reg_ctx->ConvertRegisterKindToRegisterNumber(
165  if (arg_reg_num != LLDB_INVALID_REGNUM) {
166  reg_info = reg_ctx->GetRegisterInfoAtIndex(arg_reg_num);
167  } else {
168  switch (value_idx) {
169  case 0:
170  reg_info = reg_ctx->GetRegisterInfoByName("x0");
171  break;
172  case 1:
173  reg_info = reg_ctx->GetRegisterInfoByName("x1");
174  break;
175  case 2:
176  reg_info = reg_ctx->GetRegisterInfoByName("x2");
177  break;
178  case 3:
179  reg_info = reg_ctx->GetRegisterInfoByName("x3");
180  break;
181  case 4:
182  reg_info = reg_ctx->GetRegisterInfoByName("x4");
183  break;
184  case 5:
185  reg_info = reg_ctx->GetRegisterInfoByName("x5");
186  break;
187  case 6:
188  reg_info = reg_ctx->GetRegisterInfoByName("x6");
189  break;
190  case 7:
191  reg_info = reg_ctx->GetRegisterInfoByName("x7");
192  break;
193  }
194  }
195 
196  if (reg_info) {
197  RegisterValue reg_value;
198 
199  if (reg_ctx->ReadRegister(reg_info, reg_value)) {
200  if (is_signed)
201  reg_value.SignExtend(bit_width);
202  if (!reg_value.GetScalarValue(value->GetScalar()))
203  return false;
204  continue;
205  }
206  }
207  return false;
208  } else {
209  if (sp == 0) {
210  // Read the stack pointer if we already haven't read it
211  sp = reg_ctx->GetSP(0);
212  if (sp == 0)
213  return false;
214  }
215 
216  // Arguments 5 on up are on the stack
217  const uint32_t arg_byte_size = (bit_width + (8 - 1)) / 8;
218  Status error;
220  sp, arg_byte_size, is_signed, value->GetScalar(), error))
221  return false;
222 
223  sp += arg_byte_size;
224  // Align up to the next 8 byte boundary if needed
225  if (sp % 8) {
226  sp >>= 3;
227  sp += 1;
228  sp <<= 3;
229  }
230  }
231  }
232  }
233  return true;
234 }
235 
236 Status
237 ABIMacOSX_arm64::SetReturnValueObject(lldb::StackFrameSP &frame_sp,
238  lldb::ValueObjectSP &new_value_sp) {
239  Status error;
240  if (!new_value_sp) {
241  error.SetErrorString("Empty value object for return value.");
242  return error;
243  }
244 
245  CompilerType return_value_type = new_value_sp->GetCompilerType();
246  if (!return_value_type) {
247  error.SetErrorString("Null clang type for return value.");
248  return error;
249  }
250 
251  Thread *thread = frame_sp->GetThread().get();
252 
253  RegisterContext *reg_ctx = thread->GetRegisterContext().get();
254 
255  if (reg_ctx) {
256  DataExtractor data;
257  Status data_error;
258  const uint64_t byte_size = new_value_sp->GetData(data, data_error);
259  if (data_error.Fail()) {
260  error.SetErrorStringWithFormat(
261  "Couldn't convert return value to raw data: %s",
262  data_error.AsCString());
263  return error;
264  }
265 
266  const uint32_t type_flags = return_value_type.GetTypeInfo(nullptr);
267  if (type_flags & eTypeIsScalar || type_flags & eTypeIsPointer) {
268  if (type_flags & eTypeIsInteger || type_flags & eTypeIsPointer) {
269  // Extract the register context so we can read arguments from registers
270  lldb::offset_t offset = 0;
271  if (byte_size <= 16) {
272  const RegisterInfo *x0_info = reg_ctx->GetRegisterInfoByName("x0", 0);
273  if (byte_size <= 8) {
274  uint64_t raw_value = data.GetMaxU64(&offset, byte_size);
275 
276  if (!reg_ctx->WriteRegisterFromUnsigned(x0_info, raw_value))
277  error.SetErrorString("failed to write register x0");
278  } else {
279  uint64_t raw_value = data.GetMaxU64(&offset, 8);
280 
281  if (reg_ctx->WriteRegisterFromUnsigned(x0_info, raw_value)) {
282  const RegisterInfo *x1_info =
283  reg_ctx->GetRegisterInfoByName("x1", 0);
284  raw_value = data.GetMaxU64(&offset, byte_size - offset);
285 
286  if (!reg_ctx->WriteRegisterFromUnsigned(x1_info, raw_value))
287  error.SetErrorString("failed to write register x1");
288  }
289  }
290  } else {
291  error.SetErrorString("We don't support returning longer than 128 bit "
292  "integer values at present.");
293  }
294  } else if (type_flags & eTypeIsFloat) {
295  if (type_flags & eTypeIsComplex) {
296  // Don't handle complex yet.
297  error.SetErrorString(
298  "returning complex float values are not supported");
299  } else {
300  const RegisterInfo *v0_info = reg_ctx->GetRegisterInfoByName("v0", 0);
301 
302  if (v0_info) {
303  if (byte_size <= 16) {
304  if (byte_size <= RegisterValue::GetMaxByteSize()) {
305  RegisterValue reg_value;
306  error = reg_value.SetValueFromData(v0_info, data, 0, true);
307  if (error.Success()) {
308  if (!reg_ctx->WriteRegister(v0_info, reg_value))
309  error.SetErrorString("failed to write register v0");
310  }
311  } else {
312  error.SetErrorStringWithFormat(
313  "returning float values with a byte size of %" PRIu64
314  " are not supported",
315  byte_size);
316  }
317  } else {
318  error.SetErrorString("returning float values longer than 128 "
319  "bits are not supported");
320  }
321  } else {
322  error.SetErrorString("v0 register is not available on this target");
323  }
324  }
325  }
326  } else if (type_flags & eTypeIsVector) {
327  if (byte_size > 0) {
328  const RegisterInfo *v0_info = reg_ctx->GetRegisterInfoByName("v0", 0);
329 
330  if (v0_info) {
331  if (byte_size <= v0_info->byte_size) {
332  RegisterValue reg_value;
333  error = reg_value.SetValueFromData(v0_info, data, 0, true);
334  if (error.Success()) {
335  if (!reg_ctx->WriteRegister(v0_info, reg_value))
336  error.SetErrorString("failed to write register v0");
337  }
338  }
339  }
340  }
341  }
342  } else {
343  error.SetErrorString("no registers are available");
344  }
345 
346  return error;
347 }
348 
350  unwind_plan.Clear();
351  unwind_plan.SetRegisterKind(eRegisterKindDWARF);
352 
353  uint32_t lr_reg_num = arm64_dwarf::lr;
354  uint32_t sp_reg_num = arm64_dwarf::sp;
355  uint32_t pc_reg_num = arm64_dwarf::pc;
356 
358 
359  // Our previous Call Frame Address is the stack pointer
360  row->GetCFAValue().SetIsRegisterPlusOffset(sp_reg_num, 0);
361 
362  // Our previous PC is in the LR
363  row->SetRegisterLocationToRegister(pc_reg_num, lr_reg_num, true);
364 
365  unwind_plan.AppendRow(row);
366 
367  // All other registers are the same.
368 
369  unwind_plan.SetSourceName("arm64 at-func-entry default");
370  unwind_plan.SetSourcedFromCompiler(eLazyBoolNo);
371 
372  return true;
373 }
374 
376  unwind_plan.Clear();
377  unwind_plan.SetRegisterKind(eRegisterKindDWARF);
378 
379  uint32_t fp_reg_num = arm64_dwarf::fp;
380  uint32_t pc_reg_num = arm64_dwarf::pc;
381 
383  const int32_t ptr_size = 8;
384 
385  row->GetCFAValue().SetIsRegisterPlusOffset(fp_reg_num, 2 * ptr_size);
386  row->SetOffset(0);
387  row->SetUnspecifiedRegistersAreUndefined(true);
388 
389  row->SetRegisterLocationToAtCFAPlusOffset(fp_reg_num, ptr_size * -2, true);
390  row->SetRegisterLocationToAtCFAPlusOffset(pc_reg_num, ptr_size * -1, true);
391 
392  unwind_plan.AppendRow(row);
393  unwind_plan.SetSourceName("arm64-apple-darwin default unwind plan");
394  unwind_plan.SetSourcedFromCompiler(eLazyBoolNo);
397  return true;
398 }
399 
400 // AAPCS64 (Procedure Call Standard for the ARM 64-bit Architecture) says
401 // registers x19 through x28 and sp are callee preserved. v8-v15 are non-
402 // volatile (and specifically only the lower 8 bytes of these regs), the rest
403 // of the fp/SIMD registers are volatile.
404 //
405 // v. https://github.com/ARM-software/abi-aa/blob/main/aapcs64/
406 
407 // We treat x29 as callee preserved also, else the unwinder won't try to
408 // retrieve fp saves.
409 
410 bool ABIMacOSX_arm64::RegisterIsVolatile(const RegisterInfo *reg_info) {
411  if (reg_info) {
412  const char *name = reg_info->name;
413 
414  // Sometimes we'll be called with the "alternate" name for these registers;
415  // recognize them as non-volatile.
416 
417  if (name[0] == 'p' && name[1] == 'c') // pc
418  return false;
419  if (name[0] == 'f' && name[1] == 'p') // fp
420  return false;
421  if (name[0] == 's' && name[1] == 'p') // sp
422  return false;
423  if (name[0] == 'l' && name[1] == 'r') // lr
424  return false;
425 
426  if (name[0] == 'x') {
427  // Volatile registers: x0-x18, x30 (lr)
428  // Return false for the non-volatile gpr regs, true for everything else
429  switch (name[1]) {
430  case '1':
431  switch (name[2]) {
432  case '9':
433  return false; // x19 is non-volatile
434  default:
435  return true;
436  }
437  break;
438  case '2':
439  switch (name[2]) {
440  case '0':
441  case '1':
442  case '2':
443  case '3':
444  case '4':
445  case '5':
446  case '6':
447  case '7':
448  case '8':
449  return false; // x20 - 28 are non-volatile
450  case '9':
451  return false; // x29 aka fp treat as non-volatile on Darwin
452  default:
453  return true;
454  }
455  case '3': // x30 aka lr treat as non-volatile
456  if (name[2] == '0')
457  return false;
458  break;
459  default:
460  return true;
461  }
462  } else if (name[0] == 'v' || name[0] == 's' || name[0] == 'd') {
463  // Volatile registers: v0-7, v16-v31
464  // Return false for non-volatile fp/SIMD regs, true for everything else
465  switch (name[1]) {
466  case '8':
467  case '9':
468  return false; // v8-v9 are non-volatile
469  case '1':
470  switch (name[2]) {
471  case '0':
472  case '1':
473  case '2':
474  case '3':
475  case '4':
476  case '5':
477  return false; // v10-v15 are non-volatile
478  default:
479  return true;
480  }
481  default:
482  return true;
483  }
484  }
485  }
486  return true;
487 }
488 
490  ExecutionContext &exe_ctx, RegisterContext *reg_ctx,
491  const CompilerType &value_type,
492  bool is_return_value, // false => parameter, true => return value
493  uint32_t &NGRN, // NGRN (see ABI documentation)
494  uint32_t &NSRN, // NSRN (see ABI documentation)
495  DataExtractor &data) {
496  llvm::Optional<uint64_t> byte_size =
497  value_type.GetByteSize(exe_ctx.GetBestExecutionContextScope());
498  if (!byte_size || *byte_size == 0)
499  return false;
500 
501  std::unique_ptr<DataBufferHeap> heap_data_up(
502  new DataBufferHeap(*byte_size, 0));
503  const ByteOrder byte_order = exe_ctx.GetProcessRef().GetByteOrder();
504  Status error;
505 
506  CompilerType base_type;
507  const uint32_t homogeneous_count =
508  value_type.IsHomogeneousAggregate(&base_type);
509  if (homogeneous_count > 0 && homogeneous_count <= 8) {
510  // Make sure we have enough registers
511  if (NSRN < 8 && (8 - NSRN) >= homogeneous_count) {
512  if (!base_type)
513  return false;
514  llvm::Optional<uint64_t> base_byte_size =
515  base_type.GetByteSize(exe_ctx.GetBestExecutionContextScope());
516  if (!base_byte_size)
517  return false;
518  uint32_t data_offset = 0;
519 
520  for (uint32_t i = 0; i < homogeneous_count; ++i) {
521  char v_name[8];
522  ::snprintf(v_name, sizeof(v_name), "v%u", NSRN);
523  const RegisterInfo *reg_info =
524  reg_ctx->GetRegisterInfoByName(v_name, 0);
525  if (reg_info == nullptr)
526  return false;
527 
528  if (*base_byte_size > reg_info->byte_size)
529  return false;
530 
531  RegisterValue reg_value;
532 
533  if (!reg_ctx->ReadRegister(reg_info, reg_value))
534  return false;
535 
536  // Make sure we have enough room in "heap_data_up"
537  if ((data_offset + *base_byte_size) <= heap_data_up->GetByteSize()) {
538  const size_t bytes_copied = reg_value.GetAsMemoryData(
539  reg_info, heap_data_up->GetBytes() + data_offset, *base_byte_size,
540  byte_order, error);
541  if (bytes_copied != *base_byte_size)
542  return false;
543  data_offset += bytes_copied;
544  ++NSRN;
545  } else
546  return false;
547  }
548  data.SetByteOrder(byte_order);
550  data.SetData(DataBufferSP(heap_data_up.release()));
551  return true;
552  }
553  }
554 
555  const size_t max_reg_byte_size = 16;
556  if (*byte_size <= max_reg_byte_size) {
557  size_t bytes_left = *byte_size;
558  uint32_t data_offset = 0;
559  while (data_offset < *byte_size) {
560  if (NGRN >= 8)
561  return false;
562 
565  if (reg_num == LLDB_INVALID_REGNUM)
566  return false;
567 
568  const RegisterInfo *reg_info = reg_ctx->GetRegisterInfoAtIndex(reg_num);
569  if (reg_info == nullptr)
570  return false;
571 
572  RegisterValue reg_value;
573 
574  if (!reg_ctx->ReadRegister(reg_info, reg_value))
575  return false;
576 
577  const size_t curr_byte_size = std::min<size_t>(8, bytes_left);
578  const size_t bytes_copied = reg_value.GetAsMemoryData(
579  reg_info, heap_data_up->GetBytes() + data_offset, curr_byte_size,
580  byte_order, error);
581  if (bytes_copied == 0)
582  return false;
583  if (bytes_copied >= bytes_left)
584  break;
585  data_offset += bytes_copied;
586  bytes_left -= bytes_copied;
587  ++NGRN;
588  }
589  } else {
590  const RegisterInfo *reg_info = nullptr;
591  if (is_return_value) {
592  // We are assuming we are decoding this immediately after returning from
593  // a function call and that the address of the structure is in x8
594  reg_info = reg_ctx->GetRegisterInfoByName("x8", 0);
595  } else {
596  // We are assuming we are stopped at the first instruction in a function
597  // and that the ABI is being respected so all parameters appear where
598  // they should be (functions with no external linkage can legally violate
599  // the ABI).
600  if (NGRN >= 8)
601  return false;
602 
605  if (reg_num == LLDB_INVALID_REGNUM)
606  return false;
607  reg_info = reg_ctx->GetRegisterInfoAtIndex(reg_num);
608  if (reg_info == nullptr)
609  return false;
610  ++NGRN;
611  }
612 
613  if (reg_info == nullptr)
614  return false;
615 
616  const lldb::addr_t value_addr =
617  reg_ctx->ReadRegisterAsUnsigned(reg_info, LLDB_INVALID_ADDRESS);
618 
619  if (value_addr == LLDB_INVALID_ADDRESS)
620  return false;
621 
622  if (exe_ctx.GetProcessRef().ReadMemory(
623  value_addr, heap_data_up->GetBytes(), heap_data_up->GetByteSize(),
624  error) != heap_data_up->GetByteSize()) {
625  return false;
626  }
627  }
628 
629  data.SetByteOrder(byte_order);
631  data.SetData(DataBufferSP(heap_data_up.release()));
632  return true;
633 }
634 
636  Thread &thread, CompilerType &return_compiler_type) const {
637  ValueObjectSP return_valobj_sp;
638  Value value;
639 
640  ExecutionContext exe_ctx(thread.shared_from_this());
641  if (exe_ctx.GetTargetPtr() == nullptr || exe_ctx.GetProcessPtr() == nullptr)
642  return return_valobj_sp;
643 
644  // value.SetContext (Value::eContextTypeClangType, return_compiler_type);
645  value.SetCompilerType(return_compiler_type);
646 
647  RegisterContext *reg_ctx = thread.GetRegisterContext().get();
648  if (!reg_ctx)
649  return return_valobj_sp;
650 
651  llvm::Optional<uint64_t> byte_size =
652  return_compiler_type.GetByteSize(&thread);
653  if (!byte_size)
654  return return_valobj_sp;
655 
656  const uint32_t type_flags = return_compiler_type.GetTypeInfo(nullptr);
657  if (type_flags & eTypeIsScalar || type_flags & eTypeIsPointer) {
658  value.SetValueType(Value::ValueType::Scalar);
659 
660  bool success = false;
661  if (type_flags & eTypeIsInteger || type_flags & eTypeIsPointer) {
662  // Extract the register context so we can read arguments from registers
663  if (*byte_size <= 8) {
664  const RegisterInfo *x0_reg_info =
665  reg_ctx->GetRegisterInfoByName("x0", 0);
666  if (x0_reg_info) {
667  uint64_t raw_value =
668  thread.GetRegisterContext()->ReadRegisterAsUnsigned(x0_reg_info,
669  0);
670  const bool is_signed = (type_flags & eTypeIsSigned) != 0;
671  switch (*byte_size) {
672  default:
673  break;
674  case 16: // uint128_t
675  // In register x0 and x1
676  {
677  const RegisterInfo *x1_reg_info =
678  reg_ctx->GetRegisterInfoByName("x1", 0);
679 
680  if (x1_reg_info) {
681  if (*byte_size <=
682  x0_reg_info->byte_size + x1_reg_info->byte_size) {
683  std::unique_ptr<DataBufferHeap> heap_data_up(
684  new DataBufferHeap(*byte_size, 0));
685  const ByteOrder byte_order =
686  exe_ctx.GetProcessRef().GetByteOrder();
687  RegisterValue x0_reg_value;
688  RegisterValue x1_reg_value;
689  if (reg_ctx->ReadRegister(x0_reg_info, x0_reg_value) &&
690  reg_ctx->ReadRegister(x1_reg_info, x1_reg_value)) {
691  Status error;
692  if (x0_reg_value.GetAsMemoryData(
693  x0_reg_info, heap_data_up->GetBytes() + 0, 8,
694  byte_order, error) &&
695  x1_reg_value.GetAsMemoryData(
696  x1_reg_info, heap_data_up->GetBytes() + 8, 8,
697  byte_order, error)) {
698  DataExtractor data(
699  DataBufferSP(heap_data_up.release()), byte_order,
700  exe_ctx.GetProcessRef().GetAddressByteSize());
701 
702  return_valobj_sp = ValueObjectConstResult::Create(
703  &thread, return_compiler_type, ConstString(""), data);
704  return return_valobj_sp;
705  }
706  }
707  }
708  }
709  }
710  break;
711  case sizeof(uint64_t):
712  if (is_signed)
713  value.GetScalar() = (int64_t)(raw_value);
714  else
715  value.GetScalar() = (uint64_t)(raw_value);
716  success = true;
717  break;
718 
719  case sizeof(uint32_t):
720  if (is_signed)
721  value.GetScalar() = (int32_t)(raw_value & UINT32_MAX);
722  else
723  value.GetScalar() = (uint32_t)(raw_value & UINT32_MAX);
724  success = true;
725  break;
726 
727  case sizeof(uint16_t):
728  if (is_signed)
729  value.GetScalar() = (int16_t)(raw_value & UINT16_MAX);
730  else
731  value.GetScalar() = (uint16_t)(raw_value & UINT16_MAX);
732  success = true;
733  break;
734 
735  case sizeof(uint8_t):
736  if (is_signed)
737  value.GetScalar() = (int8_t)(raw_value & UINT8_MAX);
738  else
739  value.GetScalar() = (uint8_t)(raw_value & UINT8_MAX);
740  success = true;
741  break;
742  }
743  }
744  }
745  } else if (type_flags & eTypeIsFloat) {
746  if (type_flags & eTypeIsComplex) {
747  // Don't handle complex yet.
748  } else {
749  if (*byte_size <= sizeof(long double)) {
750  const RegisterInfo *v0_reg_info =
751  reg_ctx->GetRegisterInfoByName("v0", 0);
752  RegisterValue v0_value;
753  if (reg_ctx->ReadRegister(v0_reg_info, v0_value)) {
754  DataExtractor data;
755  if (v0_value.GetData(data)) {
756  lldb::offset_t offset = 0;
757  if (*byte_size == sizeof(float)) {
758  value.GetScalar() = data.GetFloat(&offset);
759  success = true;
760  } else if (*byte_size == sizeof(double)) {
761  value.GetScalar() = data.GetDouble(&offset);
762  success = true;
763  } else if (*byte_size == sizeof(long double)) {
764  value.GetScalar() = data.GetLongDouble(&offset);
765  success = true;
766  }
767  }
768  }
769  }
770  }
771  }
772 
773  if (success)
774  return_valobj_sp = ValueObjectConstResult::Create(
775  thread.GetStackFrameAtIndex(0).get(), value, ConstString(""));
776  } else if (type_flags & eTypeIsVector) {
777  if (*byte_size > 0) {
778 
779  const RegisterInfo *v0_info = reg_ctx->GetRegisterInfoByName("v0", 0);
780 
781  if (v0_info) {
782  if (*byte_size <= v0_info->byte_size) {
783  std::unique_ptr<DataBufferHeap> heap_data_up(
784  new DataBufferHeap(*byte_size, 0));
785  const ByteOrder byte_order = exe_ctx.GetProcessRef().GetByteOrder();
786  RegisterValue reg_value;
787  if (reg_ctx->ReadRegister(v0_info, reg_value)) {
788  Status error;
789  if (reg_value.GetAsMemoryData(v0_info, heap_data_up->GetBytes(),
790  heap_data_up->GetByteSize(),
791  byte_order, error)) {
792  DataExtractor data(DataBufferSP(heap_data_up.release()),
793  byte_order,
794  exe_ctx.GetProcessRef().GetAddressByteSize());
795  return_valobj_sp = ValueObjectConstResult::Create(
796  &thread, return_compiler_type, ConstString(""), data);
797  }
798  }
799  }
800  }
801  }
802  } else if (type_flags & eTypeIsStructUnion || type_flags & eTypeIsClass) {
803  DataExtractor data;
804 
805  uint32_t NGRN = 0; // Search ABI docs for NGRN
806  uint32_t NSRN = 0; // Search ABI docs for NSRN
807  const bool is_return_value = true;
809  exe_ctx, reg_ctx, return_compiler_type, is_return_value, NGRN, NSRN,
810  data)) {
811  return_valobj_sp = ValueObjectConstResult::Create(
812  &thread, return_compiler_type, ConstString(""), data);
813  }
814  }
815  return return_valobj_sp;
816 }
817 
819  lldb::addr_t pac_sign_extension = 0x0080000000000000ULL;
820  return (pc & pac_sign_extension) ? pc | mask : pc & (~mask);
821 }
822 
824  PluginManager::RegisterPlugin(GetPluginNameStatic(), pluginDesc,
825  CreateInstance);
826 }
827 
829  PluginManager::UnregisterPlugin(CreateInstance);
830 }
lldb_private::RegisterContext::WriteRegister
virtual bool WriteRegister(const RegisterInfo *reg_info, const RegisterValue &reg_value)=0
lldb_private::CompilerType::IsPointerOrReferenceType
bool IsPointerOrReferenceType(CompilerType *pointee_type=nullptr) const
Definition: CompilerType.cpp:166
lldb_private::ExecutionContext
Definition: ExecutionContext.h:292
Scalar.h
lldb_private::UnwindPlan::AppendRow
void AppendRow(const RowSP &row_sp)
Definition: UnwindPlan.cpp:360
lldb_private::ArchSpec
Definition: ArchSpec.h:33
lldb_private::Log::PutString
void PutString(llvm::StringRef str)
Definition: Log.cpp:119
LLDB_REGNUM_GENERIC_ARG1
#define LLDB_REGNUM_GENERIC_ARG1
Definition: lldb-defines.h:68
ABIMacOSX_arm64::CreateInstance
static lldb::ABISP CreateInstance(lldb::ProcessSP process_sp, const lldb_private::ArchSpec &arch)
Definition: ABIMacOSX_arm64.cpp:43
LLDB_INVALID_REGNUM
#define LLDB_INVALID_REGNUM
Definition: lldb-defines.h:91
lldb_private::Process::ReadMemory
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:1925
ABIMacOSX_arm64::CreateFunctionEntryUnwindPlan
bool CreateFunctionEntryUnwindPlan(lldb_private::UnwindPlan &unwind_plan) override
Definition: ABIMacOSX_arm64.cpp:349
lldb_private::RegisterValue
Definition: RegisterValue.h:28
lldb_private::Process::ReadScalarIntegerFromMemory
size_t ReadScalarIntegerFromMemory(lldb::addr_t addr, uint32_t byte_size, bool is_signed, Scalar &scalar, Status &error)
Definition: Process.cpp:2215
lldb_private::UnwindPlan::SetRegisterKind
void SetRegisterKind(lldb::RegisterKind kind)
Definition: UnwindPlan.h:439
lldb::eRegisterKindDWARF
@ eRegisterKindDWARF
the register numbers seen DWARF
Definition: lldb-enumerations.h:229
lldb_private::Value
Definition: Value.h:38
lldb_private::Value::SetValueType
void SetValueType(ValueType value_type)
Definition: Value.h:89
lldb_private::ExecutionContext::GetProcessPtr
Process * GetProcessPtr() const
Returns a pointer to the process object.
Definition: ExecutionContext.cpp:208
lldb::eRegisterKindGeneric
@ eRegisterKindGeneric
insn ptr reg, stack ptr reg, etc not specific to any particular target
Definition: lldb-enumerations.h:230
ABIMacOSX_arm64.h
lldb_private::ValueList::GetValueAtIndex
Value * GetValueAtIndex(size_t idx)
Definition: Value.cpp:679
lldb_private::UnwindPlan::SetUnwindPlanValidAtAllInstructions
void SetUnwindPlanValidAtAllInstructions(lldb_private::LazyBool valid_at_all_insn)
Definition: UnwindPlan.h:492
lldb_private::RegisterContext::ReadRegister
virtual bool ReadRegister(const RegisterInfo *reg_info, RegisterValue &reg_value)=0
LLDB_LOGF
#define LLDB_LOGF(log,...)
Definition: Log.h:249
Module.h
lldb_private::RegisterContext::ConvertRegisterKindToRegisterNumber
virtual uint32_t ConvertRegisterKindToRegisterNumber(lldb::RegisterKind kind, uint32_t num)
Convert from a given register numbering scheme to the lldb register numbering scheme.
Definition: RegisterContext.cpp:268
lldb_private::RegisterContext::ReadRegisterAsUnsigned
uint64_t ReadRegisterAsUnsigned(uint32_t reg, uint64_t fail_value)
Definition: RegisterContext.cpp:188
lldb_private::CompilerType::GetByteSize
llvm::Optional< uint64_t > GetByteSize(ExecutionContextScope *exe_scope) const
Return the size of the type in bytes.
Definition: CompilerType.cpp:489
lldb_private::UnwindPlan::SetUnwindPlanForSignalTrap
void SetUnwindPlanForSignalTrap(lldb_private::LazyBool is_for_signal_trap)
Definition: UnwindPlan.h:504
lldb::offset_t
uint64_t offset_t
Definition: lldb-types.h:87
RegisterValue.h
lldb_private::ValueList
Definition: Value.h:157
lldb_private::ArchSpec::GetTriple
llvm::Triple & GetTriple()
Architecture triple accessor.
Definition: ArchSpec.h:444
lldb::addr_t
uint64_t addr_t
Definition: lldb-types.h:83
pc
@ pc
Definition: CompactUnwindInfo.cpp:1250
ABIMacOSX_arm64::FixAddress
lldb::addr_t FixAddress(lldb::addr_t pc, lldb::addr_t mask) override
Definition: ABIMacOSX_arm64.cpp:818
lldb_private::RegisterContext::GetRegisterInfoAtIndex
virtual const RegisterInfo * GetRegisterInfoAtIndex(size_t reg)=0
lldb_private::UnwindPlan::SetSourceName
void SetSourceName(const char *)
Definition: UnwindPlan.cpp:562
lldb_private::ValueList::GetSize
size_t GetSize()
Definition: Value.cpp:677
lldb_private::DataExtractor::SetData
lldb::offset_t SetData(const void *bytes, lldb::offset_t length, lldb::ByteOrder byte_order)
Set data with a buffer that is caller owned.
Definition: DataExtractor.cpp:225
lldb_private::ExecutionContext::GetProcessRef
Process & GetProcessRef() const
Returns a reference to the process object.
Definition: ExecutionContext.cpp:231
lldb_private::StreamString::GetString
llvm::StringRef GetString() const
Definition: StreamString.cpp:51
Process.h
lldb_private::CompilerType::IsIntegerOrEnumerationType
bool IsIntegerOrEnumerationType(bool &is_signed) const
Definition: CompilerType.cpp:153
lldb_private::Value::SetCompilerType
void SetCompilerType(const CompilerType &compiler_type)
Definition: Value.cpp:254
Target.h
lldb_private::DataExtractor::SetByteOrder
void SetByteOrder(lldb::ByteOrder byte_order)
Set the byte_order value.
Definition: DataExtractor.h:931
lldb_private::Value::GetScalar
const Scalar & GetScalar() const
Definition: Value.h:112
ABIMacOSX_arm64::GetRedZoneSize
size_t GetRedZoneSize() const override
Definition: ABIMacOSX_arm64.cpp:38
lldb_private::CompilerType::IsHomogeneousAggregate
uint32_t IsHomogeneousAggregate(CompilerType *base_type_ptr) const
Definition: CompilerType.cpp:109
LIBLLDB_LOG_EXPRESSIONS
#define LIBLLDB_LOG_EXPRESSIONS
Definition: Logging.h:22
error
static llvm::raw_ostream & error(Stream &strm)
Definition: CommandReturnObject.cpp:17
lldb_private::DataExtractor
Definition: DataExtractor.h:48
Log.h
pluginDesc
static const char * pluginDesc
Definition: ABIMacOSX_arm64.cpp:36
lldb_private::Thread
Definition: Thread.h:60
lldb_private::Status::Fail
bool Fail() const
Test for error condition.
Definition: Status.cpp:182
ABIMacOSX_arm64
Definition: ABIMacOSX_arm64.h:16
lldb_private::DataExtractor::SetAddressByteSize
void SetAddressByteSize(uint32_t addr_size)
Set the address byte size.
Definition: DataExtractor.h:845
lldb_private::DataExtractor::GetDouble
double GetDouble(lldb::offset_t *offset_ptr) const
Definition: DataExtractor.cpp:628
lldb_private::RegisterValue::GetData
bool GetData(DataExtractor &data) const
Definition: RegisterValue.cpp:34
lldb_private::RegisterContext::GetRegisterInfo
const RegisterInfo * GetRegisterInfo(lldb::RegisterKind reg_kind, uint32_t reg_num)
Definition: RegisterContext.cpp:80
lldb_private::UnwindPlan::SetSourcedFromCompiler
void SetSourcedFromCompiler(lldb_private::LazyBool from_compiler)
Definition: UnwindPlan.h:480
lldb_private::Process::GetAddressByteSize
uint32_t GetAddressByteSize() const
Definition: Process.cpp:3306
lldb_private::ConstString
Definition: ConstString.h:40
lldb_private::StreamString
Definition: StreamString.h:23
lldb_private::GetLogIfAllCategoriesSet
Log * GetLogIfAllCategoriesSet(uint32_t mask)
Definition: Logging.cpp:58
sp
@ sp
Definition: CompactUnwindInfo.cpp:1249
arm64_dwarf::sp
@ sp
Definition: ARM64_DWARF_Registers.h:51
lldb_private::DataExtractor::GetFloat
float GetFloat(lldb::offset_t *offset_ptr) const
Extract a float from *offset_ptr.
Definition: DataExtractor.cpp:624
arm64_dwarf::pc
@ pc
Definition: ARM64_DWARF_Registers.h:52
Thread.h
UnwindPlan.h
lldb_private::RegisterContext::GetSP
uint64_t GetSP(uint64_t fail_value=LLDB_INVALID_ADDRESS)
Definition: RegisterContext.cpp:152
lldb_private::RegisterContext
Definition: RegisterContext.h:17
ABIMacOSX_arm64::SetReturnValueObject
lldb_private::Status SetReturnValueObject(lldb::StackFrameSP &frame_sp, lldb::ValueObjectSP &new_value) override
Definition: ABIMacOSX_arm64.cpp:237
lldb_private::UserID::GetID
lldb::user_id_t GetID() const
Get accessor for the user ID.
Definition: UserID.h:47
ARM64_DWARF_Registers.h
ValueObjectConstResult.h
lldb_private::UnwindPlan::RowSP
std::shared_ptr< Row > RowSP
Definition: UnwindPlan.h:395
lldb_private::RegisterValue::SetValueFromData
Status SetValueFromData(const RegisterInfo *reg_info, DataExtractor &data, lldb::offset_t offset, bool partial_data_ok)
Definition: RegisterValue.cpp:172
lldb_private::UnwindPlan::Clear
void Clear()
Definition: UnwindPlan.h:510
lldb_private::Status
Definition: Status.h:44
lldb_private::RegisterContext::WriteRegisterFromUnsigned
bool WriteRegisterFromUnsigned(uint32_t reg, uint64_t uval)
Definition: RegisterContext.cpp:205
lldb_private::UnwindPlan::Row
Definition: UnwindPlan.h:55
uint32_t
lldb_private::eLazyBoolNo
@ eLazyBoolNo
Definition: lldb-private-enumerations.h:115
ABIMacOSX_arm64::GetArgumentValues
bool GetArgumentValues(lldb_private::Thread &thread, lldb_private::ValueList &values) const override
Definition: ABIMacOSX_arm64.cpp:119
lldb_private::ExecutionContext::GetBestExecutionContextScope
ExecutionContextScope * GetBestExecutionContextScope() const
Definition: ExecutionContext.cpp:216
LLDB_REGNUM_GENERIC_SP
#define LLDB_REGNUM_GENERIC_SP
Definition: lldb-defines.h:64
lldb_private::DataExtractor::GetMaxU64
uint64_t GetMaxU64(lldb::offset_t *offset_ptr, size_t byte_size) const
Extract an unsigned integer of size byte_size from *offset_ptr.
Definition: DataExtractor.cpp:526
lldb_private::RegisterValue::GetAsMemoryData
uint32_t GetAsMemoryData(const RegisterInfo *reg_info, void *dst, uint32_t dst_len, lldb::ByteOrder dst_byte_order, Status &error) const
Definition: RegisterValue.cpp:38
lldb_private::CompilerType::GetBitSize
llvm::Optional< uint64_t > GetBitSize(ExecutionContextScope *exe_scope) const
Return the size of the type in bits.
Definition: CompilerType.cpp:482
LoadValueFromConsecutiveGPRRegisters
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)
Definition: ABIMacOSX_arm64.cpp:489
lldb_private::CompilerType::GetTypeInfo
uint32_t GetTypeInfo(CompilerType *pointee_or_element_compiler_type=nullptr) const
Definition: CompilerType.cpp:290
UINT32_MAX
#define UINT32_MAX
Definition: lldb-defines.h:31
uint16_t
PluginManager.h
LLDB_INVALID_ADDRESS
#define LLDB_INVALID_ADDRESS
Definition: lldb-defines.h:86
lldb_private::CompilerType
Generic representation of a type in a programming language.
Definition: CompilerType.h:33
lldb_private::Stream::Printf
size_t Printf(const char *format,...) __attribute__((format(printf
Output printf formatted output to the stream.
Definition: Stream.cpp:107
lldb_private::Value::GetCompilerType
const CompilerType & GetCompilerType()
Definition: Value.cpp:225
Status.h
lldb_private
A class that represents a running process on the host machine.
Definition: SBCommandInterpreterRunOptions.h:16
ABIMacOSX_arm64::GetReturnValueObjectImpl
lldb::ValueObjectSP GetReturnValueObjectImpl(lldb_private::Thread &thread, lldb_private::CompilerType &ast_type) const override
Definition: ABIMacOSX_arm64.cpp:635
lldb_private::DataExtractor::GetLongDouble
long double GetLongDouble(lldb::offset_t *offset_ptr) const
Definition: DataExtractor.cpp:632
ABIMacOSX_arm64::RegisterIsVolatile
bool RegisterIsVolatile(const lldb_private::RegisterInfo *reg_info) override
Definition: ABIMacOSX_arm64.cpp:410
LLDB_REGNUM_GENERIC_PC
#define LLDB_REGNUM_GENERIC_PC
Definition: lldb-defines.h:63
ConstString.h
lldb_private::RegisterValue::SignExtend
bool SignExtend(uint32_t sign_bitpos)
Definition: RegisterValue.cpp:459
lldb_private::Process::GetByteOrder
lldb::ByteOrder GetByteOrder() const
Definition: Process.cpp:3302
lldb_private::Log
Definition: Log.h:49
lldb_private::Stream::PutCString
size_t PutCString(llvm::StringRef cstr)
Output a C string to the stream.
Definition: Stream.cpp:63
ABIMacOSX_arm64::Terminate
static void Terminate()
Definition: ABIMacOSX_arm64.cpp:828
lldb_private::Thread::GetStackFrameAtIndex
virtual lldb::StackFrameSP GetStackFrameAtIndex(uint32_t idx)
Definition: Thread.h:397
ABIMacOSX_arm64::PrepareTrivialCall
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
Definition: ABIMacOSX_arm64.cpp:58
lldb_private::Thread::GetRegisterContext
virtual lldb::RegisterContextSP GetRegisterContext()=0
lldb_private::DataBufferHeap
Definition: DataBufferHeap.h:30
lldb_private::UnwindPlan
Definition: UnwindPlan.h:53
ABIMacOSX_arm64::CreateDefaultUnwindPlan
bool CreateDefaultUnwindPlan(lldb_private::UnwindPlan &unwind_plan) override
Definition: ABIMacOSX_arm64.cpp:375
lldb
Definition: SBAddress.h:15
arm64_dwarf::fp
@ fp
Definition: ARM64_DWARF_Registers.h:47
RegisterContext.h
Value.h
lldb_private::RegisterValue::GetScalarValue
bool GetScalarValue(Scalar &scalar) const
Definition: RegisterValue.cpp:136
arm64_dwarf::lr
@ lr
Definition: ARM64_DWARF_Registers.h:49
lldb_private::ExecutionContext::GetTargetPtr
Target * GetTargetPtr() const
Returns a pointer to the target object.
Definition: ExecutionContext.cpp:200
lldb_private::RegisterContext::GetRegisterInfoByName
const RegisterInfo * GetRegisterInfoByName(llvm::StringRef reg_name, uint32_t start_idx=0)
Definition: RegisterContext.cpp:52
ABIMacOSX_arm64::Initialize
static void Initialize()
Definition: ABIMacOSX_arm64.cpp:823
lldb::ByteOrder
ByteOrder
Byte ordering definitions.
Definition: lldb-enumerations.h:138
lldb_private::Status::AsCString
const char * AsCString(const char *default_error_str="unknown error") const
Get the error string associated with the current error.
Definition: Status.cpp:131
LLDB_REGNUM_GENERIC_RA
#define LLDB_REGNUM_GENERIC_RA
Definition: lldb-defines.h:66