[lldb/Plugins] Add memory region support in ScriptedProcess
This patch adds support for memory regions in Scripted Processes. This is necessary to read the stack memory region in order to reconstruct each stackframe of the program. In order to do so, this patch makes some changes to the SBAPI, namely: - Add a new constructor for `SBMemoryRegionInfo` that takes arguments such as the memory region name, address range, permissions ... This is used when reading memory at some address to compute the offset in the binary blob provided by the user. - Add a `GetMemoryRegionContainingAddress` method to `SBMemoryRegionInfoList` to simplify the access to a specific memory region. With these changes, lldb is now able to unwind the stack and reconstruct each frame. On top of that, reloading the target module at offset 0 allows lldb to symbolicate the `ScriptedProcess` using debug info, similarly to an ordinary Process. To test this, I wrote a simple program with multiple function calls, ran it in lldb, stopped at a leaf function and read the registers values and copied the stack memory into a binary file. These are then used in the python script. Differential Revision: https://reviews.llvm.org/D108953 Signed-off-by: Med Ismail Bennani <medismail.bennani@gmail.com>
This commit is contained in:
@@ -239,7 +239,7 @@ size_t ScriptedProcess::DoReadMemory(lldb::addr_t addr, void *buf, size_t size,
|
||||
lldb::DataExtractorSP data_extractor_sp =
|
||||
GetInterface().ReadMemoryAtAddress(addr, size, error);
|
||||
|
||||
if (!data_extractor_sp || error.Fail())
|
||||
if (!data_extractor_sp || !data_extractor_sp->GetByteSize() || error.Fail())
|
||||
return 0;
|
||||
|
||||
offset_t bytes_copied = data_extractor_sp->CopyByteOrderedData(
|
||||
@@ -258,24 +258,34 @@ ArchSpec ScriptedProcess::GetArchitecture() {
|
||||
|
||||
Status ScriptedProcess::GetMemoryRegionInfo(lldb::addr_t load_addr,
|
||||
MemoryRegionInfo ®ion) {
|
||||
// TODO: Implement
|
||||
return Status();
|
||||
CheckInterpreterAndScriptObject();
|
||||
|
||||
Status error;
|
||||
if (auto region_or_err =
|
||||
GetInterface().GetMemoryRegionContainingAddress(load_addr, error))
|
||||
region = *region_or_err;
|
||||
|
||||
return error;
|
||||
}
|
||||
|
||||
Status ScriptedProcess::GetMemoryRegions(MemoryRegionInfos ®ion_list) {
|
||||
CheckInterpreterAndScriptObject();
|
||||
|
||||
Status error;
|
||||
lldb::addr_t address = 0;
|
||||
lldb::MemoryRegionInfoSP mem_region_sp = nullptr;
|
||||
|
||||
while ((mem_region_sp =
|
||||
GetInterface().GetMemoryRegionContainingAddress(address))) {
|
||||
auto range = mem_region_sp->GetRange();
|
||||
while (auto region_or_err =
|
||||
GetInterface().GetMemoryRegionContainingAddress(address, error)) {
|
||||
if (error.Fail())
|
||||
break;
|
||||
|
||||
MemoryRegionInfo &mem_region = *region_or_err;
|
||||
auto range = mem_region.GetRange();
|
||||
address += range.GetRangeBase() + range.GetByteSize();
|
||||
region_list.push_back(*mem_region_sp.get());
|
||||
region_list.push_back(mem_region);
|
||||
}
|
||||
|
||||
return {};
|
||||
return error;
|
||||
}
|
||||
|
||||
void ScriptedProcess::Clear() { Process::m_thread_list.Clear(); }
|
||||
|
||||
Reference in New Issue
Block a user