[lldb] Address mask sbprocess apis and new mask invalid const (#83663)

[lldb] Add SBProcess methods for get/set/use address masks (#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
https://github.com/llvm/llvm-project/pull/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
This commit is contained in:
Jason Molenda
2024-03-06 10:06:56 -08:00
committed by GitHub
parent dcd08daed5
commit aeaa11aeac
19 changed files with 517 additions and 45 deletions

View File

@@ -1255,6 +1255,98 @@ lldb::SBFileSpec SBProcess::GetCoreFile() {
return SBFileSpec(core_file);
}
addr_t SBProcess::GetAddressMask(AddressMaskType type,
AddressMaskRange addr_range) {
LLDB_INSTRUMENT_VA(this, type, addr_range);
if (ProcessSP process_sp = GetSP()) {
switch (type) {
case eAddressMaskTypeCode:
if (addr_range == eAddressMaskRangeHigh)
return process_sp->GetHighmemCodeAddressMask();
else
return process_sp->GetCodeAddressMask();
case eAddressMaskTypeData:
if (addr_range == eAddressMaskRangeHigh)
return process_sp->GetHighmemDataAddressMask();
else
return process_sp->GetDataAddressMask();
case eAddressMaskTypeAny:
if (addr_range == eAddressMaskRangeHigh)
return process_sp->GetHighmemDataAddressMask();
else
return process_sp->GetDataAddressMask();
}
}
return LLDB_INVALID_ADDRESS_MASK;
}
void SBProcess::SetAddressMask(AddressMaskType type, addr_t mask,
AddressMaskRange addr_range) {
LLDB_INSTRUMENT_VA(this, type, mask, addr_range);
if (ProcessSP process_sp = GetSP()) {
switch (type) {
case eAddressMaskTypeCode:
if (addr_range == eAddressMaskRangeAll) {
process_sp->SetCodeAddressMask(mask);
process_sp->SetHighmemCodeAddressMask(mask);
} else if (addr_range == eAddressMaskRangeHigh) {
process_sp->SetHighmemCodeAddressMask(mask);
} else {
process_sp->SetCodeAddressMask(mask);
}
break;
case eAddressMaskTypeData:
if (addr_range == eAddressMaskRangeAll) {
process_sp->SetDataAddressMask(mask);
process_sp->SetHighmemDataAddressMask(mask);
} else if (addr_range == eAddressMaskRangeHigh) {
process_sp->SetHighmemDataAddressMask(mask);
} else {
process_sp->SetDataAddressMask(mask);
}
break;
case eAddressMaskTypeAll:
if (addr_range == eAddressMaskRangeAll) {
process_sp->SetCodeAddressMask(mask);
process_sp->SetDataAddressMask(mask);
process_sp->SetHighmemCodeAddressMask(mask);
process_sp->SetHighmemDataAddressMask(mask);
} else if (addr_range == eAddressMaskRangeHigh) {
process_sp->SetHighmemCodeAddressMask(mask);
process_sp->SetHighmemDataAddressMask(mask);
} else {
process_sp->SetCodeAddressMask(mask);
process_sp->SetDataAddressMask(mask);
}
break;
}
}
}
void SBProcess::SetAddressableBits(AddressMaskType type, uint32_t num_bits,
AddressMaskRange addr_range) {
LLDB_INSTRUMENT_VA(this, type, num_bits, addr_range);
SetAddressMask(type, AddressableBits::AddressableBitToMask(num_bits),
addr_range);
}
addr_t SBProcess::FixAddress(addr_t addr, AddressMaskType type) {
LLDB_INSTRUMENT_VA(this, addr, type);
if (ProcessSP process_sp = GetSP()) {
if (type == eAddressMaskTypeAny)
return process_sp->FixAnyAddress(addr);
else if (type == eAddressMaskTypeData)
return process_sp->FixDataAddress(addr);
else if (type == eAddressMaskTypeCode)
return process_sp->FixCodeAddress(addr);
}
return addr;
}
lldb::addr_t SBProcess::AllocateMemory(size_t size, uint32_t permissions,
lldb::SBError &sb_error) {
LLDB_INSTRUMENT_VA(this, size, permissions, sb_error);