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/ProcessGDBRemote.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/ProcessGDBRemote.cpp')
-rw-r--r-- | lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp b/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp index 2e652e1..af98369 100644 --- a/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp +++ b/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp @@ -1671,7 +1671,7 @@ ThreadSP ProcessGDBRemote::SetThreadStopInfo( for (const auto &pair : expedited_register_map) { StringExtractor reg_value_extractor(pair.second); - DataBufferSP buffer_sp(new DataBufferHeap( + WritableDataBufferSP buffer_sp(new DataBufferHeap( reg_value_extractor.GetStringRef().size() / 2, 0)); reg_value_extractor.GetHexBytes(buffer_sp->GetData(), '\xcc'); uint32_t lldb_regnum = @@ -2050,7 +2050,8 @@ ProcessGDBRemote::SetThreadStopInfo(StructuredData::Dictionary *thread_dict) { bytes.SetFilePos(0); const size_t byte_size = bytes.GetStringRef().size() / 2; - DataBufferSP data_buffer_sp(new DataBufferHeap(byte_size, 0)); + WritableDataBufferSP data_buffer_sp( + new DataBufferHeap(byte_size, 0)); const size_t bytes_copied = bytes.GetHexBytes(data_buffer_sp->GetData(), 0); if (bytes_copied == byte_size) @@ -2212,7 +2213,8 @@ StateType ProcessGDBRemote::SetThreadStopInfo(StringExtractor &stop_packet) { if (!addr_str.getAsInteger(0, mem_cache_addr)) { StringExtractor bytes(bytes_str); const size_t byte_size = bytes.GetBytesLeft() / 2; - DataBufferSP data_buffer_sp(new DataBufferHeap(byte_size, 0)); + WritableDataBufferSP data_buffer_sp( + new DataBufferHeap(byte_size, 0)); const size_t bytes_copied = bytes.GetHexBytes(data_buffer_sp->GetData(), 0); if (bytes_copied == byte_size) |