1 //===-- ABIMacOSX_arm64.cpp -----------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
9 #include "ABIMacOSX_arm64.h"
14 #include "llvm/ADT/STLExtras.h"
15 #include "llvm/TargetParser/Triple.h"
17 #include "lldb/Core/Module.h"
18 #include "lldb/Core/PluginManager.h"
19 #include "lldb/Core/Value.h"
20 #include "lldb/Core/ValueObjectConstResult.h"
21 #include "lldb/Symbol/UnwindPlan.h"
22 #include "lldb/Target/Process.h"
23 #include "lldb/Target/RegisterContext.h"
24 #include "lldb/Target/Target.h"
25 #include "lldb/Target/Thread.h"
26 #include "lldb/Utility/ConstString.h"
27 #include "lldb/Utility/LLDBLog.h"
28 #include "lldb/Utility/Log.h"
29 #include "lldb/Utility/RegisterValue.h"
30 #include "lldb/Utility/Scalar.h"
31 #include "lldb/Utility/Status.h"
33 #include "Utility/ARM64_DWARF_Registers.h"
36 using namespace lldb_private
;
38 static const char *pluginDesc
= "Mac OS X ABI for arm64 targets";
40 size_t ABIMacOSX_arm64::GetRedZoneSize() const { return 128; }
45 ABIMacOSX_arm64::CreateInstance(ProcessSP process_sp
, const ArchSpec
&arch
) {
46 const llvm::Triple::ArchType arch_type
= arch
.GetTriple().getArch();
47 const llvm::Triple::VendorType vendor_type
= arch
.GetTriple().getVendor();
49 if (vendor_type
== llvm::Triple::Apple
) {
50 if (arch_type
== llvm::Triple::aarch64
||
51 arch_type
== llvm::Triple::aarch64_32
) {
53 new ABIMacOSX_arm64(std::move(process_sp
), MakeMCRegisterInfo(arch
)));
60 bool ABIMacOSX_arm64::PrepareTrivialCall(
61 Thread
&thread
, lldb::addr_t sp
, lldb::addr_t func_addr
,
62 lldb::addr_t return_addr
, llvm::ArrayRef
<lldb::addr_t
> args
) const {
63 RegisterContext
*reg_ctx
= thread
.GetRegisterContext().get();
67 Log
*log
= GetLog(LLDBLog::Expressions
);
71 s
.Printf("ABIMacOSX_arm64::PrepareTrivialCall (tid = 0x%" PRIx64
72 ", sp = 0x%" PRIx64
", func_addr = 0x%" PRIx64
73 ", return_addr = 0x%" PRIx64
,
74 thread
.GetID(), (uint64_t)sp
, (uint64_t)func_addr
,
75 (uint64_t)return_addr
);
77 for (size_t i
= 0; i
< args
.size(); ++i
)
78 s
.Printf(", arg%d = 0x%" PRIx64
, static_cast<int>(i
+ 1), args
[i
]);
80 log
->PutString(s
.GetString());
83 const uint32_t pc_reg_num
= reg_ctx
->ConvertRegisterKindToRegisterNumber(
84 eRegisterKindGeneric
, LLDB_REGNUM_GENERIC_PC
);
85 const uint32_t sp_reg_num
= reg_ctx
->ConvertRegisterKindToRegisterNumber(
86 eRegisterKindGeneric
, LLDB_REGNUM_GENERIC_SP
);
87 const uint32_t ra_reg_num
= reg_ctx
->ConvertRegisterKindToRegisterNumber(
88 eRegisterKindGeneric
, LLDB_REGNUM_GENERIC_RA
);
90 // x0 - x7 contain first 8 simple args
91 if (args
.size() > 8) // TODO handle more than 8 arguments
94 for (size_t i
= 0; i
< args
.size(); ++i
) {
95 const RegisterInfo
*reg_info
= reg_ctx
->GetRegisterInfo(
96 eRegisterKindGeneric
, LLDB_REGNUM_GENERIC_ARG1
+ i
);
97 LLDB_LOGF(log
, "About to write arg%d (0x%" PRIx64
") into %s",
98 static_cast<int>(i
+ 1), args
[i
], reg_info
->name
);
99 if (!reg_ctx
->WriteRegisterFromUnsigned(reg_info
, args
[i
]))
103 // Set "lr" to the return address
104 if (!reg_ctx
->WriteRegisterFromUnsigned(
105 reg_ctx
->GetRegisterInfoAtIndex(ra_reg_num
), return_addr
))
108 // Set "sp" to the requested value
109 if (!reg_ctx
->WriteRegisterFromUnsigned(
110 reg_ctx
->GetRegisterInfoAtIndex(sp_reg_num
), sp
))
113 // Set "pc" to the address requested
114 if (!reg_ctx
->WriteRegisterFromUnsigned(
115 reg_ctx
->GetRegisterInfoAtIndex(pc_reg_num
), func_addr
))
121 bool ABIMacOSX_arm64::GetArgumentValues(Thread
&thread
,
122 ValueList
&values
) const {
123 uint32_t num_values
= values
.GetSize();
125 ExecutionContext
exe_ctx(thread
.shared_from_this());
127 // Extract the register context so we can read arguments from registers
129 RegisterContext
*reg_ctx
= thread
.GetRegisterContext().get();
136 for (uint32_t value_idx
= 0; value_idx
< num_values
; ++value_idx
) {
137 // We currently only support extracting values with Clang QualTypes. Do we
138 // care about others?
139 Value
*value
= values
.GetValueAtIndex(value_idx
);
144 CompilerType value_type
= value
->GetCompilerType();
145 std::optional
<uint64_t> bit_size
= value_type
.GetBitSize(&thread
);
149 bool is_signed
= false;
150 size_t bit_width
= 0;
151 if (value_type
.IsIntegerOrEnumerationType(is_signed
)) {
152 bit_width
= *bit_size
;
153 } else if (value_type
.IsPointerOrReferenceType()) {
154 bit_width
= *bit_size
;
156 // We only handle integer, pointer and reference types currently...
160 if (bit_width
<= (exe_ctx
.GetProcessRef().GetAddressByteSize() * 8)) {
162 // Arguments 1-6 are in x0-x5...
163 const RegisterInfo
*reg_info
= nullptr;
164 // Search by generic ID first, then fall back to by name
165 uint32_t arg_reg_num
= reg_ctx
->ConvertRegisterKindToRegisterNumber(
166 eRegisterKindGeneric
, LLDB_REGNUM_GENERIC_ARG1
+ value_idx
);
167 if (arg_reg_num
!= LLDB_INVALID_REGNUM
) {
168 reg_info
= reg_ctx
->GetRegisterInfoAtIndex(arg_reg_num
);
172 reg_info
= reg_ctx
->GetRegisterInfoByName("x0");
175 reg_info
= reg_ctx
->GetRegisterInfoByName("x1");
178 reg_info
= reg_ctx
->GetRegisterInfoByName("x2");
181 reg_info
= reg_ctx
->GetRegisterInfoByName("x3");
184 reg_info
= reg_ctx
->GetRegisterInfoByName("x4");
187 reg_info
= reg_ctx
->GetRegisterInfoByName("x5");
190 reg_info
= reg_ctx
->GetRegisterInfoByName("x6");
193 reg_info
= reg_ctx
->GetRegisterInfoByName("x7");
199 RegisterValue reg_value
;
201 if (reg_ctx
->ReadRegister(reg_info
, reg_value
)) {
203 reg_value
.SignExtend(bit_width
);
204 if (!reg_value
.GetScalarValue(value
->GetScalar()))
212 // Read the stack pointer if we already haven't read it
213 sp
= reg_ctx
->GetSP(0);
218 // Arguments 5 on up are on the stack
219 const uint32_t arg_byte_size
= (bit_width
+ (8 - 1)) / 8;
221 if (!exe_ctx
.GetProcessRef().ReadScalarIntegerFromMemory(
222 sp
, arg_byte_size
, is_signed
, value
->GetScalar(), error
))
226 // Align up to the next 8 byte boundary if needed
239 ABIMacOSX_arm64::SetReturnValueObject(lldb::StackFrameSP
&frame_sp
,
240 lldb::ValueObjectSP
&new_value_sp
) {
243 error
.SetErrorString("Empty value object for return value.");
247 CompilerType return_value_type
= new_value_sp
->GetCompilerType();
248 if (!return_value_type
) {
249 error
.SetErrorString("Null clang type for return value.");
253 Thread
*thread
= frame_sp
->GetThread().get();
255 RegisterContext
*reg_ctx
= thread
->GetRegisterContext().get();
260 const uint64_t byte_size
= new_value_sp
->GetData(data
, data_error
);
261 if (data_error
.Fail()) {
262 error
.SetErrorStringWithFormat(
263 "Couldn't convert return value to raw data: %s",
264 data_error
.AsCString());
268 const uint32_t type_flags
= return_value_type
.GetTypeInfo(nullptr);
269 if (type_flags
& eTypeIsScalar
|| type_flags
& eTypeIsPointer
) {
270 if (type_flags
& eTypeIsInteger
|| type_flags
& eTypeIsPointer
) {
271 // Extract the register context so we can read arguments from registers
272 lldb::offset_t offset
= 0;
273 if (byte_size
<= 16) {
274 const RegisterInfo
*x0_info
= reg_ctx
->GetRegisterInfoByName("x0", 0);
275 if (byte_size
<= 8) {
276 uint64_t raw_value
= data
.GetMaxU64(&offset
, byte_size
);
278 if (!reg_ctx
->WriteRegisterFromUnsigned(x0_info
, raw_value
))
279 error
.SetErrorString("failed to write register x0");
281 uint64_t raw_value
= data
.GetMaxU64(&offset
, 8);
283 if (reg_ctx
->WriteRegisterFromUnsigned(x0_info
, raw_value
)) {
284 const RegisterInfo
*x1_info
=
285 reg_ctx
->GetRegisterInfoByName("x1", 0);
286 raw_value
= data
.GetMaxU64(&offset
, byte_size
- offset
);
288 if (!reg_ctx
->WriteRegisterFromUnsigned(x1_info
, raw_value
))
289 error
.SetErrorString("failed to write register x1");
293 error
.SetErrorString("We don't support returning longer than 128 bit "
294 "integer values at present.");
296 } else if (type_flags
& eTypeIsFloat
) {
297 if (type_flags
& eTypeIsComplex
) {
298 // Don't handle complex yet.
299 error
.SetErrorString(
300 "returning complex float values are not supported");
302 const RegisterInfo
*v0_info
= reg_ctx
->GetRegisterInfoByName("v0", 0);
305 if (byte_size
<= 16) {
306 RegisterValue reg_value
;
307 error
= reg_value
.SetValueFromData(*v0_info
, data
, 0, true);
309 if (!reg_ctx
->WriteRegister(v0_info
, reg_value
))
310 error
.SetErrorString("failed to write register v0");
312 error
.SetErrorString("returning float values longer than 128 "
313 "bits are not supported");
316 error
.SetErrorString("v0 register is not available on this target");
319 } else if (type_flags
& eTypeIsVector
) {
321 const RegisterInfo
*v0_info
= reg_ctx
->GetRegisterInfoByName("v0", 0);
324 if (byte_size
<= v0_info
->byte_size
) {
325 RegisterValue reg_value
;
326 error
= reg_value
.SetValueFromData(*v0_info
, data
, 0, true);
327 if (error
.Success()) {
328 if (!reg_ctx
->WriteRegister(v0_info
, reg_value
))
329 error
.SetErrorString("failed to write register v0");
336 error
.SetErrorString("no registers are available");
342 bool ABIMacOSX_arm64::CreateFunctionEntryUnwindPlan(UnwindPlan
&unwind_plan
) {
344 unwind_plan
.SetRegisterKind(eRegisterKindDWARF
);
346 uint32_t lr_reg_num
= arm64_dwarf::lr
;
347 uint32_t sp_reg_num
= arm64_dwarf::sp
;
348 uint32_t pc_reg_num
= arm64_dwarf::pc
;
350 UnwindPlan::RowSP
row(new UnwindPlan::Row
);
352 // Our previous Call Frame Address is the stack pointer
353 row
->GetCFAValue().SetIsRegisterPlusOffset(sp_reg_num
, 0);
355 // Our previous PC is in the LR
356 row
->SetRegisterLocationToRegister(pc_reg_num
, lr_reg_num
, true);
358 unwind_plan
.AppendRow(row
);
360 // All other registers are the same.
362 unwind_plan
.SetSourceName("arm64 at-func-entry default");
363 unwind_plan
.SetSourcedFromCompiler(eLazyBoolNo
);
368 bool ABIMacOSX_arm64::CreateDefaultUnwindPlan(UnwindPlan
&unwind_plan
) {
370 unwind_plan
.SetRegisterKind(eRegisterKindDWARF
);
372 uint32_t fp_reg_num
= arm64_dwarf::fp
;
373 uint32_t pc_reg_num
= arm64_dwarf::pc
;
375 UnwindPlan::RowSP
row(new UnwindPlan::Row
);
376 const int32_t ptr_size
= 8;
378 row
->GetCFAValue().SetIsRegisterPlusOffset(fp_reg_num
, 2 * ptr_size
);
380 row
->SetUnspecifiedRegistersAreUndefined(true);
382 row
->SetRegisterLocationToAtCFAPlusOffset(fp_reg_num
, ptr_size
* -2, true);
383 row
->SetRegisterLocationToAtCFAPlusOffset(pc_reg_num
, ptr_size
* -1, true);
385 unwind_plan
.AppendRow(row
);
386 unwind_plan
.SetSourceName("arm64-apple-darwin default unwind plan");
387 unwind_plan
.SetSourcedFromCompiler(eLazyBoolNo
);
388 unwind_plan
.SetUnwindPlanValidAtAllInstructions(eLazyBoolNo
);
389 unwind_plan
.SetUnwindPlanForSignalTrap(eLazyBoolNo
);
393 // AAPCS64 (Procedure Call Standard for the ARM 64-bit Architecture) says
394 // registers x19 through x28 and sp are callee preserved. v8-v15 are non-
395 // volatile (and specifically only the lower 8 bytes of these regs), the rest
396 // of the fp/SIMD registers are volatile.
398 // v. https://github.com/ARM-software/abi-aa/blob/main/aapcs64/
400 // We treat x29 as callee preserved also, else the unwinder won't try to
401 // retrieve fp saves.
403 bool ABIMacOSX_arm64::RegisterIsVolatile(const RegisterInfo
*reg_info
) {
405 const char *name
= reg_info
->name
;
407 // Sometimes we'll be called with the "alternate" name for these registers;
408 // recognize them as non-volatile.
410 if (name
[0] == 'p' && name
[1] == 'c') // pc
412 if (name
[0] == 'f' && name
[1] == 'p') // fp
414 if (name
[0] == 's' && name
[1] == 'p') // sp
416 if (name
[0] == 'l' && name
[1] == 'r') // lr
419 if (name
[0] == 'x') {
420 // Volatile registers: x0-x18, x30 (lr)
421 // Return false for the non-volatile gpr regs, true for everything else
426 return false; // x19 is non-volatile
442 return false; // x20 - 28 are non-volatile
444 return false; // x29 aka fp treat as non-volatile on Darwin
448 case '3': // x30 aka lr treat as non-volatile
455 } else if (name
[0] == 'v' || name
[0] == 's' || name
[0] == 'd') {
456 // Volatile registers: v0-7, v16-v31
457 // Return false for non-volatile fp/SIMD regs, true for everything else
461 return false; // v8-v9 are non-volatile
470 return false; // v10-v15 are non-volatile
482 static bool LoadValueFromConsecutiveGPRRegisters(
483 ExecutionContext
&exe_ctx
, RegisterContext
*reg_ctx
,
484 const CompilerType
&value_type
,
485 bool is_return_value
, // false => parameter, true => return value
486 uint32_t &NGRN
, // NGRN (see ABI documentation)
487 uint32_t &NSRN
, // NSRN (see ABI documentation)
488 DataExtractor
&data
) {
489 std::optional
<uint64_t> byte_size
=
490 value_type
.GetByteSize(exe_ctx
.GetBestExecutionContextScope());
491 if (!byte_size
|| *byte_size
== 0)
494 std::unique_ptr
<DataBufferHeap
> heap_data_up(
495 new DataBufferHeap(*byte_size
, 0));
496 const ByteOrder byte_order
= exe_ctx
.GetProcessRef().GetByteOrder();
499 CompilerType base_type
;
500 const uint32_t homogeneous_count
=
501 value_type
.IsHomogeneousAggregate(&base_type
);
502 if (homogeneous_count
> 0 && homogeneous_count
<= 8) {
503 // Make sure we have enough registers
504 if (NSRN
< 8 && (8 - NSRN
) >= homogeneous_count
) {
507 std::optional
<uint64_t> base_byte_size
=
508 base_type
.GetByteSize(exe_ctx
.GetBestExecutionContextScope());
511 uint32_t data_offset
= 0;
513 for (uint32_t i
= 0; i
< homogeneous_count
; ++i
) {
515 ::snprintf(v_name
, sizeof(v_name
), "v%u", NSRN
);
516 const RegisterInfo
*reg_info
=
517 reg_ctx
->GetRegisterInfoByName(v_name
, 0);
518 if (reg_info
== nullptr)
521 if (*base_byte_size
> reg_info
->byte_size
)
524 RegisterValue reg_value
;
526 if (!reg_ctx
->ReadRegister(reg_info
, reg_value
))
529 // Make sure we have enough room in "heap_data_up"
530 if ((data_offset
+ *base_byte_size
) <= heap_data_up
->GetByteSize()) {
531 const size_t bytes_copied
= reg_value
.GetAsMemoryData(
532 *reg_info
, heap_data_up
->GetBytes() + data_offset
,
533 *base_byte_size
, byte_order
, error
);
534 if (bytes_copied
!= *base_byte_size
)
536 data_offset
+= bytes_copied
;
541 data
.SetByteOrder(byte_order
);
542 data
.SetAddressByteSize(exe_ctx
.GetProcessRef().GetAddressByteSize());
543 data
.SetData(DataBufferSP(heap_data_up
.release()));
548 const size_t max_reg_byte_size
= 16;
549 if (*byte_size
<= max_reg_byte_size
) {
550 size_t bytes_left
= *byte_size
;
551 uint32_t data_offset
= 0;
552 while (data_offset
< *byte_size
) {
556 uint32_t reg_num
= reg_ctx
->ConvertRegisterKindToRegisterNumber(
557 eRegisterKindGeneric
, LLDB_REGNUM_GENERIC_ARG1
+ NGRN
);
558 if (reg_num
== LLDB_INVALID_REGNUM
)
561 const RegisterInfo
*reg_info
= reg_ctx
->GetRegisterInfoAtIndex(reg_num
);
562 if (reg_info
== nullptr)
565 RegisterValue reg_value
;
567 if (!reg_ctx
->ReadRegister(reg_info
, reg_value
))
570 const size_t curr_byte_size
= std::min
<size_t>(8, bytes_left
);
571 const size_t bytes_copied
= reg_value
.GetAsMemoryData(
572 *reg_info
, heap_data_up
->GetBytes() + data_offset
, curr_byte_size
,
574 if (bytes_copied
== 0)
576 if (bytes_copied
>= bytes_left
)
578 data_offset
+= bytes_copied
;
579 bytes_left
-= bytes_copied
;
583 const RegisterInfo
*reg_info
= nullptr;
584 if (is_return_value
) {
585 // The Darwin arm64 ABI doesn't write the return location back to x8
586 // before returning from the function the way the x86_64 ABI does. So
587 // we can't reconstruct stack based returns on exit from the function:
590 // We are assuming we are stopped at the first instruction in a function
591 // and that the ABI is being respected so all parameters appear where
592 // they should be (functions with no external linkage can legally violate
597 uint32_t reg_num
= reg_ctx
->ConvertRegisterKindToRegisterNumber(
598 eRegisterKindGeneric
, LLDB_REGNUM_GENERIC_ARG1
+ NGRN
);
599 if (reg_num
== LLDB_INVALID_REGNUM
)
601 reg_info
= reg_ctx
->GetRegisterInfoAtIndex(reg_num
);
602 if (reg_info
== nullptr)
607 const lldb::addr_t value_addr
=
608 reg_ctx
->ReadRegisterAsUnsigned(reg_info
, LLDB_INVALID_ADDRESS
);
610 if (value_addr
== LLDB_INVALID_ADDRESS
)
613 if (exe_ctx
.GetProcessRef().ReadMemory(
614 value_addr
, heap_data_up
->GetBytes(), heap_data_up
->GetByteSize(),
615 error
) != heap_data_up
->GetByteSize()) {
620 data
.SetByteOrder(byte_order
);
621 data
.SetAddressByteSize(exe_ctx
.GetProcessRef().GetAddressByteSize());
622 data
.SetData(DataBufferSP(heap_data_up
.release()));
626 ValueObjectSP
ABIMacOSX_arm64::GetReturnValueObjectImpl(
627 Thread
&thread
, CompilerType
&return_compiler_type
) const {
628 ValueObjectSP return_valobj_sp
;
631 ExecutionContext
exe_ctx(thread
.shared_from_this());
632 if (exe_ctx
.GetTargetPtr() == nullptr || exe_ctx
.GetProcessPtr() == nullptr)
633 return return_valobj_sp
;
635 // value.SetContext (Value::eContextTypeClangType, return_compiler_type);
636 value
.SetCompilerType(return_compiler_type
);
638 RegisterContext
*reg_ctx
= thread
.GetRegisterContext().get();
640 return return_valobj_sp
;
642 std::optional
<uint64_t> byte_size
= return_compiler_type
.GetByteSize(&thread
);
644 return return_valobj_sp
;
646 const uint32_t type_flags
= return_compiler_type
.GetTypeInfo(nullptr);
647 if (type_flags
& eTypeIsScalar
|| type_flags
& eTypeIsPointer
) {
648 value
.SetValueType(Value::ValueType::Scalar
);
650 bool success
= false;
651 if (type_flags
& eTypeIsInteger
|| type_flags
& eTypeIsPointer
) {
652 // Extract the register context so we can read arguments from registers
653 if (*byte_size
<= 8) {
654 const RegisterInfo
*x0_reg_info
=
655 reg_ctx
->GetRegisterInfoByName("x0", 0);
658 thread
.GetRegisterContext()->ReadRegisterAsUnsigned(x0_reg_info
,
660 const bool is_signed
= (type_flags
& eTypeIsSigned
) != 0;
661 switch (*byte_size
) {
664 case 16: // uint128_t
665 // In register x0 and x1
667 const RegisterInfo
*x1_reg_info
=
668 reg_ctx
->GetRegisterInfoByName("x1", 0);
672 x0_reg_info
->byte_size
+ x1_reg_info
->byte_size
) {
673 std::unique_ptr
<DataBufferHeap
> heap_data_up(
674 new DataBufferHeap(*byte_size
, 0));
675 const ByteOrder byte_order
=
676 exe_ctx
.GetProcessRef().GetByteOrder();
677 RegisterValue x0_reg_value
;
678 RegisterValue x1_reg_value
;
679 if (reg_ctx
->ReadRegister(x0_reg_info
, x0_reg_value
) &&
680 reg_ctx
->ReadRegister(x1_reg_info
, x1_reg_value
)) {
682 if (x0_reg_value
.GetAsMemoryData(
683 *x0_reg_info
, heap_data_up
->GetBytes() + 0, 8,
684 byte_order
, error
) &&
685 x1_reg_value
.GetAsMemoryData(
686 *x1_reg_info
, heap_data_up
->GetBytes() + 8, 8,
687 byte_order
, error
)) {
689 DataBufferSP(heap_data_up
.release()), byte_order
,
690 exe_ctx
.GetProcessRef().GetAddressByteSize());
692 return_valobj_sp
= ValueObjectConstResult::Create(
693 &thread
, return_compiler_type
, ConstString(""), data
);
694 return return_valobj_sp
;
701 case sizeof(uint64_t):
703 value
.GetScalar() = (int64_t)(raw_value
);
705 value
.GetScalar() = (uint64_t)(raw_value
);
709 case sizeof(uint32_t):
711 value
.GetScalar() = (int32_t)(raw_value
& UINT32_MAX
);
713 value
.GetScalar() = (uint32_t)(raw_value
& UINT32_MAX
);
717 case sizeof(uint16_t):
719 value
.GetScalar() = (int16_t)(raw_value
& UINT16_MAX
);
721 value
.GetScalar() = (uint16_t)(raw_value
& UINT16_MAX
);
725 case sizeof(uint8_t):
727 value
.GetScalar() = (int8_t)(raw_value
& UINT8_MAX
);
729 value
.GetScalar() = (uint8_t)(raw_value
& UINT8_MAX
);
735 } else if (type_flags
& eTypeIsFloat
) {
736 if (type_flags
& eTypeIsComplex
) {
737 // Don't handle complex yet.
739 if (*byte_size
<= sizeof(long double)) {
740 const RegisterInfo
*v0_reg_info
=
741 reg_ctx
->GetRegisterInfoByName("v0", 0);
742 RegisterValue v0_value
;
743 if (reg_ctx
->ReadRegister(v0_reg_info
, v0_value
)) {
745 if (v0_value
.GetData(data
)) {
746 lldb::offset_t offset
= 0;
747 if (*byte_size
== sizeof(float)) {
748 value
.GetScalar() = data
.GetFloat(&offset
);
750 } else if (*byte_size
== sizeof(double)) {
751 value
.GetScalar() = data
.GetDouble(&offset
);
753 } else if (*byte_size
== sizeof(long double)) {
754 value
.GetScalar() = data
.GetLongDouble(&offset
);
764 return_valobj_sp
= ValueObjectConstResult::Create(
765 thread
.GetStackFrameAtIndex(0).get(), value
, ConstString(""));
766 } else if (type_flags
& eTypeIsVector
) {
767 if (*byte_size
> 0) {
769 const RegisterInfo
*v0_info
= reg_ctx
->GetRegisterInfoByName("v0", 0);
772 if (*byte_size
<= v0_info
->byte_size
) {
773 std::unique_ptr
<DataBufferHeap
> heap_data_up(
774 new DataBufferHeap(*byte_size
, 0));
775 const ByteOrder byte_order
= exe_ctx
.GetProcessRef().GetByteOrder();
776 RegisterValue reg_value
;
777 if (reg_ctx
->ReadRegister(v0_info
, reg_value
)) {
779 if (reg_value
.GetAsMemoryData(*v0_info
, heap_data_up
->GetBytes(),
780 heap_data_up
->GetByteSize(),
781 byte_order
, error
)) {
782 DataExtractor
data(DataBufferSP(heap_data_up
.release()),
784 exe_ctx
.GetProcessRef().GetAddressByteSize());
785 return_valobj_sp
= ValueObjectConstResult::Create(
786 &thread
, return_compiler_type
, ConstString(""), data
);
792 } else if (type_flags
& eTypeIsStructUnion
|| type_flags
& eTypeIsClass
) {
795 uint32_t NGRN
= 0; // Search ABI docs for NGRN
796 uint32_t NSRN
= 0; // Search ABI docs for NSRN
797 const bool is_return_value
= true;
798 if (LoadValueFromConsecutiveGPRRegisters(
799 exe_ctx
, reg_ctx
, return_compiler_type
, is_return_value
, NGRN
, NSRN
,
801 return_valobj_sp
= ValueObjectConstResult::Create(
802 &thread
, return_compiler_type
, ConstString(""), data
);
805 return return_valobj_sp
;
808 addr_t
ABIMacOSX_arm64::FixCodeAddress(addr_t pc
) {
809 addr_t pac_sign_extension
= 0x0080000000000000ULL
;
810 addr_t tbi_mask
= 0xff80000000000000ULL
;
813 if (ProcessSP process_sp
= GetProcessSP()) {
814 mask
= process_sp
->GetCodeAddressMask();
815 if (pc
& pac_sign_extension
) {
816 addr_t highmem_mask
= process_sp
->GetHighmemCodeAddressMask();
824 return (pc
& pac_sign_extension
) ? pc
| mask
: pc
& (~mask
);
827 addr_t
ABIMacOSX_arm64::FixDataAddress(addr_t pc
) {
828 addr_t pac_sign_extension
= 0x0080000000000000ULL
;
829 addr_t tbi_mask
= 0xff80000000000000ULL
;
832 if (ProcessSP process_sp
= GetProcessSP()) {
833 mask
= process_sp
->GetDataAddressMask();
834 if (pc
& pac_sign_extension
) {
835 addr_t highmem_mask
= process_sp
->GetHighmemDataAddressMask();
843 return (pc
& pac_sign_extension
) ? pc
| mask
: pc
& (~mask
);
846 void ABIMacOSX_arm64::Initialize() {
847 PluginManager::RegisterPlugin(GetPluginNameStatic(), pluginDesc
,
851 void ABIMacOSX_arm64::Terminate() {
852 PluginManager::UnregisterPlugin(CreateInstance
);