aboutsummaryrefslogtreecommitdiff
path: root/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp
diff options
context:
space:
mode:
authorPavel Labath <pavel@labath.sk>2024-09-02 14:44:18 +0200
committerGitHub <noreply@github.com>2024-09-02 14:44:18 +0200
commit181cc75ea8be70e3fa7145456e1bf2331e0bc5e4 (patch)
tree75793108d142e5e484515987d5218ae9ab025e07 /lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp
parent0c0bac94c08e73d4c35b454ba02317f2db313f93 (diff)
downloadllvm-181cc75ea8be70e3fa7145456e1bf2331e0bc5e4.zip
llvm-181cc75ea8be70e3fa7145456e1bf2331e0bc5e4.tar.gz
llvm-181cc75ea8be70e3fa7145456e1bf2331e0bc5e4.tar.bz2
[lldb/linux] Make truncated reads work (#106532)
Previously, we were returning an error if we couldn't read the whole region. This doesn't matter most of the time, because lldb caches memory reads, and in that process it aligns them to cache line boundaries. As (LLDB) cache lines are smaller than pages, the reads are unlikely to cross page boundaries. Nonetheless, this can cause a problem for large reads (which bypass the cache), where we're unable to read anything even if just a single byte of the memory is unreadable. This patch fixes the lldb-server to do that, and also changes the linux implementation, to reuse any partial results it got from the process_vm_readv call (to avoid having to re-read everything again using ptrace, only to find that it stopped at the same place). This matches debugserver behavior. It is also consistent with the gdb remote protocol documentation, but -- notably -- not with actual gdbserver behavior (which returns errors instead of partial results). We filed a [clarification bug](https://sourceware.org/bugzilla/show_bug.cgi?id=24751) several years ago. Though we did not really reach a conclusion there, I think this is the most logical behavior. The associated test does not currently pass on windows, because the windows memory read APIs don't support partial reads (I have a WIP patch to work around that).
Diffstat (limited to 'lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp')
-rw-r--r--lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp22
1 files changed, 6 insertions, 16 deletions
diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp
index f6f13a8..504c994 100644
--- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp
+++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp
@@ -2526,28 +2526,18 @@ GDBRemoteCommunicationServerLLGS::Handle_memory_read(
size_t bytes_read = 0;
Status error = m_current_process->ReadMemoryWithoutTrap(
read_addr, &buf[0], byte_count, bytes_read);
- if (error.Fail()) {
- LLDB_LOGF(log,
- "GDBRemoteCommunicationServerLLGS::%s pid %" PRIu64
- " mem 0x%" PRIx64 ": failed to read. Error: %s",
- __FUNCTION__, m_current_process->GetID(), read_addr,
- error.AsCString());
- return SendErrorResponse(0x08);
- }
-
- if (bytes_read == 0) {
- LLDB_LOGF(log,
- "GDBRemoteCommunicationServerLLGS::%s pid %" PRIu64
- " mem 0x%" PRIx64 ": read 0 of %" PRIu64 " requested bytes",
- __FUNCTION__, m_current_process->GetID(), read_addr, byte_count);
+ LLDB_LOG(
+ log,
+ "ReadMemoryWithoutTrap({0}) read {1} of {2} requested bytes (error: {3})",
+ read_addr, byte_count, bytes_read, error);
+ if (bytes_read == 0)
return SendErrorResponse(0x08);
- }
StreamGDBRemote response;
packet.SetFilePos(0);
char kind = packet.GetChar('?');
if (kind == 'x')
- response.PutEscapedBytes(buf.data(), byte_count);
+ response.PutEscapedBytes(buf.data(), bytes_read);
else {
assert(kind == 'm');
for (size_t i = 0; i < bytes_read; ++i)