Skip to content

Commit

Permalink
Revert "Reland "[lldb] Remove non address bits when looking up memory…
Browse files Browse the repository at this point in the history
… regions""

This reverts commit fac3f20.

I found this has broken how we detect the last memory region in
GetMemoryRegions/"memory region" command.

When you're debugging an AArch64 system with pointer authentication,
the ABI plugin will remove the top bit from the end address of the last
user mapped area.

(lldb)
[0x0000fffffffdf000-0x0001000000000000) rw- [stack]

ABI plugin removes anything above the 48th bit (48 bit virtual addresses
by default on AArch64, leaving an address of 0.

(lldb)
[0x0000000000000000-0x0000000000400000) ---

You get back a mapping for 0 and get into an infinite loop.
  • Loading branch information
DavidSpickett committed Nov 26, 2021
1 parent 34cc210 commit 0df5229
Show file tree
Hide file tree
Showing 17 changed files with 41 additions and 130 deletions.
38 changes: 10 additions & 28 deletions lldb/include/lldb/Target/Process.h
Expand Up @@ -1762,7 +1762,7 @@ class Process : public std::enable_shared_from_this<Process>,
///
/// If load_addr is within the address space the process has mapped
/// range_info will be filled in with the start and end of that range as
/// well as the permissions for that range and range_info. GetMapped will
/// well as the permissions for that range and range_info.GetMapped will
/// return true.
///
/// If load_addr is outside any mapped region then range_info will have its
Expand All @@ -1771,21 +1771,23 @@ class Process : public std::enable_shared_from_this<Process>,
/// there are no valid mapped ranges between load_addr and the end of the
/// process address space.
///
/// GetMemoryRegionInfo calls DoGetMemoryRegionInfo. Override that function in
/// process subclasses.
/// GetMemoryRegionInfo will only return an error if it is unimplemented for
/// the current process.
///
/// \param[in] load_addr
/// The load address to query the range_info for. May include non
/// address bits, these will be removed by the the ABI plugin if there is
/// one.
/// The load address to query the range_info for.
///
/// \param[out] range_info
/// An range_info value containing the details of the range.
///
/// \return
/// An error value.
Status GetMemoryRegionInfo(lldb::addr_t load_addr,
MemoryRegionInfo &range_info);
virtual Status GetMemoryRegionInfo(lldb::addr_t load_addr,
MemoryRegionInfo &range_info) {
Status error;
error.SetErrorString("Process::GetMemoryRegionInfo() not supported");
return error;
}

/// Obtain all the mapped memory regions within this process.
///
Expand Down Expand Up @@ -2605,26 +2607,6 @@ void PruneThreadPlans();
virtual size_t DoReadMemory(lldb::addr_t vm_addr, void *buf, size_t size,
Status &error) = 0;

/// DoGetMemoryRegionInfo is called by GetMemoryRegionInfo after it has
/// removed non address bits from load_addr. Override this method in
/// subclasses of Process.
///
/// See GetMemoryRegionInfo for details of the logic.
///
/// \param[in] load_addr
/// The load address to query the range_info for. (non address bits
/// removed)
///
/// \param[out] range_info
/// An range_info value containing the details of the range.
///
/// \return
/// An error value.
virtual Status DoGetMemoryRegionInfo(lldb::addr_t load_addr,
MemoryRegionInfo &range_info) {
return Status("Process::DoGetMemoryRegionInfo() not supported");
}

lldb::StateType GetPrivateState();

/// The "private" side of resuming a process. This doesn't alter the state
Expand Down
4 changes: 2 additions & 2 deletions lldb/source/Plugins/Process/Windows/Common/ProcessWindows.cpp
Expand Up @@ -601,8 +601,8 @@ Status ProcessWindows::DoDeallocateMemory(lldb::addr_t ptr) {
return ProcessDebugger::DeallocateMemory(ptr);
}

Status ProcessWindows::DoGetMemoryRegionInfo(lldb::addr_t vm_addr,
MemoryRegionInfo &info) {
Status ProcessWindows::GetMemoryRegionInfo(lldb::addr_t vm_addr,
MemoryRegionInfo &info) {
return ProcessDebugger::GetMemoryRegionInfo(vm_addr, info);
}

Expand Down
6 changes: 2 additions & 4 deletions lldb/source/Plugins/Process/Windows/Common/ProcessWindows.h
Expand Up @@ -78,6 +78,8 @@ class ProcessWindows : public Process, public ProcessDebugger {
lldb::addr_t DoAllocateMemory(size_t size, uint32_t permissions,
Status &error) override;
Status DoDeallocateMemory(lldb::addr_t ptr) override;
Status GetMemoryRegionInfo(lldb::addr_t vm_addr,
MemoryRegionInfo &info) override;

lldb::addr_t GetImageInfoAddress() override;

Expand All @@ -101,10 +103,6 @@ class ProcessWindows : public Process, public ProcessDebugger {
Status EnableWatchpoint(Watchpoint *wp, bool notify = true) override;
Status DisableWatchpoint(Watchpoint *wp, bool notify = true) override;

protected:
Status DoGetMemoryRegionInfo(lldb::addr_t vm_addr,
MemoryRegionInfo &info) override;

private:
struct WatchpointInfo {
uint32_t slot_id;
Expand Down
4 changes: 2 additions & 2 deletions lldb/source/Plugins/Process/elf-core/ProcessElfCore.cpp
Expand Up @@ -281,8 +281,8 @@ size_t ProcessElfCore::ReadMemory(lldb::addr_t addr, void *buf, size_t size,
return DoReadMemory(addr, buf, size, error);
}

Status ProcessElfCore::DoGetMemoryRegionInfo(lldb::addr_t load_addr,
MemoryRegionInfo &region_info) {
Status ProcessElfCore::GetMemoryRegionInfo(lldb::addr_t load_addr,
MemoryRegionInfo &region_info) {
region_info.Clear();
const VMRangeToPermissions::Entry *permission_entry =
m_core_range_infos.FindEntryThatContainsOrFollows(load_addr);
Expand Down
8 changes: 4 additions & 4 deletions lldb/source/Plugins/Process/elf-core/ProcessElfCore.h
Expand Up @@ -86,6 +86,10 @@ class ProcessElfCore : public lldb_private::PostMortemProcess {
size_t DoReadMemory(lldb::addr_t addr, void *buf, size_t size,
lldb_private::Status &error) override;

lldb_private::Status
GetMemoryRegionInfo(lldb::addr_t load_addr,
lldb_private::MemoryRegionInfo &region_info) override;

lldb::addr_t GetImageInfoAddress() override;

lldb_private::ArchSpec GetArchitecture();
Expand All @@ -101,10 +105,6 @@ class ProcessElfCore : public lldb_private::PostMortemProcess {
bool DoUpdateThreadList(lldb_private::ThreadList &old_thread_list,
lldb_private::ThreadList &new_thread_list) override;

lldb_private::Status
DoGetMemoryRegionInfo(lldb::addr_t load_addr,
lldb_private::MemoryRegionInfo &region_info) override;

private:
struct NT_FILE_Entry {
lldb::addr_t start;
Expand Down
4 changes: 2 additions & 2 deletions lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
Expand Up @@ -2877,8 +2877,8 @@ lldb::addr_t ProcessGDBRemote::DoAllocateMemory(size_t size,
return allocated_addr;
}

Status ProcessGDBRemote::DoGetMemoryRegionInfo(addr_t load_addr,
MemoryRegionInfo &region_info) {
Status ProcessGDBRemote::GetMemoryRegionInfo(addr_t load_addr,
MemoryRegionInfo &region_info) {

Status error(m_gdb_comm.GetMemoryRegionInfo(load_addr, region_info));
return error;
Expand Down
6 changes: 3 additions & 3 deletions lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.h
Expand Up @@ -144,6 +144,9 @@ class ProcessGDBRemote : public Process,
lldb::addr_t DoAllocateMemory(size_t size, uint32_t permissions,
Status &error) override;

Status GetMemoryRegionInfo(lldb::addr_t load_addr,
MemoryRegionInfo &region_info) override;

Status DoDeallocateMemory(lldb::addr_t ptr) override;

// Process STDIO
Expand Down Expand Up @@ -417,9 +420,6 @@ class ProcessGDBRemote : public Process,
Status DoWriteMemoryTags(lldb::addr_t addr, size_t len, int32_t type,
const std::vector<uint8_t> &tags) override;

Status DoGetMemoryRegionInfo(lldb::addr_t load_addr,
MemoryRegionInfo &region_info) override;

private:
// For ProcessGDBRemote only
std::string m_partial_profile_data;
Expand Down
4 changes: 2 additions & 2 deletions lldb/source/Plugins/Process/mach-core/ProcessMachCore.cpp
Expand Up @@ -633,8 +633,8 @@ size_t ProcessMachCore::DoReadMemory(addr_t addr, void *buf, size_t size,
return bytes_read;
}

Status ProcessMachCore::DoGetMemoryRegionInfo(addr_t load_addr,
MemoryRegionInfo &region_info) {
Status ProcessMachCore::GetMemoryRegionInfo(addr_t load_addr,
MemoryRegionInfo &region_info) {
region_info.Clear();
const VMRangeToPermissions::Entry *permission_entry =
m_core_range_infos.FindEntryThatContainsOrFollows(load_addr);
Expand Down
8 changes: 4 additions & 4 deletions lldb/source/Plugins/Process/mach-core/ProcessMachCore.h
Expand Up @@ -68,6 +68,10 @@ class ProcessMachCore : public lldb_private::PostMortemProcess {
size_t DoReadMemory(lldb::addr_t addr, void *buf, size_t size,
lldb_private::Status &error) override;

lldb_private::Status
GetMemoryRegionInfo(lldb::addr_t load_addr,
lldb_private::MemoryRegionInfo &region_info) override;

lldb::addr_t GetImageInfoAddress() override;

protected:
Expand All @@ -80,10 +84,6 @@ class ProcessMachCore : public lldb_private::PostMortemProcess {

lldb_private::ObjectFile *GetCoreObjectFile();

lldb_private::Status
DoGetMemoryRegionInfo(lldb::addr_t load_addr,
lldb_private::MemoryRegionInfo &region_info) override;

private:
bool GetDynamicLoaderAddress(lldb::addr_t addr);

Expand Down
4 changes: 2 additions & 2 deletions lldb/source/Plugins/Process/minidump/ProcessMinidump.cpp
Expand Up @@ -439,8 +439,8 @@ void ProcessMinidump::BuildMemoryRegions() {
llvm::sort(*m_memory_regions);
}

Status ProcessMinidump::DoGetMemoryRegionInfo(lldb::addr_t load_addr,
MemoryRegionInfo &region) {
Status ProcessMinidump::GetMemoryRegionInfo(lldb::addr_t load_addr,
MemoryRegionInfo &region) {
BuildMemoryRegions();
region = MinidumpParser::GetMemoryRegionInfo(*m_memory_regions, load_addr);
return Status();
Expand Down
6 changes: 3 additions & 3 deletions lldb/source/Plugins/Process/minidump/ProcessMinidump.h
Expand Up @@ -75,6 +75,9 @@ class ProcessMinidump : public PostMortemProcess {

ArchSpec GetArchitecture();

Status GetMemoryRegionInfo(lldb::addr_t load_addr,
MemoryRegionInfo &range_info) override;

Status GetMemoryRegions(
lldb_private::MemoryRegionInfos &region_list) override;

Expand All @@ -95,9 +98,6 @@ class ProcessMinidump : public PostMortemProcess {
bool DoUpdateThreadList(ThreadList &old_thread_list,
ThreadList &new_thread_list) override;

Status DoGetMemoryRegionInfo(lldb::addr_t load_addr,
MemoryRegionInfo &range_info) override;

void ReadModuleList();

lldb::ModuleSP GetOrCreateModule(lldb_private::UUID minidump_uuid,
Expand Down
4 changes: 2 additions & 2 deletions lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp
Expand Up @@ -248,8 +248,8 @@ ArchSpec ScriptedProcess::GetArchitecture() {
return GetTarget().GetArchitecture();
}

Status ScriptedProcess::DoGetMemoryRegionInfo(lldb::addr_t load_addr,
MemoryRegionInfo &region) {
Status ScriptedProcess::GetMemoryRegionInfo(lldb::addr_t load_addr,
MemoryRegionInfo &region) {
CheckInterpreterAndScriptObject();

Status error;
Expand Down
6 changes: 3 additions & 3 deletions lldb/source/Plugins/Process/scripted/ScriptedProcess.h
Expand Up @@ -84,6 +84,9 @@ class ScriptedProcess : public Process {

ArchSpec GetArchitecture();

Status GetMemoryRegionInfo(lldb::addr_t load_addr,
MemoryRegionInfo &range_info) override;

Status
GetMemoryRegions(lldb_private::MemoryRegionInfos &region_list) override;

Expand All @@ -97,9 +100,6 @@ class ScriptedProcess : public Process {
bool DoUpdateThreadList(ThreadList &old_thread_list,
ThreadList &new_thread_list) override;

Status DoGetMemoryRegionInfo(lldb::addr_t load_addr,
MemoryRegionInfo &range_info) override;

private:
friend class ScriptedThread;

Expand Down
7 changes: 0 additions & 7 deletions lldb/source/Target/Process.cpp
Expand Up @@ -5853,13 +5853,6 @@ Process::AdvanceAddressToNextBranchInstruction(Address default_stop_addr,
return retval;
}

Status Process::GetMemoryRegionInfo(lldb::addr_t load_addr,
MemoryRegionInfo &range_info) {
if (auto abi = GetABI())
load_addr = abi->FixDataAddress(load_addr);
return DoGetMemoryRegionInfo(load_addr, range_info);
}

Status
Process::GetMemoryRegions(lldb_private::MemoryRegionInfos &region_list) {

Expand Down
3 changes: 0 additions & 3 deletions lldb/test/API/linux/aarch64/tagged_memory_region/Makefile

This file was deleted.

This file was deleted.

17 changes: 0 additions & 17 deletions lldb/test/API/linux/aarch64/tagged_memory_region/main.c

This file was deleted.

0 comments on commit 0df5229

Please sign in to comment.