diff options
author | Jonas Devlieghere <jonas@devlieghere.com> | 2022-04-01 15:59:18 -0700 |
---|---|---|
committer | Jonas Devlieghere <jonas@devlieghere.com> | 2022-04-05 13:46:37 -0700 |
commit | fc54427e76c89e567390dd4a1d64a65568f4ec26 (patch) | |
tree | d785373d3b04cb1cee280af9da4d7f510dbeaef0 /lldb/source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.cpp | |
parent | 4169650537622ef278b4d62ef5fb37aeb0ee9f4e (diff) | |
download | llvm-fc54427e76c89e567390dd4a1d64a65568f4ec26.zip llvm-fc54427e76c89e567390dd4a1d64a65568f4ec26.tar.gz llvm-fc54427e76c89e567390dd4a1d64a65568f4ec26.tar.bz2 |
[lldb] Refactor DataBuffer so we can map files as read-only
Currently, all data buffers are assumed to be writable. This is a
problem on macOS where it's not allowed to load unsigned binaries in
memory as writable. To be more precise, MAP_RESILIENT_CODESIGN and
MAP_RESILIENT_MEDIA need to be set for mapped (unsigned) binaries on our
platform.
Binaries are mapped through FileSystem::CreateDataBuffer which returns a
DataBufferLLVM. The latter is backed by a llvm::WritableMemoryBuffer
because every DataBuffer in LLDB is considered to be writable. In order
to use a read-only llvm::MemoryBuffer I had to split our abstraction
around it.
This patch distinguishes between a DataBuffer (read-only) and
WritableDataBuffer (read-write) and updates LLDB to use the appropriate
one.
rdar://74890607
Differential revision: https://reviews.llvm.org/D122856
Diffstat (limited to 'lldb/source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.cpp')
-rw-r--r-- | lldb/source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.cpp | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.cpp b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.cpp index 1b66e8c..7ad4f49 100644 --- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.cpp +++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.cpp @@ -517,7 +517,7 @@ bool GDBRemoteRegisterContext::WriteAllRegisterValues( } bool GDBRemoteRegisterContext::ReadAllRegisterValues( - lldb::DataBufferSP &data_sp) { + lldb::WritableDataBufferSP &data_sp) { ExecutionContext exe_ctx(CalculateThread()); Process *process = exe_ctx.GetProcessPtr(); @@ -536,9 +536,13 @@ bool GDBRemoteRegisterContext::ReadAllRegisterValues( if (gdb_comm.SyncThreadState(m_thread.GetProtocolID())) InvalidateAllRegisters(); - if (use_g_packet && - (data_sp = gdb_comm.ReadAllRegisters(m_thread.GetProtocolID()))) - return true; + if (use_g_packet) { + if (DataBufferSP data_buffer = + gdb_comm.ReadAllRegisters(m_thread.GetProtocolID())) { + data_sp = std::make_shared<DataBufferHeap>(*data_buffer); + return true; + } + } // We're going to read each register // individually and store them as binary data in a buffer. |