Skip to content

Cp/add fixaddress sbprocess apis #8347

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

jasonmolenda
Copy link

No description provided.

jasonmolenda and others added 2 commits March 6, 2024 18:23
…3663)

[lldb] Add SBProcess methods for get/set/use address masks (llvm#83095)

I'm reviving a patch from phabracator, https://reviews.llvm.org/D155905
which was approved but I wasn't thrilled with all the API I was adding
to SBProcess for all of the address mask types / memory regions. In this
update, I added enums to control type address mask type (code, data,
any) and address space specifiers (low, high, all) with defaulted
arguments for the most common case.  I originally landed this via
llvm#83095 but it failed on CIs
outside of arm64 Darwin so I had to debug it on more environments
and update the patch.

This patch is also fixing a bug in the "addressable bits to address
mask" calculation I added in AddressableBits::SetProcessMasks. If lldb
were told that 64 bits are valid for addressing, this method would
overflow the calculation and set an invalid mask. Added tests to check
this specific bug while I was adding these APIs.

This patch changes the value of "no mask set" from 0 to
LLDB_INVALID_ADDRESS_MASK, which is UINT64_MAX. A mask of all 1's
means "no bits are used for addressing" which is an impossible mask,
whereas a mask of 0 means "all bits are used for addressing" which
is possible.

I added a base class implementation of ABI::FixCodeAddress and
ABI::FixDataAddress that will apply the Process mask values if they
are set to a value other than LLDB_INVALID_ADDRESS_MASK.

I updated all the callers/users of the Mask methods which were
handling a value of 0 to mean invalid mask to use
LLDB_INVALID_ADDRESS_MASK.

I added code to the all AArch64 ABI Fix* methods to apply the
Highmem masks if they have been set.  These will not be set on a
Linux environment, but in TestAddressMasks.py I test the highmem
masks feature for any AArch64 target, so all AArch64 ABI  plugins
must handle it.

rdar://123530562
(cherry picked from commit aeaa11a)
TestAddressMasks failed on the lldb-arm-buntu bot with the
Code address mask test,

        mask = process.GetAddressMask(lldb.eAddressMaskTypeAny)
        process.SetAddressMask(lldb.eAddressMaskTypeCode, mask | 0x3)
        self.assertEqual(
            0x000002950001F694,
            process.FixAddress(0x00265E950001F697, lldb.eAddressMaskTypeCode),
        )

The API returned 0x000002950001f694 instead of the expected
0x00265e950001f696.  The low bits differ because ABISysV_arm hardcodes
the Code address mask to clear the 0th bit, it doesn't use the
Process code mask.  I didn't debug why some of the high bytes were
dropped.  The address mask APIs are only important on 64-bit targets,
where many of the bits are not used for addressing and are used for
metadata instead, so I'm going to skip these tests on 32-bit arm
instead of debugging.

(cherry picked from commit 04bbbba)
@jasonmolenda
Copy link
Author

@swift-ci test

@jasonmolenda
Copy link
Author

@swift-ci test

@jasonmolenda
Copy link
Author

@swift-ci test linux

to match the new mask illegal value, and simplfy by grabbing
the Data mask which is more general than the Code mask and is
used everywhere when we don't know the type of the data.
@jasonmolenda
Copy link
Author

@augusto2112 the 4th commit on this PR is a change to LLDBMemoryReader::queryDataLayout's DLQ_GetPtrAuthMask if you'd like to look at it. I changed the value of "no mask" and this needed to be updated to match, it was resulting in test failures on Intel systems where there is no mask.

@jasonmolenda
Copy link
Author

I'm putting off PR testing tonight because github main branch testing fails because of a compilation error in swift-docc, but I'll test tomorrow once that's been looked at.

@jasonmolenda
Copy link
Author

@swift-ci test

@augusto2112
Copy link

@swift-ci test windows

@jasonmolenda
Copy link
Author

@augusto2112 the PR testing passed. Are you OK with my change to the swift metadata mask getter?

@jasonmolenda jasonmolenda merged commit f9fc88d into swiftlang:stable/20230725 Mar 12, 2024
@jasonmolenda jasonmolenda deleted the cp/add-fixaddress-sbprocess-apis branch March 12, 2024 22:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants