[lldb-server][linux] Add ability to allocate memory
authorPavel Labath <pavel@labath.sk>
Fri, 9 Oct 2020 11:59:50 +0000 (13:59 +0200)
committerPavel Labath <pavel@labath.sk>
Wed, 14 Oct 2020 13:02:09 +0000 (15:02 +0200)
commit2c4226f8ac2c925d7e1d59d1de1660cd1dd63f31
tree2ce3704bf4f6c2a457660d04d10503eb50e0a8fa
parent6bb123b819c61c61197ec2ba54ceb6d16e9121cf
[lldb-server][linux] Add ability to allocate memory

This patch adds support for the _M and _m gdb-remote packets, which
(de)allocate memory in the inferior. This works by "injecting" a
m(un)map syscall into the inferior. This consists of:
- finding an executable page of memory
- writing the syscall opcode to it
- setting up registers according to the os syscall convention
- single stepping over the syscall

The advantage of this approach over calling the mmap function is that
this works even in case the mmap function is buggy or unavailable. The
disadvantage is it is more platform-dependent, which is why this patch
only works on X86 (_32 and _64) right now. Adding support for other
linux architectures should be easy and consist of defining the
appropriate syscall constants. Adding support for other OSes depends on
the its ability to do a similar trick.

Differential Revision: https://reviews.llvm.org/D89124
20 files changed:
lldb/include/lldb/Host/common/NativeProcessProtocol.h
lldb/source/Plugins/Process/FreeBSDRemote/NativeProcessFreeBSD.cpp
lldb/source/Plugins/Process/FreeBSDRemote/NativeProcessFreeBSD.h
lldb/source/Plugins/Process/Linux/NativeProcessLinux.cpp
lldb/source/Plugins/Process/Linux/NativeProcessLinux.h
lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux.h
lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_x86_64.cpp
lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_x86_64.h
lldb/source/Plugins/Process/NetBSD/NativeProcessNetBSD.cpp
lldb/source/Plugins/Process/NetBSD/NativeProcessNetBSD.h
lldb/source/Plugins/Process/Windows/Common/NativeProcessWindows.cpp
lldb/source/Plugins/Process/Windows/Common/NativeProcessWindows.h
lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp
lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.h
lldb/test/API/lang/c/stepping/TestStepAndBreakpoints.py
lldb/test/API/tools/lldb-server/memory-allocation/Makefile [new file with mode: 0644]
lldb/test/API/tools/lldb-server/memory-allocation/TestGdbRemoteMemoryAllocation.py [new file with mode: 0644]
lldb/test/API/tools/lldb-server/memory-allocation/main.c [new file with mode: 0644]
lldb/test/Shell/Expr/nodefaultlib.cpp [new file with mode: 0644]
lldb/unittests/TestingSupport/Host/NativeProcessTestUtils.h