-
Notifications
You must be signed in to change notification settings - Fork 12.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[lldb] Optimized lldb-server memory usage #100666
Conversation
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.
@llvm/pr-subscribers-lldb Author: Dmitry Vasilyev (slydiman) ChangesMAX_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:
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.
|
…t mapping Removed fork(). Used threads and the common thread-safe port map for all platform connections. Updated lldb::FileSystem to use llvm::vfs::createPhysicalFileSystem() with an own virtual working directory per thread. This patch depends on llvm#100659, llvm#100666. This patch fixes llvm#97537, llvm#90923, llvm#56346. lldb-server has been tested on Windows with 50 connections and 100 processes launched simultaneously. Tested also the cross build with Linux x86_64 host and Linux Aarch64 target.
@@ -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'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we still need this line? Seems redundant since the array is initialized to this value anyway.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated. Thanks.
Hm, I was worried that we might get the filepath of a unix socket in some use case, but we llvm::to_integer(port_cstr) shortly later, so that can't be the case. |
@@ -1145,8 +1145,8 @@ Status GDBRemoteCommunication::StartDebugserverProcess( | |||
if (socket_pipe.CanWrite()) | |||
socket_pipe.CloseWriteFileDescriptor(); | |||
if (socket_pipe.CanRead()) { | |||
char port_cstr[PATH_MAX] = {0}; | |||
port_cstr[0] = '\0'; | |||
// The port number may be "1024\0".."65535\0". |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Technically, if you're running as root, it could also be one of the smaller values. I'd just document the largest value.
…t mapping Removed fork(). Used threads and the common thread-safe port map for all platform connections. Updated lldb::FileSystem to use llvm::vfs::createPhysicalFileSystem() with an own virtual working directory per thread. This patch depends on llvm#100659, llvm#100666. This patch fixes llvm#97537, llvm#90923, llvm#56346. lldb-server has been tested on Windows with 50 connections and 100 processes launched simultaneously. Tested also the cross build with Linux x86_64 host and Linux Aarch64 target.
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.