[Lldb-commits] [PATCH] D137682: Change IRMemoryMap's last-resort magic address to an inaddressable address so it doesn't conflict

Jason Molenda via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Tue Nov 8 17:18:53 PST 2022


jasonmolenda created this revision.
jasonmolenda added reviewers: JDevlieghere, jingham.
jasonmolenda added a project: LLDB.
Herald added a subscriber: Michael137.
Herald added a project: All.
jasonmolenda requested review of this revision.
Herald added a subscriber: lldb-commits.

When the IRInterpreter runs, and needs to store things in inferior memory, and it cannot allocate a memory region in the inferior, IRMemoryMap::FindSpace will create a buffer in lldb memory with a target address, and that will be used. If the target address overlaps with the address of an actual memory region in the inferior process, attempts to access the genuine memory there in IRInterpreted expressions will instead access lldb's local scratch memory.  The Process may not support any way to query memory regions, so the solution Sean has picked in years past was to pick an especially unlikely address.

Obviously, we have a program that puts things at this address.

Given that 64-bit systems do not genuinely have 64 bits of address space, we can pick a better address.  This patch changes the current unlikely address, 0xffffffff00000000, to 0xdead0fff00000000.  Still in high memory, but because bit 62 is now 0 with this address, it cannot overlap with an actual virtual address unless there was a system alling for 62 bits of addressable address space.  This is unlikely to happen soon.

I wrote a test which loads a binary into lldb, and slides the DATA segment around to different addresses, testing that the global variable in that DATA segment can still be read, as well as testing that if the DATA segment is slid to this impossible address, we get the incorrect value for the global.

This patch also fixes an incorrect way of getting the Target in `DWARFExpression::Evaluate` which gets a StackFrame from the ExecutionContext passed in, and uses that to get the Target, instead of simply using the Target, when calculating the load address of the address just read.  This had the effect of always returning the original file address, even when I loaded the segment at different addresses, in this test where there's no running process.  I looked through DWARFExpression briefly and didn't see any other code doing this.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D137682

Files:
  lldb/source/Expression/DWARFExpression.cpp
  lldb/source/Expression/IRMemoryMap.cpp
  lldb/test/API/lang/c/high-mem-global/Makefile
  lldb/test/API/lang/c/high-mem-global/TestHighMemGlobal.py
  lldb/test/API/lang/c/high-mem-global/main.c

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D137682.474120.patch
Type: text/x-patch
Size: 4046 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20221109/369f96b2/attachment.bin>


More information about the lldb-commits mailing list