llvm-project/lldb/bindings/interface/SBMemoryRegionInfo.i
Med Ismail Bennani a758c9f720 [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>
2021-10-08 14:54:07 +02:00

101 lines
2.9 KiB
C++

//===-- SWIG Interface for SBMemoryRegionInfo -------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
namespace lldb {
%feature("docstring",
"API clients can get information about memory regions in processes."
) SBMemoryRegionInfo;
class SBMemoryRegionInfo
{
public:
SBMemoryRegionInfo ();
SBMemoryRegionInfo (const lldb::SBMemoryRegionInfo &rhs);
SBMemoryRegionInfo::SBMemoryRegionInfo(const char *name, lldb::addr_t begin,
lldb::addr_t end, uint32_t permissions, bool mapped, bool stack_memory);
~SBMemoryRegionInfo ();
void
Clear();
lldb::addr_t
GetRegionBase ();
lldb::addr_t
GetRegionEnd ();
bool
IsReadable ();
bool
IsWritable ();
bool
IsExecutable ();
bool
IsMapped ();
const char *
GetName ();
%feature("autodoc", "
GetRegionEnd(SBMemoryRegionInfo self) -> lldb::addr_t
Returns whether this memory region has a list of modified (dirty)
pages available or not. When calling GetNumDirtyPages(), you will
have 0 returned for both \"dirty page list is not known\" and
\"empty dirty page list\" (that is, no modified pages in this
memory region). You must use this method to disambiguate.") HasDirtyMemoryPageList;
bool
HasDirtyMemoryPageList();
%feature("autodoc", "
GetNumDirtyPages(SBMemoryRegionInfo self) -> uint32_t
Return the number of dirty (modified) memory pages in this
memory region, if available. You must use the
SBMemoryRegionInfo::HasDirtyMemoryPageList() method to
determine if a dirty memory list is available; it will depend
on the target system can provide this information.") GetNumDirtyPages;
uint32_t
GetNumDirtyPages();
%feature("autodoc", "
GetDirtyPageAddressAtIndex(SBMemoryRegionInfo self, uint32_t idx) -> lldb::addr_t
Return the address of a modified, or dirty, page of memory.
If the provided index is out of range, or this memory region
does not have dirty page information, LLDB_INVALID_ADDRESS
is returned.") GetDirtyPageAddressAtIndex;
addr_t
GetDirtyPageAddressAtIndex(uint32_t idx);
%feature("autodoc", "
GetPageSize(SBMemoryRegionInfo self) -> int
Return the size of pages in this memory region. 0 will be returned
if this information was unavailable.") GetPageSize();
int
GetPageSize();
bool
operator == (const lldb::SBMemoryRegionInfo &rhs) const;
bool
operator != (const lldb::SBMemoryRegionInfo &rhs) const;
bool
GetDescription (lldb::SBStream &description);
STRING_EXTENSION(SBMemoryRegionInfo)
};
} // namespace lldb