From b3c4ee51245d940e63fea49e53c795498add26db Mon Sep 17 00:00:00 2001 From: Walter Erquinigo Date: Tue, 15 Jul 2025 13:44:40 -0700 Subject: [PATCH 1/4] [LLDB][GPU] Add a GPUActions option for sync initialization I'm experimenting with initializating asynchronously and I think it's a good idea to make sync initialization an option in the GPU Actions. Given that AMD was using this by default, I modified it accordingly. --- lldb/include/lldb/Utility/GPUGDBRemotePackets.h | 4 ++++ .../Plugins/Process/gdb-remote/ProcessGDBRemote.cpp | 11 ++++++++--- .../Plugins/AMDGPU/LLDBServerPluginAMDGPU.cpp | 1 + 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/lldb/include/lldb/Utility/GPUGDBRemotePackets.h b/lldb/include/lldb/Utility/GPUGDBRemotePackets.h index 7826f3b566d96..2860c1a70f6d7 100644 --- a/lldb/include/lldb/Utility/GPUGDBRemotePackets.h +++ b/lldb/include/lldb/Utility/GPUGDBRemotePackets.h @@ -190,6 +190,10 @@ struct GPUActions { /// Set this to true if the native plug-in sync with the GPU process and wait /// for it to return to a running state. bool wait_for_gpu_process_to_resume = false; + /// Set this to true if the native plug-in should wait synchronously for the + /// GPU process to initialize. This should be true if + /// `wait_for_gpu_process_to_resume` is set to true as part of initialization. + bool wait_synchronously_for_gpu_to_initialize = false; }; bool fromJSON(const llvm::json::Value &value, GPUActions &data, diff --git a/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp b/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp index 478b56f0fb9cd..259b76927036f 100644 --- a/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp +++ b/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp @@ -978,9 +978,14 @@ Status ProcessGDBRemote::HandleConnectionRequest(const GPUActions &gpu_action) { // We wait for the process to fully stop before we can query or alter it via // GPUActions. - ProcessSP process_sp = platform_sp->ConnectProcessSynchronous( - connection_info.connect_url, GetPluginNameStatic(), debugger, - *debugger.GetAsyncOutputStream(), gpu_target_sp.get(), error); + ProcessSP process_sp = + gpu_action.wait_synchronously_for_gpu_to_initialize + ? platform_sp->ConnectProcessSynchronous( + connection_info.connect_url, GetPluginNameStatic(), debugger, + *debugger.GetAsyncOutputStream(), gpu_target_sp.get(), error) + : platform_sp->ConnectProcess(connection_info.connect_url, + GetPluginNameStatic(), debugger, + gpu_target_sp.get(), error); if (error.Fail()) return error; if (!process_sp) diff --git a/lldb/tools/lldb-server/Plugins/AMDGPU/LLDBServerPluginAMDGPU.cpp b/lldb/tools/lldb-server/Plugins/AMDGPU/LLDBServerPluginAMDGPU.cpp index 8c9fbd1b38a18..12181d1314e38 100644 --- a/lldb/tools/lldb-server/Plugins/AMDGPU/LLDBServerPluginAMDGPU.cpp +++ b/lldb/tools/lldb-server/Plugins/AMDGPU/LLDBServerPluginAMDGPU.cpp @@ -386,6 +386,7 @@ std::optional LLDBServerPluginAMDGPU::NativeProcessIsStopping() { "launched successfully"); } actions.connect_info = CreateConnection(); + actions.wait_synchronously_for_gpu_to_initialize = true; } return actions; } else { From 110373a570f50788f80fb61f600bba625fb70b03 Mon Sep 17 00:00:00 2001 From: Walter Erquinigo Date: Wed, 16 Jul 2025 13:55:24 -0700 Subject: [PATCH 2/4] fix --- lldb/include/lldb/Utility/GPUGDBRemotePackets.h | 6 ++---- lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp | 4 +--- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/lldb/include/lldb/Utility/GPUGDBRemotePackets.h b/lldb/include/lldb/Utility/GPUGDBRemotePackets.h index 2860c1a70f6d7..9561b8b4d5f81 100644 --- a/lldb/include/lldb/Utility/GPUGDBRemotePackets.h +++ b/lldb/include/lldb/Utility/GPUGDBRemotePackets.h @@ -122,6 +122,8 @@ struct GPUPluginConnectionInfo { std::optional triple; /// The connection URL to use with "process connect ". std::string connect_url; + /// Synchronously wait for the GPU to initialize when connecting. + bool synchronous = false; }; bool fromJSON(const llvm::json::Value &value, GPUPluginConnectionInfo &data, @@ -190,10 +192,6 @@ struct GPUActions { /// Set this to true if the native plug-in sync with the GPU process and wait /// for it to return to a running state. bool wait_for_gpu_process_to_resume = false; - /// Set this to true if the native plug-in should wait synchronously for the - /// GPU process to initialize. This should be true if - /// `wait_for_gpu_process_to_resume` is set to true as part of initialization. - bool wait_synchronously_for_gpu_to_initialize = false; }; bool fromJSON(const llvm::json::Value &value, GPUActions &data, diff --git a/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp b/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp index 259b76927036f..fab4b0286b28a 100644 --- a/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp +++ b/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp @@ -976,10 +976,8 @@ Status ProcessGDBRemote::HandleConnectionRequest(const GPUActions &gpu_action) { return Status::FromErrorString("invalid platform for target needed for " "connecting to process"); - // We wait for the process to fully stop before we can query or alter it via - // GPUActions. ProcessSP process_sp = - gpu_action.wait_synchronously_for_gpu_to_initialize + gpu_action.connect_info->synchronous ? platform_sp->ConnectProcessSynchronous( connection_info.connect_url, GetPluginNameStatic(), debugger, *debugger.GetAsyncOutputStream(), gpu_target_sp.get(), error) From d0a49d474cc9d852a5b7ca78f09eed33a9dace85 Mon Sep 17 00:00:00 2001 From: Walter Erquinigo Date: Thu, 17 Jul 2025 17:24:36 -0400 Subject: [PATCH 3/4] Update LLDBServerPluginAMDGPU.cpp --- .../tools/lldb-server/Plugins/AMDGPU/LLDBServerPluginAMDGPU.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lldb/tools/lldb-server/Plugins/AMDGPU/LLDBServerPluginAMDGPU.cpp b/lldb/tools/lldb-server/Plugins/AMDGPU/LLDBServerPluginAMDGPU.cpp index 12181d1314e38..3d10c4cf1620f 100644 --- a/lldb/tools/lldb-server/Plugins/AMDGPU/LLDBServerPluginAMDGPU.cpp +++ b/lldb/tools/lldb-server/Plugins/AMDGPU/LLDBServerPluginAMDGPU.cpp @@ -386,7 +386,7 @@ std::optional LLDBServerPluginAMDGPU::NativeProcessIsStopping() { "launched successfully"); } actions.connect_info = CreateConnection(); - actions.wait_synchronously_for_gpu_to_initialize = true; + actions.connect_info.synchronous = true; } return actions; } else { From c6ce8ccb2463c58db3f0314855ff5c333dde800b Mon Sep 17 00:00:00 2001 From: Walter Erquinigo Date: Thu, 17 Jul 2025 17:25:47 -0400 Subject: [PATCH 4/4] Update LLDBServerPluginAMDGPU.cpp --- .../tools/lldb-server/Plugins/AMDGPU/LLDBServerPluginAMDGPU.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lldb/tools/lldb-server/Plugins/AMDGPU/LLDBServerPluginAMDGPU.cpp b/lldb/tools/lldb-server/Plugins/AMDGPU/LLDBServerPluginAMDGPU.cpp index 3d10c4cf1620f..5839badfca41c 100644 --- a/lldb/tools/lldb-server/Plugins/AMDGPU/LLDBServerPluginAMDGPU.cpp +++ b/lldb/tools/lldb-server/Plugins/AMDGPU/LLDBServerPluginAMDGPU.cpp @@ -386,7 +386,7 @@ std::optional LLDBServerPluginAMDGPU::NativeProcessIsStopping() { "launched successfully"); } actions.connect_info = CreateConnection(); - actions.connect_info.synchronous = true; + actions.connect_info->synchronous = true; } return actions; } else {