[Lldb-commits] [lldb] [lldb] Optimized lldb-server memory usage (PR #100666)

via lldb-commits lldb-commits at lists.llvm.org
Thu Jul 25 15:44:23 PDT 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-lldb

Author: Dmitry Vasilyev (slydiman)

<details>
<summary>Changes</summary>

MAX_PATH is definitely larger than 6 bytes we are expecting for this message, and could be rather large depending on the target OS (4K for some Linux OSs).

Since the buffer gets allocated on the stack we better be conservative and allocate what we actually need.

---
Full diff: https://github.com/llvm/llvm-project/pull/100666.diff


1 Files Affected:

- (modified) lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp (+2-1) 


``````````diff
diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp
index 187370eb36cae..b961c0e42469a 100644
--- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp
+++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp
@@ -1145,7 +1145,8 @@ Status GDBRemoteCommunication::StartDebugserverProcess(
       if (socket_pipe.CanWrite())
         socket_pipe.CloseWriteFileDescriptor();
       if (socket_pipe.CanRead()) {
-        char port_cstr[PATH_MAX] = {0};
+        // The port number may be "1024\0".."65535\0".
+        char port_cstr[6] = {0};
         port_cstr[0] = '\0';
         size_t num_bytes = sizeof(port_cstr);
         // Read port from pipe with 10 second timeout.

``````````

</details>


https://github.com/llvm/llvm-project/pull/100666


More information about the lldb-commits mailing list