Skip to content

Commit 10b0e35

Browse files
authored
[lldb] Invert relationship between Process and AddressableBits (#85858)
AddressableBits is in the Utility module of LLDB. It currently directly refers to Process, which is from the Target LLDB module. This is a layering violation which concretely means that it is impossible to link anything that uses Utility without it also using Target as well. This is generally not an issue for LLDB (since everything is built together) but it may make it difficult to write unit tests for AddressableBits later on.
1 parent d42992e commit 10b0e35

File tree

6 files changed

+43
-23
lines changed

6 files changed

+43
-23
lines changed

lldb/include/lldb/Target/Process.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
#include "lldb/Target/ThreadList.h"
4444
#include "lldb/Target/ThreadPlanStack.h"
4545
#include "lldb/Target/Trace.h"
46+
#include "lldb/Utility/AddressableBits.h"
4647
#include "lldb/Utility/ArchSpec.h"
4748
#include "lldb/Utility/Broadcaster.h"
4849
#include "lldb/Utility/Event.h"
@@ -3219,6 +3220,8 @@ void PruneThreadPlans();
32193220

32203221
void LoadOperatingSystemPlugin(bool flush);
32213222

3223+
void SetAddressableBitMasks(AddressableBits bit_masks);
3224+
32223225
private:
32233226
Status DestroyImpl(bool force_kill);
32243227

lldb/include/lldb/Utility/AddressableBits.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,13 @@ class AddressableBits {
3232

3333
void SetLowmemAddressableBits(uint32_t lowmem_addressing_bits);
3434

35+
uint32_t GetLowmemAddressableBits() const;
36+
3537
void SetHighmemAddressableBits(uint32_t highmem_addressing_bits);
3638

37-
static lldb::addr_t AddressableBitToMask(uint32_t addressable_bits);
39+
uint32_t GetHighmemAddressableBits() const;
3840

39-
void SetProcessMasks(lldb_private::Process &process);
41+
static lldb::addr_t AddressableBitToMask(uint32_t addressable_bits);
4042

4143
private:
4244
uint32_t m_low_memory_addr_bits;

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -900,7 +900,7 @@ void ProcessGDBRemote::DidLaunchOrAttach(ArchSpec &process_arch) {
900900
}
901901

902902
AddressableBits addressable_bits = m_gdb_comm.GetAddressableBits();
903-
addressable_bits.SetProcessMasks(*this);
903+
SetAddressableBitMasks(addressable_bits);
904904

905905
if (process_arch.IsValid()) {
906906
const ArchSpec &target_arch = GetTarget().GetArchitecture();
@@ -2337,7 +2337,7 @@ StateType ProcessGDBRemote::SetThreadStopInfo(StringExtractor &stop_packet) {
23372337
}
23382338
}
23392339

2340-
addressable_bits.SetProcessMasks(*this);
2340+
SetAddressableBitMasks(addressable_bits);
23412341

23422342
ThreadSP thread_sp = SetThreadStopInfo(
23432343
tid, expedited_register_map, signo, thread_name, reason, description,

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -574,7 +574,7 @@ Status ProcessMachCore::DoLoadCore() {
574574
CleanupMemoryRegionPermissions();
575575

576576
AddressableBits addressable_bits = core_objfile->GetAddressableBits();
577-
addressable_bits.SetProcessMasks(*this);
577+
SetAddressableBitMasks(addressable_bits);
578578

579579
return error;
580580
}

lldb/source/Target/Process.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
#include "lldb/Target/ThreadPlanCallFunction.h"
6464
#include "lldb/Target/ThreadPlanStack.h"
6565
#include "lldb/Target/UnixSignals.h"
66+
#include "lldb/Utility/AddressableBits.h"
6667
#include "lldb/Utility/Event.h"
6768
#include "lldb/Utility/LLDBLog.h"
6869
#include "lldb/Utility/Log.h"
@@ -6453,3 +6454,25 @@ Status Process::CalculateCoreFileSaveRanges(lldb::SaveCoreStyle core_style,
64536454

64546455
return Status(); // Success!
64556456
}
6457+
6458+
void Process::SetAddressableBitMasks(AddressableBits bit_masks) {
6459+
uint32_t low_memory_addr_bits = bit_masks.GetLowmemAddressableBits();
6460+
uint32_t high_memory_addr_bits = bit_masks.GetHighmemAddressableBits();
6461+
6462+
if (low_memory_addr_bits == 0 && high_memory_addr_bits == 0)
6463+
return;
6464+
6465+
if (low_memory_addr_bits != 0) {
6466+
addr_t low_addr_mask =
6467+
AddressableBits::AddressableBitToMask(low_memory_addr_bits);
6468+
SetCodeAddressMask(low_addr_mask);
6469+
SetDataAddressMask(low_addr_mask);
6470+
}
6471+
6472+
if (high_memory_addr_bits != 0) {
6473+
addr_t high_addr_mask =
6474+
AddressableBits::AddressableBitToMask(high_memory_addr_bits);
6475+
SetHighmemCodeAddressMask(high_addr_mask);
6476+
SetHighmemDataAddressMask(high_addr_mask);
6477+
}
6478+
}

lldb/source/Utility/AddressableBits.cpp

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@
77
//===----------------------------------------------------------------------===//
88

99
#include "lldb/Utility/AddressableBits.h"
10-
#include "lldb/Target/Process.h"
1110
#include "lldb/lldb-types.h"
1211

12+
#include <cassert>
13+
1314
using namespace lldb;
1415
using namespace lldb_private;
1516

@@ -28,32 +29,23 @@ void AddressableBits::SetLowmemAddressableBits(
2829
m_low_memory_addr_bits = lowmem_addressing_bits;
2930
}
3031

32+
uint32_t AddressableBits::GetLowmemAddressableBits() const {
33+
return m_low_memory_addr_bits;
34+
}
35+
3136
void AddressableBits::SetHighmemAddressableBits(
3237
uint32_t highmem_addressing_bits) {
3338
m_high_memory_addr_bits = highmem_addressing_bits;
3439
}
3540

41+
uint32_t AddressableBits::GetHighmemAddressableBits() const {
42+
return m_high_memory_addr_bits;
43+
}
44+
3645
addr_t AddressableBits::AddressableBitToMask(uint32_t addressable_bits) {
3746
assert(addressable_bits <= sizeof(addr_t) * 8);
3847
if (addressable_bits == 64)
3948
return 0; // all bits used for addressing
4049
else
4150
return ~((1ULL << addressable_bits) - 1);
4251
}
43-
44-
void AddressableBits::SetProcessMasks(Process &process) {
45-
if (m_low_memory_addr_bits == 0 && m_high_memory_addr_bits == 0)
46-
return;
47-
48-
if (m_low_memory_addr_bits != 0) {
49-
addr_t low_addr_mask = AddressableBitToMask(m_low_memory_addr_bits);
50-
process.SetCodeAddressMask(low_addr_mask);
51-
process.SetDataAddressMask(low_addr_mask);
52-
}
53-
54-
if (m_high_memory_addr_bits != 0) {
55-
addr_t hi_addr_mask = AddressableBitToMask(m_high_memory_addr_bits);
56-
process.SetHighmemCodeAddressMask(hi_addr_mask);
57-
process.SetHighmemDataAddressMask(hi_addr_mask);
58-
}
59-
}

0 commit comments

Comments
 (0)