Path: blob/main/contrib/llvm-project/lldb/source/Plugins/ABI/AArch64/ABIMacOSX_arm64.cpp
39653 views
//===-- ABIMacOSX_arm64.cpp -----------------------------------------------===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//78#include "ABIMacOSX_arm64.h"910#include <optional>11#include <vector>1213#include "llvm/ADT/STLExtras.h"14#include "llvm/TargetParser/Triple.h"1516#include "lldb/Core/Module.h"17#include "lldb/Core/PluginManager.h"18#include "lldb/Core/Value.h"19#include "lldb/Core/ValueObjectConstResult.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"3132#include "Utility/ARM64_DWARF_Registers.h"3334using namespace lldb;35using namespace lldb_private;3637static const char *pluginDesc = "Mac OS X ABI for arm64 targets";3839size_t ABIMacOSX_arm64::GetRedZoneSize() const { return 128; }4041// Static Functions4243ABISP44ABIMacOSX_arm64::CreateInstance(ProcessSP process_sp, const ArchSpec &arch) {45const llvm::Triple::ArchType arch_type = arch.GetTriple().getArch();46const llvm::Triple::VendorType vendor_type = arch.GetTriple().getVendor();4748if (vendor_type == llvm::Triple::Apple) {49if (arch_type == llvm::Triple::aarch64 ||50arch_type == llvm::Triple::aarch64_32) {51return ABISP(52new ABIMacOSX_arm64(std::move(process_sp), MakeMCRegisterInfo(arch)));53}54}5556return ABISP();57}5859bool ABIMacOSX_arm64::PrepareTrivialCall(60Thread &thread, lldb::addr_t sp, lldb::addr_t func_addr,61lldb::addr_t return_addr, llvm::ArrayRef<lldb::addr_t> args) const {62RegisterContext *reg_ctx = thread.GetRegisterContext().get();63if (!reg_ctx)64return false;6566Log *log = GetLog(LLDBLog::Expressions);6768if (log) {69StreamString s;70s.Printf("ABIMacOSX_arm64::PrepareTrivialCall (tid = 0x%" PRIx6471", sp = 0x%" PRIx64 ", func_addr = 0x%" PRIx6472", return_addr = 0x%" PRIx64,73thread.GetID(), (uint64_t)sp, (uint64_t)func_addr,74(uint64_t)return_addr);7576for (size_t i = 0; i < args.size(); ++i)77s.Printf(", arg%d = 0x%" PRIx64, static_cast<int>(i + 1), args[i]);78s.PutCString(")");79log->PutString(s.GetString());80}8182const uint32_t pc_reg_num = reg_ctx->ConvertRegisterKindToRegisterNumber(83eRegisterKindGeneric, LLDB_REGNUM_GENERIC_PC);84const uint32_t sp_reg_num = reg_ctx->ConvertRegisterKindToRegisterNumber(85eRegisterKindGeneric, LLDB_REGNUM_GENERIC_SP);86const uint32_t ra_reg_num = reg_ctx->ConvertRegisterKindToRegisterNumber(87eRegisterKindGeneric, LLDB_REGNUM_GENERIC_RA);8889// x0 - x7 contain first 8 simple args90if (args.size() > 8) // TODO handle more than 8 arguments91return false;9293for (size_t i = 0; i < args.size(); ++i) {94const RegisterInfo *reg_info = reg_ctx->GetRegisterInfo(95eRegisterKindGeneric, LLDB_REGNUM_GENERIC_ARG1 + i);96LLDB_LOGF(log, "About to write arg%d (0x%" PRIx64 ") into %s",97static_cast<int>(i + 1), args[i], reg_info->name);98if (!reg_ctx->WriteRegisterFromUnsigned(reg_info, args[i]))99return false;100}101102// Set "lr" to the return address103if (!reg_ctx->WriteRegisterFromUnsigned(104reg_ctx->GetRegisterInfoAtIndex(ra_reg_num), return_addr))105return false;106107// Set "sp" to the requested value108if (!reg_ctx->WriteRegisterFromUnsigned(109reg_ctx->GetRegisterInfoAtIndex(sp_reg_num), sp))110return false;111112// Set "pc" to the address requested113if (!reg_ctx->WriteRegisterFromUnsigned(114reg_ctx->GetRegisterInfoAtIndex(pc_reg_num), func_addr))115return false;116117return true;118}119120bool ABIMacOSX_arm64::GetArgumentValues(Thread &thread,121ValueList &values) const {122uint32_t num_values = values.GetSize();123124ExecutionContext exe_ctx(thread.shared_from_this());125126// Extract the register context so we can read arguments from registers127128RegisterContext *reg_ctx = thread.GetRegisterContext().get();129130if (!reg_ctx)131return false;132133addr_t sp = 0;134135for (uint32_t value_idx = 0; value_idx < num_values; ++value_idx) {136// We currently only support extracting values with Clang QualTypes. Do we137// care about others?138Value *value = values.GetValueAtIndex(value_idx);139140if (!value)141return false;142143CompilerType value_type = value->GetCompilerType();144std::optional<uint64_t> bit_size = value_type.GetBitSize(&thread);145if (!bit_size)146return false;147148bool is_signed = false;149size_t bit_width = 0;150if (value_type.IsIntegerOrEnumerationType(is_signed)) {151bit_width = *bit_size;152} else if (value_type.IsPointerOrReferenceType()) {153bit_width = *bit_size;154} else {155// We only handle integer, pointer and reference types currently...156return false;157}158159if (bit_width <= (exe_ctx.GetProcessRef().GetAddressByteSize() * 8)) {160if (value_idx < 8) {161// Arguments 1-6 are in x0-x5...162const RegisterInfo *reg_info = nullptr;163// Search by generic ID first, then fall back to by name164uint32_t arg_reg_num = reg_ctx->ConvertRegisterKindToRegisterNumber(165eRegisterKindGeneric, LLDB_REGNUM_GENERIC_ARG1 + value_idx);166if (arg_reg_num != LLDB_INVALID_REGNUM) {167reg_info = reg_ctx->GetRegisterInfoAtIndex(arg_reg_num);168} else {169switch (value_idx) {170case 0:171reg_info = reg_ctx->GetRegisterInfoByName("x0");172break;173case 1:174reg_info = reg_ctx->GetRegisterInfoByName("x1");175break;176case 2:177reg_info = reg_ctx->GetRegisterInfoByName("x2");178break;179case 3:180reg_info = reg_ctx->GetRegisterInfoByName("x3");181break;182case 4:183reg_info = reg_ctx->GetRegisterInfoByName("x4");184break;185case 5:186reg_info = reg_ctx->GetRegisterInfoByName("x5");187break;188case 6:189reg_info = reg_ctx->GetRegisterInfoByName("x6");190break;191case 7:192reg_info = reg_ctx->GetRegisterInfoByName("x7");193break;194}195}196197if (reg_info) {198RegisterValue reg_value;199200if (reg_ctx->ReadRegister(reg_info, reg_value)) {201if (is_signed)202reg_value.SignExtend(bit_width);203if (!reg_value.GetScalarValue(value->GetScalar()))204return false;205continue;206}207}208return false;209} else {210if (sp == 0) {211// Read the stack pointer if we already haven't read it212sp = reg_ctx->GetSP(0);213if (sp == 0)214return false;215}216217// Arguments 5 on up are on the stack218const uint32_t arg_byte_size = (bit_width + (8 - 1)) / 8;219Status error;220if (!exe_ctx.GetProcessRef().ReadScalarIntegerFromMemory(221sp, arg_byte_size, is_signed, value->GetScalar(), error))222return false;223224sp += arg_byte_size;225// Align up to the next 8 byte boundary if needed226if (sp % 8) {227sp >>= 3;228sp += 1;229sp <<= 3;230}231}232}233}234return true;235}236237Status238ABIMacOSX_arm64::SetReturnValueObject(lldb::StackFrameSP &frame_sp,239lldb::ValueObjectSP &new_value_sp) {240Status error;241if (!new_value_sp) {242error.SetErrorString("Empty value object for return value.");243return error;244}245246CompilerType return_value_type = new_value_sp->GetCompilerType();247if (!return_value_type) {248error.SetErrorString("Null clang type for return value.");249return error;250}251252Thread *thread = frame_sp->GetThread().get();253254RegisterContext *reg_ctx = thread->GetRegisterContext().get();255256if (reg_ctx) {257DataExtractor data;258Status data_error;259const uint64_t byte_size = new_value_sp->GetData(data, data_error);260if (data_error.Fail()) {261error.SetErrorStringWithFormat(262"Couldn't convert return value to raw data: %s",263data_error.AsCString());264return error;265}266267const uint32_t type_flags = return_value_type.GetTypeInfo(nullptr);268if (type_flags & eTypeIsScalar || type_flags & eTypeIsPointer) {269if (type_flags & eTypeIsInteger || type_flags & eTypeIsPointer) {270// Extract the register context so we can read arguments from registers271lldb::offset_t offset = 0;272if (byte_size <= 16) {273const RegisterInfo *x0_info = reg_ctx->GetRegisterInfoByName("x0", 0);274if (byte_size <= 8) {275uint64_t raw_value = data.GetMaxU64(&offset, byte_size);276277if (!reg_ctx->WriteRegisterFromUnsigned(x0_info, raw_value))278error.SetErrorString("failed to write register x0");279} else {280uint64_t raw_value = data.GetMaxU64(&offset, 8);281282if (reg_ctx->WriteRegisterFromUnsigned(x0_info, raw_value)) {283const RegisterInfo *x1_info =284reg_ctx->GetRegisterInfoByName("x1", 0);285raw_value = data.GetMaxU64(&offset, byte_size - offset);286287if (!reg_ctx->WriteRegisterFromUnsigned(x1_info, raw_value))288error.SetErrorString("failed to write register x1");289}290}291} else {292error.SetErrorString("We don't support returning longer than 128 bit "293"integer values at present.");294}295} else if (type_flags & eTypeIsFloat) {296if (type_flags & eTypeIsComplex) {297// Don't handle complex yet.298error.SetErrorString(299"returning complex float values are not supported");300} else {301const RegisterInfo *v0_info = reg_ctx->GetRegisterInfoByName("v0", 0);302303if (v0_info) {304if (byte_size <= 16) {305RegisterValue reg_value;306error = reg_value.SetValueFromData(*v0_info, data, 0, true);307if (error.Success())308if (!reg_ctx->WriteRegister(v0_info, reg_value))309error.SetErrorString("failed to write register v0");310} else {311error.SetErrorString("returning float values longer than 128 "312"bits are not supported");313}314} else315error.SetErrorString("v0 register is not available on this target");316}317}318} else if (type_flags & eTypeIsVector) {319if (byte_size > 0) {320const RegisterInfo *v0_info = reg_ctx->GetRegisterInfoByName("v0", 0);321322if (v0_info) {323if (byte_size <= v0_info->byte_size) {324RegisterValue reg_value;325error = reg_value.SetValueFromData(*v0_info, data, 0, true);326if (error.Success()) {327if (!reg_ctx->WriteRegister(v0_info, reg_value))328error.SetErrorString("failed to write register v0");329}330}331}332}333}334} else {335error.SetErrorString("no registers are available");336}337338return error;339}340341bool ABIMacOSX_arm64::CreateFunctionEntryUnwindPlan(UnwindPlan &unwind_plan) {342unwind_plan.Clear();343unwind_plan.SetRegisterKind(eRegisterKindDWARF);344345uint32_t lr_reg_num = arm64_dwarf::lr;346uint32_t sp_reg_num = arm64_dwarf::sp;347uint32_t pc_reg_num = arm64_dwarf::pc;348349UnwindPlan::RowSP row(new UnwindPlan::Row);350351// Our previous Call Frame Address is the stack pointer352row->GetCFAValue().SetIsRegisterPlusOffset(sp_reg_num, 0);353354// Our previous PC is in the LR355row->SetRegisterLocationToRegister(pc_reg_num, lr_reg_num, true);356357unwind_plan.AppendRow(row);358359// All other registers are the same.360361unwind_plan.SetSourceName("arm64 at-func-entry default");362unwind_plan.SetSourcedFromCompiler(eLazyBoolNo);363364return true;365}366367bool ABIMacOSX_arm64::CreateDefaultUnwindPlan(UnwindPlan &unwind_plan) {368unwind_plan.Clear();369unwind_plan.SetRegisterKind(eRegisterKindDWARF);370371uint32_t fp_reg_num = arm64_dwarf::fp;372uint32_t pc_reg_num = arm64_dwarf::pc;373374UnwindPlan::RowSP row(new UnwindPlan::Row);375const int32_t ptr_size = 8;376377row->GetCFAValue().SetIsRegisterPlusOffset(fp_reg_num, 2 * ptr_size);378row->SetOffset(0);379row->SetUnspecifiedRegistersAreUndefined(true);380381row->SetRegisterLocationToAtCFAPlusOffset(fp_reg_num, ptr_size * -2, true);382row->SetRegisterLocationToAtCFAPlusOffset(pc_reg_num, ptr_size * -1, true);383384unwind_plan.AppendRow(row);385unwind_plan.SetSourceName("arm64-apple-darwin default unwind plan");386unwind_plan.SetSourcedFromCompiler(eLazyBoolNo);387unwind_plan.SetUnwindPlanValidAtAllInstructions(eLazyBoolNo);388unwind_plan.SetUnwindPlanForSignalTrap(eLazyBoolNo);389return true;390}391392// AAPCS64 (Procedure Call Standard for the ARM 64-bit Architecture) says393// registers x19 through x28 and sp are callee preserved. v8-v15 are non-394// volatile (and specifically only the lower 8 bytes of these regs), the rest395// of the fp/SIMD registers are volatile.396//397// v. https://github.com/ARM-software/abi-aa/blob/main/aapcs64/398399// We treat x29 as callee preserved also, else the unwinder won't try to400// retrieve fp saves.401402bool ABIMacOSX_arm64::RegisterIsVolatile(const RegisterInfo *reg_info) {403if (reg_info) {404const char *name = reg_info->name;405406// Sometimes we'll be called with the "alternate" name for these registers;407// recognize them as non-volatile.408409if (name[0] == 'p' && name[1] == 'c') // pc410return false;411if (name[0] == 'f' && name[1] == 'p') // fp412return false;413if (name[0] == 's' && name[1] == 'p') // sp414return false;415if (name[0] == 'l' && name[1] == 'r') // lr416return false;417418if (name[0] == 'x') {419// Volatile registers: x0-x18, x30 (lr)420// Return false for the non-volatile gpr regs, true for everything else421switch (name[1]) {422case '1':423switch (name[2]) {424case '9':425return false; // x19 is non-volatile426default:427return true;428}429break;430case '2':431switch (name[2]) {432case '0':433case '1':434case '2':435case '3':436case '4':437case '5':438case '6':439case '7':440case '8':441return false; // x20 - 28 are non-volatile442case '9':443return false; // x29 aka fp treat as non-volatile on Darwin444default:445return true;446}447case '3': // x30 aka lr treat as non-volatile448if (name[2] == '0')449return false;450break;451default:452return true;453}454} else if (name[0] == 'v' || name[0] == 's' || name[0] == 'd') {455// Volatile registers: v0-7, v16-v31456// Return false for non-volatile fp/SIMD regs, true for everything else457switch (name[1]) {458case '8':459case '9':460return false; // v8-v9 are non-volatile461case '1':462switch (name[2]) {463case '0':464case '1':465case '2':466case '3':467case '4':468case '5':469return false; // v10-v15 are non-volatile470default:471return true;472}473default:474return true;475}476}477}478return true;479}480481static bool LoadValueFromConsecutiveGPRRegisters(482ExecutionContext &exe_ctx, RegisterContext *reg_ctx,483const CompilerType &value_type,484bool is_return_value, // false => parameter, true => return value485uint32_t &NGRN, // NGRN (see ABI documentation)486uint32_t &NSRN, // NSRN (see ABI documentation)487DataExtractor &data) {488std::optional<uint64_t> byte_size =489value_type.GetByteSize(exe_ctx.GetBestExecutionContextScope());490if (!byte_size || *byte_size == 0)491return false;492493std::unique_ptr<DataBufferHeap> heap_data_up(494new DataBufferHeap(*byte_size, 0));495const ByteOrder byte_order = exe_ctx.GetProcessRef().GetByteOrder();496Status error;497498CompilerType base_type;499const uint32_t homogeneous_count =500value_type.IsHomogeneousAggregate(&base_type);501if (homogeneous_count > 0 && homogeneous_count <= 8) {502// Make sure we have enough registers503if (NSRN < 8 && (8 - NSRN) >= homogeneous_count) {504if (!base_type)505return false;506std::optional<uint64_t> base_byte_size =507base_type.GetByteSize(exe_ctx.GetBestExecutionContextScope());508if (!base_byte_size)509return false;510uint32_t data_offset = 0;511512for (uint32_t i = 0; i < homogeneous_count; ++i) {513char v_name[8];514::snprintf(v_name, sizeof(v_name), "v%u", NSRN);515const RegisterInfo *reg_info =516reg_ctx->GetRegisterInfoByName(v_name, 0);517if (reg_info == nullptr)518return false;519520if (*base_byte_size > reg_info->byte_size)521return false;522523RegisterValue reg_value;524525if (!reg_ctx->ReadRegister(reg_info, reg_value))526return false;527528// Make sure we have enough room in "heap_data_up"529if ((data_offset + *base_byte_size) <= heap_data_up->GetByteSize()) {530const size_t bytes_copied = reg_value.GetAsMemoryData(531*reg_info, heap_data_up->GetBytes() + data_offset,532*base_byte_size, byte_order, error);533if (bytes_copied != *base_byte_size)534return false;535data_offset += bytes_copied;536++NSRN;537} else538return false;539}540data.SetByteOrder(byte_order);541data.SetAddressByteSize(exe_ctx.GetProcessRef().GetAddressByteSize());542data.SetData(DataBufferSP(heap_data_up.release()));543return true;544}545}546547const size_t max_reg_byte_size = 16;548if (*byte_size <= max_reg_byte_size) {549size_t bytes_left = *byte_size;550uint32_t data_offset = 0;551while (data_offset < *byte_size) {552if (NGRN >= 8)553return false;554555uint32_t reg_num = reg_ctx->ConvertRegisterKindToRegisterNumber(556eRegisterKindGeneric, LLDB_REGNUM_GENERIC_ARG1 + NGRN);557if (reg_num == LLDB_INVALID_REGNUM)558return false;559560const RegisterInfo *reg_info = reg_ctx->GetRegisterInfoAtIndex(reg_num);561if (reg_info == nullptr)562return false;563564RegisterValue reg_value;565566if (!reg_ctx->ReadRegister(reg_info, reg_value))567return false;568569const size_t curr_byte_size = std::min<size_t>(8, bytes_left);570const size_t bytes_copied = reg_value.GetAsMemoryData(571*reg_info, heap_data_up->GetBytes() + data_offset, curr_byte_size,572byte_order, error);573if (bytes_copied == 0)574return false;575if (bytes_copied >= bytes_left)576break;577data_offset += bytes_copied;578bytes_left -= bytes_copied;579++NGRN;580}581} else {582const RegisterInfo *reg_info = nullptr;583if (is_return_value) {584// The Darwin arm64 ABI doesn't write the return location back to x8585// before returning from the function the way the x86_64 ABI does. So586// we can't reconstruct stack based returns on exit from the function:587return false;588} else {589// We are assuming we are stopped at the first instruction in a function590// and that the ABI is being respected so all parameters appear where591// they should be (functions with no external linkage can legally violate592// the ABI).593if (NGRN >= 8)594return false;595596uint32_t reg_num = reg_ctx->ConvertRegisterKindToRegisterNumber(597eRegisterKindGeneric, LLDB_REGNUM_GENERIC_ARG1 + NGRN);598if (reg_num == LLDB_INVALID_REGNUM)599return false;600reg_info = reg_ctx->GetRegisterInfoAtIndex(reg_num);601if (reg_info == nullptr)602return false;603++NGRN;604}605606const lldb::addr_t value_addr =607reg_ctx->ReadRegisterAsUnsigned(reg_info, LLDB_INVALID_ADDRESS);608609if (value_addr == LLDB_INVALID_ADDRESS)610return false;611612if (exe_ctx.GetProcessRef().ReadMemory(613value_addr, heap_data_up->GetBytes(), heap_data_up->GetByteSize(),614error) != heap_data_up->GetByteSize()) {615return false;616}617}618619data.SetByteOrder(byte_order);620data.SetAddressByteSize(exe_ctx.GetProcessRef().GetAddressByteSize());621data.SetData(DataBufferSP(heap_data_up.release()));622return true;623}624625ValueObjectSP ABIMacOSX_arm64::GetReturnValueObjectImpl(626Thread &thread, CompilerType &return_compiler_type) const {627ValueObjectSP return_valobj_sp;628Value value;629630ExecutionContext exe_ctx(thread.shared_from_this());631if (exe_ctx.GetTargetPtr() == nullptr || exe_ctx.GetProcessPtr() == nullptr)632return return_valobj_sp;633634// value.SetContext (Value::eContextTypeClangType, return_compiler_type);635value.SetCompilerType(return_compiler_type);636637RegisterContext *reg_ctx = thread.GetRegisterContext().get();638if (!reg_ctx)639return return_valobj_sp;640641std::optional<uint64_t> byte_size = return_compiler_type.GetByteSize(&thread);642if (!byte_size)643return return_valobj_sp;644645const uint32_t type_flags = return_compiler_type.GetTypeInfo(nullptr);646if (type_flags & eTypeIsScalar || type_flags & eTypeIsPointer) {647value.SetValueType(Value::ValueType::Scalar);648649bool success = false;650if (type_flags & eTypeIsInteger || type_flags & eTypeIsPointer) {651// Extract the register context so we can read arguments from registers652if (*byte_size <= 8) {653const RegisterInfo *x0_reg_info =654reg_ctx->GetRegisterInfoByName("x0", 0);655if (x0_reg_info) {656uint64_t raw_value =657thread.GetRegisterContext()->ReadRegisterAsUnsigned(x0_reg_info,6580);659const bool is_signed = (type_flags & eTypeIsSigned) != 0;660switch (*byte_size) {661default:662break;663case 16: // uint128_t664// In register x0 and x1665{666const RegisterInfo *x1_reg_info =667reg_ctx->GetRegisterInfoByName("x1", 0);668669if (x1_reg_info) {670if (*byte_size <=671x0_reg_info->byte_size + x1_reg_info->byte_size) {672std::unique_ptr<DataBufferHeap> heap_data_up(673new DataBufferHeap(*byte_size, 0));674const ByteOrder byte_order =675exe_ctx.GetProcessRef().GetByteOrder();676RegisterValue x0_reg_value;677RegisterValue x1_reg_value;678if (reg_ctx->ReadRegister(x0_reg_info, x0_reg_value) &&679reg_ctx->ReadRegister(x1_reg_info, x1_reg_value)) {680Status error;681if (x0_reg_value.GetAsMemoryData(682*x0_reg_info, heap_data_up->GetBytes() + 0, 8,683byte_order, error) &&684x1_reg_value.GetAsMemoryData(685*x1_reg_info, heap_data_up->GetBytes() + 8, 8,686byte_order, error)) {687DataExtractor data(688DataBufferSP(heap_data_up.release()), byte_order,689exe_ctx.GetProcessRef().GetAddressByteSize());690691return_valobj_sp = ValueObjectConstResult::Create(692&thread, return_compiler_type, ConstString(""), data);693return return_valobj_sp;694}695}696}697}698}699break;700case sizeof(uint64_t):701if (is_signed)702value.GetScalar() = (int64_t)(raw_value);703else704value.GetScalar() = (uint64_t)(raw_value);705success = true;706break;707708case sizeof(uint32_t):709if (is_signed)710value.GetScalar() = (int32_t)(raw_value & UINT32_MAX);711else712value.GetScalar() = (uint32_t)(raw_value & UINT32_MAX);713success = true;714break;715716case sizeof(uint16_t):717if (is_signed)718value.GetScalar() = (int16_t)(raw_value & UINT16_MAX);719else720value.GetScalar() = (uint16_t)(raw_value & UINT16_MAX);721success = true;722break;723724case sizeof(uint8_t):725if (is_signed)726value.GetScalar() = (int8_t)(raw_value & UINT8_MAX);727else728value.GetScalar() = (uint8_t)(raw_value & UINT8_MAX);729success = true;730break;731}732}733}734} else if (type_flags & eTypeIsFloat) {735if (type_flags & eTypeIsComplex) {736// Don't handle complex yet.737} else {738if (*byte_size <= sizeof(long double)) {739const RegisterInfo *v0_reg_info =740reg_ctx->GetRegisterInfoByName("v0", 0);741RegisterValue v0_value;742if (reg_ctx->ReadRegister(v0_reg_info, v0_value)) {743DataExtractor data;744if (v0_value.GetData(data)) {745lldb::offset_t offset = 0;746if (*byte_size == sizeof(float)) {747value.GetScalar() = data.GetFloat(&offset);748success = true;749} else if (*byte_size == sizeof(double)) {750value.GetScalar() = data.GetDouble(&offset);751success = true;752} else if (*byte_size == sizeof(long double)) {753value.GetScalar() = data.GetLongDouble(&offset);754success = true;755}756}757}758}759}760}761762if (success)763return_valobj_sp = ValueObjectConstResult::Create(764thread.GetStackFrameAtIndex(0).get(), value, ConstString(""));765} else if (type_flags & eTypeIsVector) {766if (*byte_size > 0) {767768const RegisterInfo *v0_info = reg_ctx->GetRegisterInfoByName("v0", 0);769770if (v0_info) {771if (*byte_size <= v0_info->byte_size) {772std::unique_ptr<DataBufferHeap> heap_data_up(773new DataBufferHeap(*byte_size, 0));774const ByteOrder byte_order = exe_ctx.GetProcessRef().GetByteOrder();775RegisterValue reg_value;776if (reg_ctx->ReadRegister(v0_info, reg_value)) {777Status error;778if (reg_value.GetAsMemoryData(*v0_info, heap_data_up->GetBytes(),779heap_data_up->GetByteSize(),780byte_order, error)) {781DataExtractor data(DataBufferSP(heap_data_up.release()),782byte_order,783exe_ctx.GetProcessRef().GetAddressByteSize());784return_valobj_sp = ValueObjectConstResult::Create(785&thread, return_compiler_type, ConstString(""), data);786}787}788}789}790}791} else if (type_flags & eTypeIsStructUnion || type_flags & eTypeIsClass) {792DataExtractor data;793794uint32_t NGRN = 0; // Search ABI docs for NGRN795uint32_t NSRN = 0; // Search ABI docs for NSRN796const bool is_return_value = true;797if (LoadValueFromConsecutiveGPRRegisters(798exe_ctx, reg_ctx, return_compiler_type, is_return_value, NGRN, NSRN,799data)) {800return_valobj_sp = ValueObjectConstResult::Create(801&thread, return_compiler_type, ConstString(""), data);802}803}804return return_valobj_sp;805}806807addr_t ABIMacOSX_arm64::FixCodeAddress(addr_t pc) {808addr_t pac_sign_extension = 0x0080000000000000ULL;809addr_t tbi_mask = 0xff80000000000000ULL;810addr_t mask = 0;811812if (ProcessSP process_sp = GetProcessSP()) {813mask = process_sp->GetCodeAddressMask();814if (pc & pac_sign_extension) {815addr_t highmem_mask = process_sp->GetHighmemCodeAddressMask();816if (highmem_mask != LLDB_INVALID_ADDRESS_MASK)817mask = highmem_mask;818}819}820if (mask == LLDB_INVALID_ADDRESS_MASK)821mask = tbi_mask;822823return (pc & pac_sign_extension) ? pc | mask : pc & (~mask);824}825826addr_t ABIMacOSX_arm64::FixDataAddress(addr_t pc) {827addr_t pac_sign_extension = 0x0080000000000000ULL;828addr_t tbi_mask = 0xff80000000000000ULL;829addr_t mask = 0;830831if (ProcessSP process_sp = GetProcessSP()) {832mask = process_sp->GetDataAddressMask();833if (pc & pac_sign_extension) {834addr_t highmem_mask = process_sp->GetHighmemDataAddressMask();835if (highmem_mask != LLDB_INVALID_ADDRESS_MASK)836mask = highmem_mask;837}838}839if (mask == LLDB_INVALID_ADDRESS_MASK)840mask = tbi_mask;841842return (pc & pac_sign_extension) ? pc | mask : pc & (~mask);843}844845void ABIMacOSX_arm64::Initialize() {846PluginManager::RegisterPlugin(GetPluginNameStatic(), pluginDesc,847CreateInstance);848}849850void ABIMacOSX_arm64::Terminate() {851PluginManager::UnregisterPlugin(CreateInstance);852}853854855