[Lldb-commits] [lldb] [lldb][NFC] Simplify logic in ABIMacOSX_arm64::FixDataAddress (PR #159612)
Felipe de Azevedo Piovezan via lldb-commits
lldb-commits at lists.llvm.org
Thu Sep 18 10:36:18 PDT 2025
https://github.com/felipepiovezan created https://github.com/llvm/llvm-project/pull/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.
>From 9214bba07c1e0e0795d2a963d4161b208f96ed85 Mon Sep 17 00:00:00 2001
From: Felipe de Azevedo Piovezan <fpiovezan at apple.com>
Date: Mon, 15 Sep 2025 15:53:39 -0700
Subject: [PATCH 1/2] [lldb][NFC] Simplify logic in
ABIMacOSX_arm64::FixDataAddress
---
.../Plugins/ABI/AArch64/ABIMacOSX_arm64.cpp | 52 ++++++++++---------
1 file changed, 28 insertions(+), 24 deletions(-)
diff --git a/lldb/source/Plugins/ABI/AArch64/ABIMacOSX_arm64.cpp b/lldb/source/Plugins/ABI/AArch64/ABIMacOSX_arm64.cpp
index 094e0523a4edf..db4e73ba76544 100644
--- a/lldb/source/Plugins/ABI/AArch64/ABIMacOSX_arm64.cpp
+++ b/lldb/source/Plugins/ABI/AArch64/ABIMacOSX_arm64.cpp
@@ -758,41 +758,45 @@ ValueObjectSP ABIMacOSX_arm64::GetReturnValueObjectImpl(
}
addr_t ABIMacOSX_arm64::FixCodeAddress(addr_t pc) {
- addr_t pac_sign_extension = 0x0080000000000000ULL;
+ ProcessSP process_sp = GetProcessSP();
+ if (!process_sp)
+ return pc;
+
+ addr_t mask = process_sp->GetCodeAddressMask();
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;
- }
- }
if (mask == LLDB_INVALID_ADDRESS_MASK)
mask = tbi_mask;
- return (pc & pac_sign_extension) ? pc | mask : pc & (~mask);
+ addr_t pac_sign_extension = 0x0080000000000000ULL;
+ if (pc & pac_sign_extension) {
+ addr_t highmem_mask = process_sp->GetHighmemCodeAddressMask();
+ if (highmem_mask != LLDB_INVALID_ADDRESS_MASK)
+ return pc | highmem_mask;
+ return pc | mask;
+ }
+
+ return pc & (~mask);
}
addr_t ABIMacOSX_arm64::FixDataAddress(addr_t pc) {
- addr_t pac_sign_extension = 0x0080000000000000ULL;
+ ProcessSP process_sp = GetProcessSP();
+ if (!process_sp)
+ return pc;
+
+ addr_t mask = process_sp->GetDataAddressMask();
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;
- return (pc & pac_sign_extension) ? pc | mask : pc & (~mask);
+ addr_t pac_sign_extension = 0x0080000000000000ULL;
+ if (pc & pac_sign_extension) {
+ addr_t highmem_mask = process_sp->GetHighmemDataAddressMask();
+ if (highmem_mask != LLDB_INVALID_ADDRESS_MASK)
+ return pc | highmem_mask;
+ return pc | mask;
+ }
+
+ return pc & (~mask);
}
void ABIMacOSX_arm64::Initialize() {
>From 3243ab7bced75c3e69469e8270c16e284af68a19 Mon Sep 17 00:00:00 2001
From: Felipe de Azevedo Piovezan <fpiovezan at apple.com>
Date: Thu, 18 Sep 2025 10:29:58 -0700
Subject: [PATCH 2/2] fixup! Reuse code across functions
---
.../Plugins/ABI/AArch64/ABIMacOSX_arm64.cpp | 47 ++++++++-----------
1 file changed, 19 insertions(+), 28 deletions(-)
diff --git a/lldb/source/Plugins/ABI/AArch64/ABIMacOSX_arm64.cpp b/lldb/source/Plugins/ABI/AArch64/ABIMacOSX_arm64.cpp
index db4e73ba76544..16aafe640b1a4 100644
--- a/lldb/source/Plugins/ABI/AArch64/ABIMacOSX_arm64.cpp
+++ b/lldb/source/Plugins/ABI/AArch64/ABIMacOSX_arm64.cpp
@@ -757,46 +757,37 @@ ValueObjectSP ABIMacOSX_arm64::GetReturnValueObjectImpl(
return return_valobj_sp;
}
-addr_t ABIMacOSX_arm64::FixCodeAddress(addr_t pc) {
- ProcessSP process_sp = GetProcessSP();
+constexpr addr_t tbi_mask = 0xff80000000000000ULL;
+constexpr addr_t pac_sign_extension = 0x0080000000000000ULL;
+
+static addr_t DoFixAddr(addr_t addr, bool is_code, ProcessSP process_sp) {
if (!process_sp)
- return pc;
+ return addr;
- addr_t mask = process_sp->GetCodeAddressMask();
- addr_t tbi_mask = 0xff80000000000000ULL;
+ addr_t mask = is_code ? process_sp->GetCodeAddressMask()
+ : process_sp->GetDataAddressMask();
if (mask == LLDB_INVALID_ADDRESS_MASK)
mask = tbi_mask;
- addr_t pac_sign_extension = 0x0080000000000000ULL;
- if (pc & pac_sign_extension) {
- addr_t highmem_mask = process_sp->GetHighmemCodeAddressMask();
+ 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 pc | highmem_mask;
- return pc | mask;
+ return addr | highmem_mask;
+ return addr | mask;
}
- return pc & (~mask);
+ return addr & (~mask);
}
-addr_t ABIMacOSX_arm64::FixDataAddress(addr_t pc) {
+addr_t ABIMacOSX_arm64::FixCodeAddress(addr_t pc) {
ProcessSP process_sp = GetProcessSP();
- if (!process_sp)
- return pc;
-
- addr_t mask = process_sp->GetDataAddressMask();
- addr_t tbi_mask = 0xff80000000000000ULL;
- if (mask == LLDB_INVALID_ADDRESS_MASK)
- mask = tbi_mask;
-
- addr_t pac_sign_extension = 0x0080000000000000ULL;
- if (pc & pac_sign_extension) {
- addr_t highmem_mask = process_sp->GetHighmemDataAddressMask();
- if (highmem_mask != LLDB_INVALID_ADDRESS_MASK)
- return pc | highmem_mask;
- return pc | mask;
- }
+ return DoFixAddr(pc, true /*is_code*/, GetProcessSP());
+}
- return 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() {
More information about the lldb-commits
mailing list