Skip to content

[lldb] Invert relationship between Process and AddressableBits #85858

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

Merged
merged 1 commit into from
Mar 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions lldb/include/lldb/Target/Process.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
#include "lldb/Target/ThreadList.h"
#include "lldb/Target/ThreadPlanStack.h"
#include "lldb/Target/Trace.h"
#include "lldb/Utility/AddressableBits.h"
#include "lldb/Utility/ArchSpec.h"
#include "lldb/Utility/Broadcaster.h"
#include "lldb/Utility/Event.h"
Expand Down Expand Up @@ -3219,6 +3220,8 @@ void PruneThreadPlans();

void LoadOperatingSystemPlugin(bool flush);

void SetAddressableBitMasks(AddressableBits bit_masks);

private:
Status DestroyImpl(bool force_kill);

Expand Down
6 changes: 4 additions & 2 deletions lldb/include/lldb/Utility/AddressableBits.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,13 @@ class AddressableBits {

void SetLowmemAddressableBits(uint32_t lowmem_addressing_bits);

uint32_t GetLowmemAddressableBits() const;

void SetHighmemAddressableBits(uint32_t highmem_addressing_bits);

static lldb::addr_t AddressableBitToMask(uint32_t addressable_bits);
uint32_t GetHighmemAddressableBits() const;

void SetProcessMasks(lldb_private::Process &process);
static lldb::addr_t AddressableBitToMask(uint32_t addressable_bits);

private:
uint32_t m_low_memory_addr_bits;
Expand Down
4 changes: 2 additions & 2 deletions lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -900,7 +900,7 @@ void ProcessGDBRemote::DidLaunchOrAttach(ArchSpec &process_arch) {
}

AddressableBits addressable_bits = m_gdb_comm.GetAddressableBits();
addressable_bits.SetProcessMasks(*this);
SetAddressableBitMasks(addressable_bits);

if (process_arch.IsValid()) {
const ArchSpec &target_arch = GetTarget().GetArchitecture();
Expand Down Expand Up @@ -2337,7 +2337,7 @@ StateType ProcessGDBRemote::SetThreadStopInfo(StringExtractor &stop_packet) {
}
}

addressable_bits.SetProcessMasks(*this);
SetAddressableBitMasks(addressable_bits);

ThreadSP thread_sp = SetThreadStopInfo(
tid, expedited_register_map, signo, thread_name, reason, description,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -574,7 +574,7 @@ Status ProcessMachCore::DoLoadCore() {
CleanupMemoryRegionPermissions();

AddressableBits addressable_bits = core_objfile->GetAddressableBits();
addressable_bits.SetProcessMasks(*this);
SetAddressableBitMasks(addressable_bits);

return error;
}
Expand Down
23 changes: 23 additions & 0 deletions lldb/source/Target/Process.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
#include "lldb/Target/ThreadPlanCallFunction.h"
#include "lldb/Target/ThreadPlanStack.h"
#include "lldb/Target/UnixSignals.h"
#include "lldb/Utility/AddressableBits.h"
#include "lldb/Utility/Event.h"
#include "lldb/Utility/LLDBLog.h"
#include "lldb/Utility/Log.h"
Expand Down Expand Up @@ -6453,3 +6454,25 @@ Status Process::CalculateCoreFileSaveRanges(lldb::SaveCoreStyle core_style,

return Status(); // Success!
}

void Process::SetAddressableBitMasks(AddressableBits bit_masks) {
uint32_t low_memory_addr_bits = bit_masks.GetLowmemAddressableBits();
uint32_t high_memory_addr_bits = bit_masks.GetHighmemAddressableBits();

if (low_memory_addr_bits == 0 && high_memory_addr_bits == 0)
return;

if (low_memory_addr_bits != 0) {
addr_t low_addr_mask =
AddressableBits::AddressableBitToMask(low_memory_addr_bits);
SetCodeAddressMask(low_addr_mask);
SetDataAddressMask(low_addr_mask);
}

if (high_memory_addr_bits != 0) {
addr_t high_addr_mask =
AddressableBits::AddressableBitToMask(high_memory_addr_bits);
SetHighmemCodeAddressMask(high_addr_mask);
SetHighmemDataAddressMask(high_addr_mask);
}
}
28 changes: 10 additions & 18 deletions lldb/source/Utility/AddressableBits.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@
//===----------------------------------------------------------------------===//

#include "lldb/Utility/AddressableBits.h"
#include "lldb/Target/Process.h"
#include "lldb/lldb-types.h"

#include <cassert>

using namespace lldb;
using namespace lldb_private;

Expand All @@ -28,32 +29,23 @@ void AddressableBits::SetLowmemAddressableBits(
m_low_memory_addr_bits = lowmem_addressing_bits;
}

uint32_t AddressableBits::GetLowmemAddressableBits() const {
return m_low_memory_addr_bits;
}

void AddressableBits::SetHighmemAddressableBits(
uint32_t highmem_addressing_bits) {
m_high_memory_addr_bits = highmem_addressing_bits;
}

uint32_t AddressableBits::GetHighmemAddressableBits() const {
return m_high_memory_addr_bits;
}

addr_t AddressableBits::AddressableBitToMask(uint32_t addressable_bits) {
assert(addressable_bits <= sizeof(addr_t) * 8);
if (addressable_bits == 64)
return 0; // all bits used for addressing
else
return ~((1ULL << addressable_bits) - 1);
}

void AddressableBits::SetProcessMasks(Process &process) {
if (m_low_memory_addr_bits == 0 && m_high_memory_addr_bits == 0)
return;

if (m_low_memory_addr_bits != 0) {
addr_t low_addr_mask = AddressableBitToMask(m_low_memory_addr_bits);
process.SetCodeAddressMask(low_addr_mask);
process.SetDataAddressMask(low_addr_mask);
}

if (m_high_memory_addr_bits != 0) {
addr_t hi_addr_mask = AddressableBitToMask(m_high_memory_addr_bits);
process.SetHighmemCodeAddressMask(hi_addr_mask);
process.SetHighmemDataAddressMask(hi_addr_mask);
}
}