Skip to content

Commit 1fe7350

Browse files
committed
hi/low addr space bits can be sent in stop-rely packet
Add support for the `low_mem_addressing_bits` and `high_mem_addressing_bits` keys in the stop reply packet, in addition to the existing `addressing_bits`. Same behavior as in the qHostInfo packet. Clean up AddressableBits so we don't need to check if any values have been set in the object before using it to potentially update the Process address masks. Differential Revision: https://reviews.llvm.org/D158041 (cherry picked from commit 6f4a0c7)
1 parent 4043026 commit 1fe7350

File tree

10 files changed

+102
-56
lines changed

10 files changed

+102
-56
lines changed

lldb/docs/lldb-gdb-remote.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1621,6 +1621,18 @@ for this region.
16211621
// start code that may be changing the
16221622
// page table setup, a dynamically set
16231623
// value may be needed.
1624+
// "low_mem_addressing_bits" unsigned optional, specifies how many bits in
1625+
// addresses in low memory are significant
1626+
// for addressing, base 10. AArch64 can
1627+
// have different page table setups for low
1628+
// and high memory, and therefore a different
1629+
// number of bits used for addressing.
1630+
// "high_mem_addressing_bits" unsigned optional, specifies how many bits in
1631+
// addresses in high memory are significant
1632+
// for addressing, base 10. AArch64 can have
1633+
// different page table setups for low and
1634+
// high memory, and therefore a different
1635+
// number of bits used for addressing.
16241636
//
16251637
// BEST PRACTICES:
16261638
// Since register values can be supplied with this packet, it is often useful

lldb/include/lldb/Symbol/ObjectFile.h

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -521,15 +521,10 @@ class ObjectFile : public std::enable_shared_from_this<ObjectFile>,
521521
/// object files can return an AddressableBits object that can can be
522522
/// used to set the address masks in the Process.
523523
///
524-
/// \param[out] address_bits
525-
/// Can be used to set the Process address masks.
526-
///
527524
/// \return
528-
/// Returns true if addressable bits metadata was found.
529-
virtual bool GetAddressableBits(lldb_private::AddressableBits &address_bits) {
530-
address_bits.Clear();
531-
return false;
532-
}
525+
/// Returns an AddressableBits object which can be used to set
526+
/// the address masks in the Process.
527+
virtual lldb_private::AddressableBits GetAddressableBits() { return {}; }
533528

534529
/// When the ObjectFile is a core file, lldb needs to locate the "binary" in
535530
/// the core file. lldb can iterate over the pages looking for a valid

lldb/include/lldb/Utility/AddressableBits.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,11 @@ class AddressableBits {
2929
void SetAddressableBits(uint32_t lowmem_addressing_bits,
3030
uint32_t highmem_addressing_bits);
3131

32-
void SetProcessMasks(lldb_private::Process &process);
32+
void SetLowmemAddressableBits(uint32_t lowmem_addressing_bits);
33+
34+
void SetHighmemAddressableBits(uint32_t highmem_addressing_bits);
3335

34-
void Clear();
36+
void SetProcessMasks(lldb_private::Process &process);
3537

3638
private:
3739
uint32_t m_low_memory_addr_bits;

lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5533,8 +5533,8 @@ std::string ObjectFileMachO::GetIdentifierString() {
55335533
return result;
55345534
}
55355535

5536-
bool ObjectFileMachO::GetAddressableBits(AddressableBits &address_bits) {
5537-
address_bits.Clear();
5536+
AddressableBits ObjectFileMachO::GetAddressableBits() {
5537+
AddressableBits addressable_bits;
55385538

55395539
Log *log(GetLog(LLDBLog::Process));
55405540
ModuleSP module_sp(GetModule());
@@ -5562,32 +5562,32 @@ bool ObjectFileMachO::GetAddressableBits(AddressableBits &address_bits) {
55625562
if (version == 3) {
55635563
uint32_t num_addr_bits = m_data.GetU32_unchecked(&offset);
55645564
if (num_addr_bits != 0) {
5565-
address_bits.SetAddressableBits(num_addr_bits);
5565+
addressable_bits.SetAddressableBits(num_addr_bits);
55665566
}
55675567
LLDB_LOGF(log,
55685568
"LC_NOTE 'addrable bits' v3 found, value %d "
55695569
"bits",
55705570
num_addr_bits);
5571-
return true;
5571+
break;
55725572
}
55735573
if (version == 4) {
55745574
uint32_t lo_addr_bits = m_data.GetU32_unchecked(&offset);
55755575
uint32_t hi_addr_bits = m_data.GetU32_unchecked(&offset);
55765576

5577-
address_bits.SetAddressableBits(lo_addr_bits, hi_addr_bits);
5577+
addressable_bits.SetAddressableBits(lo_addr_bits, hi_addr_bits);
55785578
LLDB_LOGF(log,
55795579
"LC_NOTE 'addrable bits' v4 found, value %d & %d bits",
55805580
lo_addr_bits, hi_addr_bits);
55815581

5582-
return true;
5582+
break;
55835583
}
55845584
}
55855585
}
55865586
}
55875587
offset = cmd_offset + lc.cmdsize;
55885588
}
55895589
}
5590-
return false;
5590+
return addressable_bits;
55915591
}
55925592

55935593
bool ObjectFileMachO::GetCorefileMainBinaryInfo(addr_t &value,

lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ class ObjectFileMachO : public lldb_private::ObjectFile {
121121

122122
std::string GetIdentifierString() override;
123123

124-
bool GetAddressableBits(lldb_private::AddressableBits &address_bits) override;
124+
lldb_private::AddressableBits GetAddressableBits() override;
125125

126126
bool GetCorefileMainBinaryInfo(lldb::addr_t &value, bool &value_is_offset,
127127
lldb_private::UUID &uuid,

lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1412,17 +1412,17 @@ GDBRemoteCommunicationClient::GetHostArchitecture() {
14121412
return m_host_arch;
14131413
}
14141414

1415-
bool GDBRemoteCommunicationClient::GetAddressableBits(
1416-
lldb_private::AddressableBits &addressable_bits) {
1417-
addressable_bits.Clear();
1415+
AddressableBits GDBRemoteCommunicationClient::GetAddressableBits() {
1416+
AddressableBits addressable_bits;
14181417
if (m_qHostInfo_is_valid == eLazyBoolCalculate)
14191418
GetHostInfo();
1420-
if (m_low_mem_addressing_bits != 0 || m_high_mem_addressing_bits != 0) {
1421-
addressable_bits.SetAddressableBits(m_low_mem_addressing_bits,
1422-
m_high_mem_addressing_bits);
1423-
return true;
1424-
}
1425-
return false;
1419+
1420+
// m_low_mem_addressing_bits and m_high_mem_addressing_bits
1421+
// will be 0 if we did not receive values; AddressableBits
1422+
// treats 0 as "unspecified".
1423+
addressable_bits.SetAddressableBits(m_low_mem_addressing_bits,
1424+
m_high_mem_addressing_bits);
1425+
return addressable_bits;
14261426
}
14271427

14281428
seconds GDBRemoteCommunicationClient::GetHostDefaultPacketTimeout() {

lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ class GDBRemoteCommunicationClient : public GDBRemoteClientBase {
238238

239239
ArchSpec GetSystemArchitecture();
240240

241-
bool GetAddressableBits(lldb_private::AddressableBits &addressable_bits);
241+
lldb_private::AddressableBits GetAddressableBits();
242242

243243
bool GetHostname(std::string &s);
244244

lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -892,10 +892,8 @@ void ProcessGDBRemote::DidLaunchOrAttach(ArchSpec &process_arch) {
892892
process_arch.GetTriple().getTriple());
893893
}
894894

895-
AddressableBits addressable_bits;
896-
if (m_gdb_comm.GetAddressableBits(addressable_bits)) {
897-
addressable_bits.SetProcessMasks(*this);
898-
}
895+
AddressableBits addressable_bits = m_gdb_comm.GetAddressableBits();
896+
addressable_bits.SetProcessMasks(*this);
899897

900898
if (process_arch.IsValid()) {
901899
const ArchSpec &target_arch = GetTarget().GetArchitecture();
@@ -2103,6 +2101,7 @@ StateType ProcessGDBRemote::SetThreadStopInfo(StringExtractor &stop_packet) {
21032101
QueueKind queue_kind = eQueueKindUnknown;
21042102
uint64_t queue_serial_number = 0;
21052103
ExpeditedRegisterMap expedited_register_map;
2104+
AddressableBits addressable_bits;
21062105
while (stop_packet.GetNameColonValue(key, value)) {
21072106
if (key.compare("metype") == 0) {
21082107
// exception type in big endian hex
@@ -2247,9 +2246,17 @@ StateType ProcessGDBRemote::SetThreadStopInfo(StringExtractor &stop_packet) {
22472246
} else if (key.compare("addressing_bits") == 0) {
22482247
uint64_t addressing_bits;
22492248
if (!value.getAsInteger(0, addressing_bits)) {
2250-
addr_t address_mask = ~((1ULL << addressing_bits) - 1);
2251-
SetCodeAddressMask(address_mask);
2252-
SetDataAddressMask(address_mask);
2249+
addressable_bits.SetAddressableBits(addressing_bits);
2250+
}
2251+
} else if (key.compare("low_mem_addressing_bits") == 0) {
2252+
uint64_t addressing_bits;
2253+
if (!value.getAsInteger(0, addressing_bits)) {
2254+
addressable_bits.SetLowmemAddressableBits(addressing_bits);
2255+
}
2256+
} else if (key.compare("high_mem_addressing_bits") == 0) {
2257+
uint64_t addressing_bits;
2258+
if (!value.getAsInteger(0, addressing_bits)) {
2259+
addressable_bits.SetHighmemAddressableBits(addressing_bits);
22532260
}
22542261
} else if (key.size() == 2 && ::isxdigit(key[0]) && ::isxdigit(key[1])) {
22552262
uint32_t reg = UINT32_MAX;
@@ -2278,6 +2285,8 @@ StateType ProcessGDBRemote::SetThreadStopInfo(StringExtractor &stop_packet) {
22782285
}
22792286
}
22802287

2288+
addressable_bits.SetProcessMasks(*this);
2289+
22812290
ThreadSP thread_sp = SetThreadStopInfo(
22822291
tid, expedited_register_map, signo, thread_name, reason, description,
22832292
exc_type, exc_data, thread_dispatch_qaddr, queue_vars_valid,

lldb/source/Plugins/Process/mach-core/ProcessMachCore.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -574,10 +574,9 @@ Status ProcessMachCore::DoLoadCore() {
574574

575575
CleanupMemoryRegionPermissions();
576576

577-
AddressableBits addressable_bits;
578-
if (core_objfile->GetAddressableBits(addressable_bits)) {
579-
addressable_bits.SetProcessMasks(*this);
580-
}
577+
AddressableBits addressable_bits = core_objfile->GetAddressableBits();
578+
addressable_bits.SetProcessMasks(*this);
579+
581580
return error;
582581
}
583582

lldb/source/Utility/AddressableBits.cpp

Lines changed: 46 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -23,28 +23,57 @@ void AddressableBits::SetAddressableBits(uint32_t lowmem_addressing_bits,
2323
m_high_memory_addr_bits = highmem_addressing_bits;
2424
}
2525

26-
void AddressableBits::Clear() {
27-
m_low_memory_addr_bits = m_high_memory_addr_bits = 0;
26+
void AddressableBits::SetLowmemAddressableBits(
27+
uint32_t lowmem_addressing_bits) {
28+
m_low_memory_addr_bits = lowmem_addressing_bits;
29+
}
30+
31+
void AddressableBits::SetHighmemAddressableBits(
32+
uint32_t highmem_addressing_bits) {
33+
m_high_memory_addr_bits = highmem_addressing_bits;
2834
}
2935

3036
void AddressableBits::SetProcessMasks(Process &process) {
31-
// In case either value is set to 0, indicating it was not set, use the
32-
// other value.
33-
if (m_low_memory_addr_bits == 0)
34-
m_low_memory_addr_bits = m_high_memory_addr_bits;
35-
if (m_high_memory_addr_bits == 0)
36-
m_high_memory_addr_bits = m_low_memory_addr_bits;
37-
38-
if (m_low_memory_addr_bits == 0)
37+
if (m_low_memory_addr_bits == 0 && m_high_memory_addr_bits == 0)
3938
return;
4039

41-
addr_t address_mask = ~((1ULL << m_low_memory_addr_bits) - 1);
42-
process.SetCodeAddressMask(address_mask);
43-
process.SetDataAddressMask(address_mask);
40+
// If we don't have an addressable bits value for low memory,
41+
// see if we have a Code/Data mask already, and use that.
42+
// Or use the high memory addressable bits value as a last
43+
// resort.
44+
addr_t low_addr_mask;
45+
if (m_low_memory_addr_bits == 0) {
46+
if (process.GetCodeAddressMask() != UINT64_MAX)
47+
low_addr_mask = process.GetCodeAddressMask();
48+
else if (process.GetDataAddressMask() != UINT64_MAX)
49+
low_addr_mask = process.GetDataAddressMask();
50+
else
51+
low_addr_mask = ~((1ULL << m_high_memory_addr_bits) - 1);
52+
} else {
53+
low_addr_mask = ~((1ULL << m_low_memory_addr_bits) - 1);
54+
}
55+
56+
// If we don't have an addressable bits value for high memory,
57+
// see if we have a Code/Data mask already, and use that.
58+
// Or use the low memory addressable bits value as a last
59+
// resort.
60+
addr_t hi_addr_mask;
61+
if (m_high_memory_addr_bits == 0) {
62+
if (process.GetHighmemCodeAddressMask() != UINT64_MAX)
63+
hi_addr_mask = process.GetHighmemCodeAddressMask();
64+
else if (process.GetHighmemDataAddressMask() != UINT64_MAX)
65+
hi_addr_mask = process.GetHighmemDataAddressMask();
66+
else
67+
hi_addr_mask = ~((1ULL << m_low_memory_addr_bits) - 1);
68+
} else {
69+
hi_addr_mask = ~((1ULL << m_high_memory_addr_bits) - 1);
70+
}
71+
72+
process.SetCodeAddressMask(low_addr_mask);
73+
process.SetDataAddressMask(low_addr_mask);
4474

45-
if (m_low_memory_addr_bits != m_high_memory_addr_bits) {
46-
lldb::addr_t hi_address_mask = ~((1ULL << m_high_memory_addr_bits) - 1);
47-
process.SetHighmemCodeAddressMask(hi_address_mask);
48-
process.SetHighmemDataAddressMask(hi_address_mask);
75+
if (low_addr_mask != hi_addr_mask) {
76+
process.SetHighmemCodeAddressMask(hi_addr_mask);
77+
process.SetHighmemDataAddressMask(hi_addr_mask);
4978
}
5079
}

0 commit comments

Comments
 (0)