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/Symbol/UnwindPlan.h"
21 #include "lldb/Target/Process.h"
22 #include "lldb/Target/RegisterContext.h"
23 #include "lldb/Target/Target.h"
24 #include "lldb/Target/Thread.h"
25 #include "lldb/Utility/ConstString.h"
26 #include "lldb/Utility/LLDBLog.h"
27 #include "lldb/Utility/Log.h"
28 #include "lldb/Utility/RegisterValue.h"
29 #include "lldb/Utility/Scalar.h"
30 #include "lldb/Utility/Status.h"
31 #include "lldb/ValueObject/ValueObjectConstResult.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
= Status::FromErrorString("Empty value object for return value.");
247 CompilerType return_value_type
= new_value_sp
->GetCompilerType();
248 if (!return_value_type
) {
249 error
= Status::FromErrorString("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
= Status::FromErrorStringWithFormat(
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
= Status::FromErrorString("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
= Status::FromErrorString("failed to write register x1");
293 error
= Status::FromErrorString(
294 "We don't support returning longer than 128 bit "
295 "integer values at present.");
297 } else if (type_flags
& eTypeIsFloat
) {
298 if (type_flags
& eTypeIsComplex
) {
299 // Don't handle complex yet.
300 error
= Status::FromErrorString(
301 "returning complex float values are not supported");
303 const RegisterInfo
*v0_info
= reg_ctx
->GetRegisterInfoByName("v0", 0);
306 if (byte_size
<= 16) {
307 RegisterValue reg_value
;
308 error
= reg_value
.SetValueFromData(*v0_info
, data
, 0, true);
310 if (!reg_ctx
->WriteRegister(v0_info
, reg_value
))
312 Status::FromErrorString("failed to write register v0");
314 error
= Status::FromErrorString(
315 "returning float values longer than 128 "
316 "bits are not supported");
319 error
= Status::FromErrorString(
320 "v0 register is not available on this target");
323 } else if (type_flags
& eTypeIsVector
) {
325 const RegisterInfo
*v0_info
= reg_ctx
->GetRegisterInfoByName("v0", 0);
328 if (byte_size
<= v0_info
->byte_size
) {
329 RegisterValue reg_value
;
330 error
= reg_value
.SetValueFromData(*v0_info
, data
, 0, true);
331 if (error
.Success()) {
332 if (!reg_ctx
->WriteRegister(v0_info
, reg_value
))
333 error
= Status::FromErrorString("failed to write register v0");
340 error
= Status::FromErrorString("no registers are available");
346 bool ABIMacOSX_arm64::CreateFunctionEntryUnwindPlan(UnwindPlan
&unwind_plan
) {
348 unwind_plan
.SetRegisterKind(eRegisterKindDWARF
);
350 uint32_t lr_reg_num
= arm64_dwarf::lr
;
351 uint32_t sp_reg_num
= arm64_dwarf::sp
;
352 uint32_t pc_reg_num
= arm64_dwarf::pc
;
354 UnwindPlan::RowSP
row(new UnwindPlan::Row
);
356 // Our previous Call Frame Address is the stack pointer
357 row
->GetCFAValue().SetIsRegisterPlusOffset(sp_reg_num
, 0);
359 // Our previous PC is in the LR
360 row
->SetRegisterLocationToRegister(pc_reg_num
, lr_reg_num
, true);
362 unwind_plan
.AppendRow(row
);
364 // All other registers are the same.
366 unwind_plan
.SetSourceName("arm64 at-func-entry default");
367 unwind_plan
.SetSourcedFromCompiler(eLazyBoolNo
);
372 bool ABIMacOSX_arm64::CreateDefaultUnwindPlan(UnwindPlan
&unwind_plan
) {
374 unwind_plan
.SetRegisterKind(eRegisterKindDWARF
);
376 uint32_t fp_reg_num
= arm64_dwarf::fp
;
377 uint32_t pc_reg_num
= arm64_dwarf::pc
;
379 UnwindPlan::RowSP
row(new UnwindPlan::Row
);
380 const int32_t ptr_size
= 8;
382 row
->GetCFAValue().SetIsRegisterPlusOffset(fp_reg_num
, 2 * ptr_size
);
384 row
->SetUnspecifiedRegistersAreUndefined(true);
386 row
->SetRegisterLocationToAtCFAPlusOffset(fp_reg_num
, ptr_size
* -2, true);
387 row
->SetRegisterLocationToAtCFAPlusOffset(pc_reg_num
, ptr_size
* -1, true);
389 unwind_plan
.AppendRow(row
);
390 unwind_plan
.SetSourceName("arm64-apple-darwin default unwind plan");
391 unwind_plan
.SetSourcedFromCompiler(eLazyBoolNo
);
392 unwind_plan
.SetUnwindPlanValidAtAllInstructions(eLazyBoolNo
);
393 unwind_plan
.SetUnwindPlanForSignalTrap(eLazyBoolNo
);
397 // AAPCS64 (Procedure Call Standard for the ARM 64-bit Architecture) says
398 // registers x19 through x28 and sp are callee preserved. v8-v15 are non-
399 // volatile (and specifically only the lower 8 bytes of these regs), the rest
400 // of the fp/SIMD registers are volatile.
402 // v. https://github.com/ARM-software/abi-aa/blob/main/aapcs64/
404 // We treat x29 as callee preserved also, else the unwinder won't try to
405 // retrieve fp saves.
407 bool ABIMacOSX_arm64::RegisterIsVolatile(const RegisterInfo
*reg_info
) {
409 const char *name
= reg_info
->name
;
411 // Sometimes we'll be called with the "alternate" name for these registers;
412 // recognize them as non-volatile.
414 if (name
[0] == 'p' && name
[1] == 'c') // pc
416 if (name
[0] == 'f' && name
[1] == 'p') // fp
418 if (name
[0] == 's' && name
[1] == 'p') // sp
420 if (name
[0] == 'l' && name
[1] == 'r') // lr
423 if (name
[0] == 'x') {
424 // Volatile registers: x0-x18, x30 (lr)
425 // Return false for the non-volatile gpr regs, true for everything else
430 return false; // x19 is non-volatile
446 return false; // x20 - 28 are non-volatile
448 return false; // x29 aka fp treat as non-volatile on Darwin
452 case '3': // x30 aka lr treat as non-volatile
459 } else if (name
[0] == 'v' || name
[0] == 's' || name
[0] == 'd') {
460 // Volatile registers: v0-7, v16-v31
461 // Return false for non-volatile fp/SIMD regs, true for everything else
465 return false; // v8-v9 are non-volatile
474 return false; // v10-v15 are non-volatile
486 static bool LoadValueFromConsecutiveGPRRegisters(
487 ExecutionContext
&exe_ctx
, RegisterContext
*reg_ctx
,
488 const CompilerType
&value_type
,
489 bool is_return_value
, // false => parameter, true => return value
490 uint32_t &NGRN
, // NGRN (see ABI documentation)
491 uint32_t &NSRN
, // NSRN (see ABI documentation)
492 DataExtractor
&data
) {
493 std::optional
<uint64_t> byte_size
=
494 value_type
.GetByteSize(exe_ctx
.GetBestExecutionContextScope());
495 if (!byte_size
|| *byte_size
== 0)
498 std::unique_ptr
<DataBufferHeap
> heap_data_up(
499 new DataBufferHeap(*byte_size
, 0));
500 const ByteOrder byte_order
= exe_ctx
.GetProcessRef().GetByteOrder();
503 CompilerType base_type
;
504 const uint32_t homogeneous_count
=
505 value_type
.IsHomogeneousAggregate(&base_type
);
506 if (homogeneous_count
> 0 && homogeneous_count
<= 8) {
507 // Make sure we have enough registers
508 if (NSRN
< 8 && (8 - NSRN
) >= homogeneous_count
) {
511 std::optional
<uint64_t> base_byte_size
=
512 base_type
.GetByteSize(exe_ctx
.GetBestExecutionContextScope());
515 uint32_t data_offset
= 0;
517 for (uint32_t i
= 0; i
< homogeneous_count
; ++i
) {
519 ::snprintf(v_name
, sizeof(v_name
), "v%u", NSRN
);
520 const RegisterInfo
*reg_info
=
521 reg_ctx
->GetRegisterInfoByName(v_name
, 0);
522 if (reg_info
== nullptr)
525 if (*base_byte_size
> reg_info
->byte_size
)
528 RegisterValue reg_value
;
530 if (!reg_ctx
->ReadRegister(reg_info
, reg_value
))
533 // Make sure we have enough room in "heap_data_up"
534 if ((data_offset
+ *base_byte_size
) <= heap_data_up
->GetByteSize()) {
535 const size_t bytes_copied
= reg_value
.GetAsMemoryData(
536 *reg_info
, heap_data_up
->GetBytes() + data_offset
,
537 *base_byte_size
, byte_order
, error
);
538 if (bytes_copied
!= *base_byte_size
)
540 data_offset
+= bytes_copied
;
545 data
.SetByteOrder(byte_order
);
546 data
.SetAddressByteSize(exe_ctx
.GetProcessRef().GetAddressByteSize());
547 data
.SetData(DataBufferSP(heap_data_up
.release()));
552 const size_t max_reg_byte_size
= 16;
553 if (*byte_size
<= max_reg_byte_size
) {
554 size_t bytes_left
= *byte_size
;
555 uint32_t data_offset
= 0;
556 while (data_offset
< *byte_size
) {
560 uint32_t reg_num
= reg_ctx
->ConvertRegisterKindToRegisterNumber(
561 eRegisterKindGeneric
, LLDB_REGNUM_GENERIC_ARG1
+ NGRN
);
562 if (reg_num
== LLDB_INVALID_REGNUM
)
565 const RegisterInfo
*reg_info
= reg_ctx
->GetRegisterInfoAtIndex(reg_num
);
566 if (reg_info
== nullptr)
569 RegisterValue reg_value
;
571 if (!reg_ctx
->ReadRegister(reg_info
, reg_value
))
574 const size_t curr_byte_size
= std::min
<size_t>(8, bytes_left
);
575 const size_t bytes_copied
= reg_value
.GetAsMemoryData(
576 *reg_info
, heap_data_up
->GetBytes() + data_offset
, curr_byte_size
,
578 if (bytes_copied
== 0)
580 if (bytes_copied
>= bytes_left
)
582 data_offset
+= bytes_copied
;
583 bytes_left
-= bytes_copied
;
587 const RegisterInfo
*reg_info
= nullptr;
588 if (is_return_value
) {
589 // The Darwin arm64 ABI doesn't write the return location back to x8
590 // before returning from the function the way the x86_64 ABI does. So
591 // we can't reconstruct stack based returns on exit from the function:
594 // We are assuming we are stopped at the first instruction in a function
595 // and that the ABI is being respected so all parameters appear where
596 // they should be (functions with no external linkage can legally violate
601 uint32_t reg_num
= reg_ctx
->ConvertRegisterKindToRegisterNumber(
602 eRegisterKindGeneric
, LLDB_REGNUM_GENERIC_ARG1
+ NGRN
);
603 if (reg_num
== LLDB_INVALID_REGNUM
)
605 reg_info
= reg_ctx
->GetRegisterInfoAtIndex(reg_num
);
606 if (reg_info
== nullptr)
611 const lldb::addr_t value_addr
=
612 reg_ctx
->ReadRegisterAsUnsigned(reg_info
, LLDB_INVALID_ADDRESS
);
614 if (value_addr
== LLDB_INVALID_ADDRESS
)
617 if (exe_ctx
.GetProcessRef().ReadMemory(
618 value_addr
, heap_data_up
->GetBytes(), heap_data_up
->GetByteSize(),
619 error
) != heap_data_up
->GetByteSize()) {
624 data
.SetByteOrder(byte_order
);
625 data
.SetAddressByteSize(exe_ctx
.GetProcessRef().GetAddressByteSize());
626 data
.SetData(DataBufferSP(heap_data_up
.release()));
630 ValueObjectSP
ABIMacOSX_arm64::GetReturnValueObjectImpl(
631 Thread
&thread
, CompilerType
&return_compiler_type
) const {
632 ValueObjectSP return_valobj_sp
;
635 ExecutionContext
exe_ctx(thread
.shared_from_this());
636 if (exe_ctx
.GetTargetPtr() == nullptr || exe_ctx
.GetProcessPtr() == nullptr)
637 return return_valobj_sp
;
639 // value.SetContext (Value::eContextTypeClangType, return_compiler_type);
640 value
.SetCompilerType(return_compiler_type
);
642 RegisterContext
*reg_ctx
= thread
.GetRegisterContext().get();
644 return return_valobj_sp
;
646 std::optional
<uint64_t> byte_size
= return_compiler_type
.GetByteSize(&thread
);
648 return return_valobj_sp
;
650 const uint32_t type_flags
= return_compiler_type
.GetTypeInfo(nullptr);
651 if (type_flags
& eTypeIsScalar
|| type_flags
& eTypeIsPointer
) {
652 value
.SetValueType(Value::ValueType::Scalar
);
654 bool success
= false;
655 if (type_flags
& eTypeIsInteger
|| type_flags
& eTypeIsPointer
) {
656 // Extract the register context so we can read arguments from registers
657 if (*byte_size
<= 8) {
658 const RegisterInfo
*x0_reg_info
=
659 reg_ctx
->GetRegisterInfoByName("x0", 0);
662 thread
.GetRegisterContext()->ReadRegisterAsUnsigned(x0_reg_info
,
664 const bool is_signed
= (type_flags
& eTypeIsSigned
) != 0;
665 switch (*byte_size
) {
668 case 16: // uint128_t
669 // In register x0 and x1
671 const RegisterInfo
*x1_reg_info
=
672 reg_ctx
->GetRegisterInfoByName("x1", 0);
676 x0_reg_info
->byte_size
+ x1_reg_info
->byte_size
) {
677 std::unique_ptr
<DataBufferHeap
> heap_data_up(
678 new DataBufferHeap(*byte_size
, 0));
679 const ByteOrder byte_order
=
680 exe_ctx
.GetProcessRef().GetByteOrder();
681 RegisterValue x0_reg_value
;
682 RegisterValue x1_reg_value
;
683 if (reg_ctx
->ReadRegister(x0_reg_info
, x0_reg_value
) &&
684 reg_ctx
->ReadRegister(x1_reg_info
, x1_reg_value
)) {
686 if (x0_reg_value
.GetAsMemoryData(
687 *x0_reg_info
, heap_data_up
->GetBytes() + 0, 8,
688 byte_order
, error
) &&
689 x1_reg_value
.GetAsMemoryData(
690 *x1_reg_info
, heap_data_up
->GetBytes() + 8, 8,
691 byte_order
, error
)) {
693 DataBufferSP(heap_data_up
.release()), byte_order
,
694 exe_ctx
.GetProcessRef().GetAddressByteSize());
696 return_valobj_sp
= ValueObjectConstResult::Create(
697 &thread
, return_compiler_type
, ConstString(""), data
);
698 return return_valobj_sp
;
705 case sizeof(uint64_t):
707 value
.GetScalar() = (int64_t)(raw_value
);
709 value
.GetScalar() = (uint64_t)(raw_value
);
713 case sizeof(uint32_t):
715 value
.GetScalar() = (int32_t)(raw_value
& UINT32_MAX
);
717 value
.GetScalar() = (uint32_t)(raw_value
& UINT32_MAX
);
721 case sizeof(uint16_t):
723 value
.GetScalar() = (int16_t)(raw_value
& UINT16_MAX
);
725 value
.GetScalar() = (uint16_t)(raw_value
& UINT16_MAX
);
729 case sizeof(uint8_t):
731 value
.GetScalar() = (int8_t)(raw_value
& UINT8_MAX
);
733 value
.GetScalar() = (uint8_t)(raw_value
& UINT8_MAX
);
739 } else if (type_flags
& eTypeIsFloat
) {
740 if (type_flags
& eTypeIsComplex
) {
741 // Don't handle complex yet.
743 if (*byte_size
<= sizeof(long double)) {
744 const RegisterInfo
*v0_reg_info
=
745 reg_ctx
->GetRegisterInfoByName("v0", 0);
746 RegisterValue v0_value
;
747 if (reg_ctx
->ReadRegister(v0_reg_info
, v0_value
)) {
749 if (v0_value
.GetData(data
)) {
750 lldb::offset_t offset
= 0;
751 if (*byte_size
== sizeof(float)) {
752 value
.GetScalar() = data
.GetFloat(&offset
);
754 } else if (*byte_size
== sizeof(double)) {
755 value
.GetScalar() = data
.GetDouble(&offset
);
757 } else if (*byte_size
== sizeof(long double)) {
758 value
.GetScalar() = data
.GetLongDouble(&offset
);
768 return_valobj_sp
= ValueObjectConstResult::Create(
769 thread
.GetStackFrameAtIndex(0).get(), value
, ConstString(""));
770 } else if (type_flags
& eTypeIsVector
) {
771 if (*byte_size
> 0) {
773 const RegisterInfo
*v0_info
= reg_ctx
->GetRegisterInfoByName("v0", 0);
776 if (*byte_size
<= v0_info
->byte_size
) {
777 std::unique_ptr
<DataBufferHeap
> heap_data_up(
778 new DataBufferHeap(*byte_size
, 0));
779 const ByteOrder byte_order
= exe_ctx
.GetProcessRef().GetByteOrder();
780 RegisterValue reg_value
;
781 if (reg_ctx
->ReadRegister(v0_info
, reg_value
)) {
783 if (reg_value
.GetAsMemoryData(*v0_info
, heap_data_up
->GetBytes(),
784 heap_data_up
->GetByteSize(),
785 byte_order
, error
)) {
786 DataExtractor
data(DataBufferSP(heap_data_up
.release()),
788 exe_ctx
.GetProcessRef().GetAddressByteSize());
789 return_valobj_sp
= ValueObjectConstResult::Create(
790 &thread
, return_compiler_type
, ConstString(""), data
);
796 } else if (type_flags
& eTypeIsStructUnion
|| type_flags
& eTypeIsClass
) {
799 uint32_t NGRN
= 0; // Search ABI docs for NGRN
800 uint32_t NSRN
= 0; // Search ABI docs for NSRN
801 const bool is_return_value
= true;
802 if (LoadValueFromConsecutiveGPRRegisters(
803 exe_ctx
, reg_ctx
, return_compiler_type
, is_return_value
, NGRN
, NSRN
,
805 return_valobj_sp
= ValueObjectConstResult::Create(
806 &thread
, return_compiler_type
, ConstString(""), data
);
809 return return_valobj_sp
;
812 addr_t
ABIMacOSX_arm64::FixCodeAddress(addr_t pc
) {
813 addr_t pac_sign_extension
= 0x0080000000000000ULL
;
814 addr_t tbi_mask
= 0xff80000000000000ULL
;
817 if (ProcessSP process_sp
= GetProcessSP()) {
818 mask
= process_sp
->GetCodeAddressMask();
819 if (pc
& pac_sign_extension
) {
820 addr_t highmem_mask
= process_sp
->GetHighmemCodeAddressMask();
821 if (highmem_mask
!= LLDB_INVALID_ADDRESS_MASK
)
825 if (mask
== LLDB_INVALID_ADDRESS_MASK
)
828 return (pc
& pac_sign_extension
) ? pc
| mask
: pc
& (~mask
);
831 addr_t
ABIMacOSX_arm64::FixDataAddress(addr_t pc
) {
832 addr_t pac_sign_extension
= 0x0080000000000000ULL
;
833 addr_t tbi_mask
= 0xff80000000000000ULL
;
836 if (ProcessSP process_sp
= GetProcessSP()) {
837 mask
= process_sp
->GetDataAddressMask();
838 if (pc
& pac_sign_extension
) {
839 addr_t highmem_mask
= process_sp
->GetHighmemDataAddressMask();
840 if (highmem_mask
!= LLDB_INVALID_ADDRESS_MASK
)
844 if (mask
== LLDB_INVALID_ADDRESS_MASK
)
847 return (pc
& pac_sign_extension
) ? pc
| mask
: pc
& (~mask
);
850 void ABIMacOSX_arm64::Initialize() {
851 PluginManager::RegisterPlugin(GetPluginNameStatic(), pluginDesc
,
855 void ABIMacOSX_arm64::Terminate() {
856 PluginManager::UnregisterPlugin(CreateInstance
);