Author: Felipe de Azevedo Piovezan Date: 2025-09-18T13:49:56-07:00 New Revision: a6662866e88a887ab125c4d533659d27c4134108
URL: https://github.com/llvm/llvm-project/commit/a6662866e88a887ab125c4d533659d27c4134108 DIFF: https://github.com/llvm/llvm-project/commit/a6662866e88a887ab125c4d533659d27c4134108.diff LOG: [lldb][NFC] Simplify logic in ABIMacOSX_arm64::FixDataAddress (#159612) I've intentionally split this into two commits to make it easier that this is an NFC patch; don't think we need to preserve them separately though upon merging. Added: Modified: lldb/source/Plugins/ABI/AArch64/ABIMacOSX_arm64.cpp Removed: ################################################################################ diff --git a/lldb/source/Plugins/ABI/AArch64/ABIMacOSX_arm64.cpp b/lldb/source/Plugins/ABI/AArch64/ABIMacOSX_arm64.cpp index 094e0523a4edf..c595564f6fb8e 100644 --- a/lldb/source/Plugins/ABI/AArch64/ABIMacOSX_arm64.cpp +++ b/lldb/source/Plugins/ABI/AArch64/ABIMacOSX_arm64.cpp @@ -757,42 +757,39 @@ ValueObjectSP ABIMacOSX_arm64::GetReturnValueObjectImpl( return return_valobj_sp; } -addr_t ABIMacOSX_arm64::FixCodeAddress(addr_t pc) { - addr_t pac_sign_extension = 0x0080000000000000ULL; - addr_t tbi_mask = 0xff80000000000000ULL; - addr_t mask = 0; - - if (ProcessSP process_sp = GetProcessSP()) { - mask = process_sp->GetCodeAddressMask(); - if (pc & pac_sign_extension) { - addr_t highmem_mask = process_sp->GetHighmemCodeAddressMask(); - if (highmem_mask != LLDB_INVALID_ADDRESS_MASK) - mask = highmem_mask; - } - } +constexpr addr_t tbi_mask = 0xff80000000000000ULL; +constexpr addr_t pac_sign_extension = 0x0080000000000000ULL; + +/// Consults the process for its {code, data} address masks and applies it to +/// `addr`. +static addr_t DoFixAddr(addr_t addr, bool is_code, ProcessSP process_sp) { + if (!process_sp) + return addr; + + addr_t mask = is_code ? process_sp->GetCodeAddressMask() + : process_sp->GetDataAddressMask(); if (mask == LLDB_INVALID_ADDRESS_MASK) mask = tbi_mask; - return (pc & pac_sign_extension) ? pc | mask : pc & (~mask); + if (addr & pac_sign_extension) { + addr_t highmem_mask = is_code ? process_sp->GetHighmemCodeAddressMask() + : process_sp->GetHighmemCodeAddressMask(); + if (highmem_mask != LLDB_INVALID_ADDRESS_MASK) + return addr | highmem_mask; + return addr | mask; + } + + return addr & (~mask); } -addr_t ABIMacOSX_arm64::FixDataAddress(addr_t pc) { - addr_t pac_sign_extension = 0x0080000000000000ULL; - addr_t tbi_mask = 0xff80000000000000ULL; - addr_t mask = 0; - - if (ProcessSP process_sp = GetProcessSP()) { - mask = process_sp->GetDataAddressMask(); - if (pc & pac_sign_extension) { - addr_t highmem_mask = process_sp->GetHighmemDataAddressMask(); - if (highmem_mask != LLDB_INVALID_ADDRESS_MASK) - mask = highmem_mask; - } - } - if (mask == LLDB_INVALID_ADDRESS_MASK) - mask = tbi_mask; +addr_t ABIMacOSX_arm64::FixCodeAddress(addr_t pc) { + ProcessSP process_sp = GetProcessSP(); + return DoFixAddr(pc, true /*is_code*/, GetProcessSP()); +} - return (pc & pac_sign_extension) ? pc | mask : pc & (~mask); +addr_t ABIMacOSX_arm64::FixDataAddress(addr_t addr) { + ProcessSP process_sp = GetProcessSP(); + return DoFixAddr(addr, false /*is_code*/, GetProcessSP()); } void ABIMacOSX_arm64::Initialize() { _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits