Skip to content

Commit a666286

Browse files
[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.
1 parent e3c7b7f commit a666286

File tree

1 file changed

+27
-30
lines changed

1 file changed

+27
-30
lines changed

lldb/source/Plugins/ABI/AArch64/ABIMacOSX_arm64.cpp

Lines changed: 27 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -757,42 +757,39 @@ ValueObjectSP ABIMacOSX_arm64::GetReturnValueObjectImpl(
757757
return return_valobj_sp;
758758
}
759759

760-
addr_t ABIMacOSX_arm64::FixCodeAddress(addr_t pc) {
761-
addr_t pac_sign_extension = 0x0080000000000000ULL;
762-
addr_t tbi_mask = 0xff80000000000000ULL;
763-
addr_t mask = 0;
764-
765-
if (ProcessSP process_sp = GetProcessSP()) {
766-
mask = process_sp->GetCodeAddressMask();
767-
if (pc & pac_sign_extension) {
768-
addr_t highmem_mask = process_sp->GetHighmemCodeAddressMask();
769-
if (highmem_mask != LLDB_INVALID_ADDRESS_MASK)
770-
mask = highmem_mask;
771-
}
772-
}
760+
constexpr addr_t tbi_mask = 0xff80000000000000ULL;
761+
constexpr addr_t pac_sign_extension = 0x0080000000000000ULL;
762+
763+
/// Consults the process for its {code, data} address masks and applies it to
764+
/// `addr`.
765+
static addr_t DoFixAddr(addr_t addr, bool is_code, ProcessSP process_sp) {
766+
if (!process_sp)
767+
return addr;
768+
769+
addr_t mask = is_code ? process_sp->GetCodeAddressMask()
770+
: process_sp->GetDataAddressMask();
773771
if (mask == LLDB_INVALID_ADDRESS_MASK)
774772
mask = tbi_mask;
775773

776-
return (pc & pac_sign_extension) ? pc | mask : pc & (~mask);
774+
if (addr & pac_sign_extension) {
775+
addr_t highmem_mask = is_code ? process_sp->GetHighmemCodeAddressMask()
776+
: process_sp->GetHighmemCodeAddressMask();
777+
if (highmem_mask != LLDB_INVALID_ADDRESS_MASK)
778+
return addr | highmem_mask;
779+
return addr | mask;
780+
}
781+
782+
return addr & (~mask);
777783
}
778784

779-
addr_t ABIMacOSX_arm64::FixDataAddress(addr_t pc) {
780-
addr_t pac_sign_extension = 0x0080000000000000ULL;
781-
addr_t tbi_mask = 0xff80000000000000ULL;
782-
addr_t mask = 0;
783-
784-
if (ProcessSP process_sp = GetProcessSP()) {
785-
mask = process_sp->GetDataAddressMask();
786-
if (pc & pac_sign_extension) {
787-
addr_t highmem_mask = process_sp->GetHighmemDataAddressMask();
788-
if (highmem_mask != LLDB_INVALID_ADDRESS_MASK)
789-
mask = highmem_mask;
790-
}
791-
}
792-
if (mask == LLDB_INVALID_ADDRESS_MASK)
793-
mask = tbi_mask;
785+
addr_t ABIMacOSX_arm64::FixCodeAddress(addr_t pc) {
786+
ProcessSP process_sp = GetProcessSP();
787+
return DoFixAddr(pc, true /*is_code*/, GetProcessSP());
788+
}
794789

795-
return (pc & pac_sign_extension) ? pc | mask : pc & (~mask);
790+
addr_t ABIMacOSX_arm64::FixDataAddress(addr_t addr) {
791+
ProcessSP process_sp = GetProcessSP();
792+
return DoFixAddr(addr, false /*is_code*/, GetProcessSP());
796793
}
797794

798795
void ABIMacOSX_arm64::Initialize() {

0 commit comments

Comments
 (0)