Skip to content

Commit 3307508

Browse files
authored
Merge pull request #9187 from jasonmolenda/cp/dont-use-host-memory-at-target-vmaddr-0
[lldb] Don't use a vm addr range starting at 0 for local memory (llvm#100288)
2 parents dd86335 + c47e51c commit 3307508

File tree

2 files changed

+20
-6
lines changed

2 files changed

+20
-6
lines changed

lldb/docs/resources/lldbgdbremote.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1403,6 +1403,12 @@ For instance, with a macOS process which has nothing mapped in the first
14031403
The lack of `permissions:` indicates that none of read/write/execute are valid
14041404
for this region.
14051405
1406+
The stub must include `permissions:` key-value on all memory ranges
1407+
that are valid to access in the inferior process -- the lack of
1408+
`permissions:` means that this is an inaccessible (no page table
1409+
entries exist, in a system using VM) memory range. If a stub cannot
1410+
determine actual permissions, return `rwx`.
1411+
14061412
**Priority To Implement:** Medium
14071413
14081414
This is nice to have, but it isn't necessary. It helps LLDB
@@ -2434,4 +2440,4 @@ The `0x` prefixes are optional - like most of the gdb-remote packets,
24342440
omitting them will work fine; these numbers are always base 16.
24352441
24362442
The length of the payload is not provided. A reliable, 8-bit clean,
2437-
transport layer is assumed.
2443+
transport layer is assumed.

lldb/source/Expression/IRMemoryMap.cpp

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ lldb::addr_t IRMemoryMap::FindSpace(size_t size) {
8484
// any allocations. Otherwise start at the beginning of memory.
8585

8686
if (m_allocations.empty()) {
87-
ret = 0x0;
87+
ret = 0;
8888
} else {
8989
auto back = m_allocations.rbegin();
9090
lldb::addr_t addr = back->first;
@@ -116,10 +116,18 @@ lldb::addr_t IRMemoryMap::FindSpace(size_t size) {
116116
Status err = process_sp->GetMemoryRegionInfo(ret, region_info);
117117
if (err.Success()) {
118118
while (true) {
119-
if (region_info.GetReadable() != MemoryRegionInfo::OptionalBool::eNo ||
120-
region_info.GetWritable() != MemoryRegionInfo::OptionalBool::eNo ||
121-
region_info.GetExecutable() !=
122-
MemoryRegionInfo::OptionalBool::eNo) {
119+
if (region_info.GetRange().GetRangeBase() == 0 &&
120+
region_info.GetRange().GetRangeEnd() < end_of_memory) {
121+
// Don't use a region that starts at address 0,
122+
// it can make it harder to debug null dereference crashes
123+
// in the inferior.
124+
ret = region_info.GetRange().GetRangeEnd();
125+
} else if (region_info.GetReadable() !=
126+
MemoryRegionInfo::OptionalBool::eNo ||
127+
region_info.GetWritable() !=
128+
MemoryRegionInfo::OptionalBool::eNo ||
129+
region_info.GetExecutable() !=
130+
MemoryRegionInfo::OptionalBool::eNo) {
123131
if (region_info.GetRange().GetRangeEnd() - 1 >= end_of_memory) {
124132
ret = LLDB_INVALID_ADDRESS;
125133
break;

0 commit comments

Comments
 (0)