Skip to content

[lldb] Don't use a vm addr range starting at 0 for local memory #100288

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
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
8 changes: 7 additions & 1 deletion lldb/docs/resources/lldbgdbremote.md
Original file line number Diff line number Diff line change
Expand Up @@ -1403,6 +1403,12 @@ For instance, with a macOS process which has nothing mapped in the first
The lack of `permissions:` indicates that none of read/write/execute are valid
for this region.

The stub must include `permissions:` key-value on all memory ranges
that are valid to access in the inferior process -- the lack of
`permissions:` means that this is an inaccessible (no page table
entries exist, in a system using VM) memory range. If a stub cannot
determine actual permissions, return `rwx`.

**Priority To Implement:** Medium

This is nice to have, but it isn't necessary. It helps LLDB
Expand Down Expand Up @@ -2434,4 +2440,4 @@ The `0x` prefixes are optional - like most of the gdb-remote packets,
omitting them will work fine; these numbers are always base 16.

The length of the payload is not provided. A reliable, 8-bit clean,
transport layer is assumed.
transport layer is assumed.
18 changes: 13 additions & 5 deletions lldb/source/Expression/IRMemoryMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ lldb::addr_t IRMemoryMap::FindSpace(size_t size) {
// any allocations. Otherwise start at the beginning of memory.

if (m_allocations.empty()) {
ret = 0x0;
ret = 0;
} else {
auto back = m_allocations.rbegin();
lldb::addr_t addr = back->first;
Expand Down Expand Up @@ -116,10 +116,18 @@ lldb::addr_t IRMemoryMap::FindSpace(size_t size) {
Status err = process_sp->GetMemoryRegionInfo(ret, region_info);
if (err.Success()) {
while (true) {
if (region_info.GetReadable() != MemoryRegionInfo::OptionalBool::eNo ||
region_info.GetWritable() != MemoryRegionInfo::OptionalBool::eNo ||
region_info.GetExecutable() !=
MemoryRegionInfo::OptionalBool::eNo) {
if (region_info.GetRange().GetRangeBase() == 0 &&
region_info.GetRange().GetRangeEnd() < end_of_memory) {
// Don't use a region that starts at address 0,
// it can make it harder to debug null dereference crashes
// in the inferior.
ret = region_info.GetRange().GetRangeEnd();
} else if (region_info.GetReadable() !=
MemoryRegionInfo::OptionalBool::eNo ||
region_info.GetWritable() !=
MemoryRegionInfo::OptionalBool::eNo ||
region_info.GetExecutable() !=
MemoryRegionInfo::OptionalBool::eNo) {
if (region_info.GetRange().GetRangeEnd() - 1 >= end_of_memory) {
ret = LLDB_INVALID_ADDRESS;
break;
Expand Down
Loading