Skip to content

Commit 6f4a0c7

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
1 parent 6664e80 commit 6f4a0c7

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
@@ -1661,6 +1661,18 @@ for this region.
16611661
// start code that may be changing the
16621662
// page table setup, a dynamically set
16631663
// value may be needed.
1664+
// "low_mem_addressing_bits" unsigned optional, specifies how many bits in
1665+
// addresses in low memory are significant
1666+
// for addressing, base 10. AArch64 can
1667+
// have different page table setups for low
1668+
// and high memory, and therefore a different
1669+
// number of bits used for addressing.
1670+
// "high_mem_addressing_bits" unsigned optional, specifies how many bits in
1671+
// addresses in high memory are significant
1672+
// for addressing, base 10. AArch64 can have
1673+
// different page table setups for low and
1674+
// high memory, and therefore a different
1675+
// number of bits used for addressing.
16641676
//
16651677
// BEST PRACTICES:
16661678
// 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
@@ -498,15 +498,10 @@ class ObjectFile : public std::enable_shared_from_this<ObjectFile>,
498498
/// object files can return an AddressableBits object that can can be
499499
/// used to set the address masks in the Process.
500500
///
501-
/// \param[out] address_bits
502-
/// Can be used to set the Process address masks.
503-
///
504501
/// \return
505-
/// Returns true if addressable bits metadata was found.
506-
virtual bool GetAddressableBits(lldb_private::AddressableBits &address_bits) {
507-
address_bits.Clear();
508-
return false;
509-
}
502+
/// Returns an AddressableBits object which can be used to set
503+
/// the address masks in the Process.
504+
virtual lldb_private::AddressableBits GetAddressableBits() { return {}; }
510505

511506
/// When the ObjectFile is a core file, lldb needs to locate the "binary" in
512507
/// 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
@@ -5486,8 +5486,8 @@ std::string ObjectFileMachO::GetIdentifierString() {
54865486
return result;
54875487
}
54885488

5489-
bool ObjectFileMachO::GetAddressableBits(AddressableBits &address_bits) {
5490-
address_bits.Clear();
5489+
AddressableBits ObjectFileMachO::GetAddressableBits() {
5490+
AddressableBits addressable_bits;
54915491

54925492
Log *log(GetLog(LLDBLog::Process));
54935493
ModuleSP module_sp(GetModule());
@@ -5515,32 +5515,32 @@ bool ObjectFileMachO::GetAddressableBits(AddressableBits &address_bits) {
55155515
if (version == 3) {
55165516
uint32_t num_addr_bits = m_data.GetU32_unchecked(&offset);
55175517
if (num_addr_bits != 0) {
5518-
address_bits.SetAddressableBits(num_addr_bits);
5518+
addressable_bits.SetAddressableBits(num_addr_bits);
55195519
}
55205520
LLDB_LOGF(log,
55215521
"LC_NOTE 'addrable bits' v3 found, value %d "
55225522
"bits",
55235523
num_addr_bits);
5524-
return true;
5524+
break;
55255525
}
55265526
if (version == 4) {
55275527
uint32_t lo_addr_bits = m_data.GetU32_unchecked(&offset);
55285528
uint32_t hi_addr_bits = m_data.GetU32_unchecked(&offset);
55295529

5530-
address_bits.SetAddressableBits(lo_addr_bits, hi_addr_bits);
5530+
addressable_bits.SetAddressableBits(lo_addr_bits, hi_addr_bits);
55315531
LLDB_LOGF(log,
55325532
"LC_NOTE 'addrable bits' v4 found, value %d & %d bits",
55335533
lo_addr_bits, hi_addr_bits);
55345534

5535-
return true;
5535+
break;
55365536
}
55375537
}
55385538
}
55395539
}
55405540
offset = cmd_offset + lc.cmdsize;
55415541
}
55425542
}
5543-
return false;
5543+
return addressable_bits;
55445544
}
55455545

55465546
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
@@ -122,7 +122,7 @@ class ObjectFileMachO : public lldb_private::ObjectFile {
122122

123123
std::string GetIdentifierString() override;
124124

125-
bool GetAddressableBits(lldb_private::AddressableBits &address_bits) override;
125+
lldb_private::AddressableBits GetAddressableBits() override;
126126

127127
bool GetCorefileMainBinaryInfo(lldb::addr_t &value, bool &value_is_offset,
128128
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
@@ -1415,17 +1415,17 @@ GDBRemoteCommunicationClient::GetHostArchitecture() {
14151415
return m_host_arch;
14161416
}
14171417

1418-
bool GDBRemoteCommunicationClient::GetAddressableBits(
1419-
lldb_private::AddressableBits &addressable_bits) {
1420-
addressable_bits.Clear();
1418+
AddressableBits GDBRemoteCommunicationClient::GetAddressableBits() {
1419+
AddressableBits addressable_bits;
14211420
if (m_qHostInfo_is_valid == eLazyBoolCalculate)
14221421
GetHostInfo();
1423-
if (m_low_mem_addressing_bits != 0 || m_high_mem_addressing_bits != 0) {
1424-
addressable_bits.SetAddressableBits(m_low_mem_addressing_bits,
1425-
m_high_mem_addressing_bits);
1426-
return true;
1427-
}
1428-
return false;
1422+
1423+
// m_low_mem_addressing_bits and m_high_mem_addressing_bits
1424+
// will be 0 if we did not receive values; AddressableBits
1425+
// treats 0 as "unspecified".
1426+
addressable_bits.SetAddressableBits(m_low_mem_addressing_bits,
1427+
m_high_mem_addressing_bits);
1428+
return addressable_bits;
14291429
}
14301430

14311431
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
@@ -899,10 +899,8 @@ void ProcessGDBRemote::DidLaunchOrAttach(ArchSpec &process_arch) {
899899
process_arch.GetTriple().getTriple());
900900
}
901901

902-
AddressableBits addressable_bits;
903-
if (m_gdb_comm.GetAddressableBits(addressable_bits)) {
904-
addressable_bits.SetProcessMasks(*this);
905-
}
902+
AddressableBits addressable_bits = m_gdb_comm.GetAddressableBits();
903+
addressable_bits.SetProcessMasks(*this);
906904

907905
if (process_arch.IsValid()) {
908906
const ArchSpec &target_arch = GetTarget().GetArchitecture();
@@ -2124,6 +2122,7 @@ StateType ProcessGDBRemote::SetThreadStopInfo(StringExtractor &stop_packet) {
21242122
QueueKind queue_kind = eQueueKindUnknown;
21252123
uint64_t queue_serial_number = 0;
21262124
ExpeditedRegisterMap expedited_register_map;
2125+
AddressableBits addressable_bits;
21272126
while (stop_packet.GetNameColonValue(key, value)) {
21282127
if (key.compare("metype") == 0) {
21292128
// exception type in big endian hex
@@ -2271,9 +2270,17 @@ StateType ProcessGDBRemote::SetThreadStopInfo(StringExtractor &stop_packet) {
22712270
} else if (key.compare("addressing_bits") == 0) {
22722271
uint64_t addressing_bits;
22732272
if (!value.getAsInteger(0, addressing_bits)) {
2274-
addr_t address_mask = ~((1ULL << addressing_bits) - 1);
2275-
SetCodeAddressMask(address_mask);
2276-
SetDataAddressMask(address_mask);
2273+
addressable_bits.SetAddressableBits(addressing_bits);
2274+
}
2275+
} else if (key.compare("low_mem_addressing_bits") == 0) {
2276+
uint64_t addressing_bits;
2277+
if (!value.getAsInteger(0, addressing_bits)) {
2278+
addressable_bits.SetLowmemAddressableBits(addressing_bits);
2279+
}
2280+
} else if (key.compare("high_mem_addressing_bits") == 0) {
2281+
uint64_t addressing_bits;
2282+
if (!value.getAsInteger(0, addressing_bits)) {
2283+
addressable_bits.SetHighmemAddressableBits(addressing_bits);
22772284
}
22782285
} else if (key.size() == 2 && ::isxdigit(key[0]) && ::isxdigit(key[1])) {
22792286
uint32_t reg = UINT32_MAX;
@@ -2302,6 +2309,8 @@ StateType ProcessGDBRemote::SetThreadStopInfo(StringExtractor &stop_packet) {
23022309
}
23032310
}
23042311

2312+
addressable_bits.SetProcessMasks(*this);
2313+
23052314
ThreadSP thread_sp = SetThreadStopInfo(
23062315
tid, expedited_register_map, signo, thread_name, reason, description,
23072316
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)