diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp index 78337af7227d1..47c8948def4cc 100644 --- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp +++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp @@ -44,6 +44,8 @@ using namespace lldb; using namespace lldb_private; using namespace lldb_private::process_gdb_remote; +static int id = 0; + // GDBRemoteCommunication constructor GDBRemoteCommunication::GDBRemoteCommunication(llvm::StringRef name) : Communication(), @@ -54,7 +56,7 @@ GDBRemoteCommunication::GDBRemoteCommunication(llvm::StringRef name) #endif m_echo_number(0), m_supports_qEcho(eLazyBoolCalculate), m_history(512), m_send_acks(true), m_is_platform(false), - m_compression_type(CompressionType::None), m_listen_url(), m_name(name) { + m_compression_type(CompressionType::None), m_listen_url(), m_name((name + std::to_string(id++)).str()) { } // Destructor diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp index 5452726a0a1a1..39777f70696e8 100644 --- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp +++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp @@ -917,6 +917,8 @@ lldb::pid_t GDBRemoteCommunicationClient::GetCurrentProcessID(bool allow_lazy) { } llvm::Error GDBRemoteCommunicationClient::LaunchProcess(const Args &args) { + m_launch_response.reset(); + if (!args.GetArgumentAtIndex(0)) return llvm::createStringError(llvm::inconvertibleErrorCode(), "Nothing to launch"); @@ -935,6 +937,8 @@ llvm::Error GDBRemoteCommunicationClient::LaunchProcess(const Args &args) { return llvm::createStringError(llvm::inconvertibleErrorCode(), "Sending vRun packet failed"); + m_launch_response = response; + if (response.IsErrorResponse()) return response.GetStatus().ToError(); diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h index 5625185d28801..d04b1a8337cce 100644 --- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h +++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h @@ -26,6 +26,7 @@ #include "lldb/Utility/GDBRemote.h" #include "lldb/Utility/GPUGDBRemotePackets.h" #include "lldb/Utility/ProcessInfo.h" +#include "lldb/Utility/StringExtractorGDBRemote.h" #include "lldb/Utility/StructuredData.h" #include "lldb/Utility/TraceGDBRemotePackets.h" #include "lldb/Utility/UUID.h" @@ -270,6 +271,10 @@ class GDBRemoteCommunicationClient : public GDBRemoteClientBase { bool HasAnyVContSupport() { return GetVContSupported('a'); } bool GetStopReply(StringExtractorGDBRemote &response); + + std::optional GetLaunchResponse() { + return m_launch_response; + } bool GetThreadStopInfo(lldb::tid_t tid, StringExtractorGDBRemote &response); @@ -659,6 +664,7 @@ class GDBRemoteCommunicationClient : public GDBRemoteClientBase { bool m_qXfer_memory_map_loaded = false; // Used to pass a file descriptor from the GDB server back to the client. std::optional m_file_passing_fd; + std::optional m_launch_response; bool GetCurrentProcessInfo(bool allow_lazy_pid = true); bool GetGDBServerVersion(); diff --git a/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp b/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp index 90c67ea87ec40..e5ea8413f4723 100644 --- a/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp +++ b/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp @@ -7,6 +7,7 @@ //===----------------------------------------------------------------------===// #include "lldb/Host/Config.h" +#include "lldb/lldb-enumerations.h" #include #include @@ -821,7 +822,14 @@ Status ProcessGDBRemote::DoLaunch(lldb_private::Module *exe_module, } StringExtractorGDBRemote response; - if (m_gdb_comm.GetStopReply(response)) { + if (m_gdb_comm.GetLaunchResponse()) { + auto launch_response = *m_gdb_comm.GetLaunchResponse(); + if (launch_response.GetChar() == 'T' || launch_response.GetChar() == 'S') { + response = launch_response; + } + } + + if (response.IsNormalResponse() || m_gdb_comm.GetStopReply(response)) { SetLastStopPacket(response); const ArchSpec &process_arch = m_gdb_comm.GetProcessArchitecture(); @@ -6397,8 +6405,7 @@ void ProcessGDBRemote::SyncState::SetStateStopped(uint64_t stop_id) { void ProcessGDBRemote::SyncState::DidResume() { Log *log = GetLog(GDBRLog::Plugin); - std::lock_guard guard(m_mutex); - m_state = lldb::eStateRunning; + SetStateImpl(m_stop_id.value_or(0), lldb::eStateRunning); LLDB_LOG(log, "pid = {}, SyncState::{}() m_stop_id = {}, m_state = {}", m_process.GetID(), __FUNCTION__, m_stop_id, StateAsCString(m_state.value_or(lldb::eStateInvalid))); diff --git a/lldb/tools/lldb-server/Plugins/AMDGPU/LLDBServerPluginAMDGPU.cpp b/lldb/tools/lldb-server/Plugins/AMDGPU/LLDBServerPluginAMDGPU.cpp index 4190f12b9aca9..e6ee7b018fe9d 100644 --- a/lldb/tools/lldb-server/Plugins/AMDGPU/LLDBServerPluginAMDGPU.cpp +++ b/lldb/tools/lldb-server/Plugins/AMDGPU/LLDBServerPluginAMDGPU.cpp @@ -231,7 +231,7 @@ bool LLDBServerPluginAMDGPU::initRocm() { } bool LLDBServerPluginAMDGPU::processGPUEvent() { - LLDB_LOGF(GetLog(GDBRLog::Plugin), "processGPUEvent"); + LLDB_LOGF(GetLog(GDBRLog::Plugin), "processGPUEvent start"); char buf[256]; ssize_t bytesRead = 0; bool result = false; @@ -257,6 +257,7 @@ bool LLDBServerPluginAMDGPU::processGPUEvent() { assert(status == AMD_DBGAPI_STATUS_SUCCESS); break; } while (true); + LLDB_LOGF(GetLog(GDBRLog::Plugin), "processGPUEvent end (result=%d)", result); return result; } @@ -364,8 +365,12 @@ LLDBServerPluginAMDGPU::CreateConnection() { } std::optional LLDBServerPluginAMDGPU::NativeProcessIsStopping() { + static bool initialized = false; Log *log = GetLog(GDBRLog::Plugin); - if (!m_is_connected) { + LLDB_LOGF(log, "%s called: %d", __FUNCTION__, initialized); + if (!initialized) { + LLDB_LOGF(log, "%s initializing", __FUNCTION__); + initialized = true; initRocm(); ProcessManagerAMDGPU *manager = (ProcessManagerAMDGPU *)m_process_manager_up.get(); @@ -590,8 +595,8 @@ LLDBServerPluginAMDGPU::BreakpointWasHit(GPUPluginBreakpointHitArgs &args) { const auto bp_identifier = args.breakpoint.identifier; llvm::raw_string_ostream os(json_string); os << toJSON(args); - LLDB_LOGF(log, "LLDBServerPluginAMDGPU::BreakpointWasHit(\"%s\"):\nJSON:\n%s", - bp_identifier.c_str(), json_string.c_str()); + LLDB_LOGF(log, "LLDBServerPluginAMDGPU::BreakpointWasHit(\"%d\"):\nJSON:\n%s", + bp_identifier, json_string.c_str()); GPUPluginBreakpointHitResponse response; response.actions.plugin_name = GetPluginName(); @@ -613,11 +618,14 @@ LLDBServerPluginAMDGPU::BreakpointWasHit(GPUPluginBreakpointHitArgs &args) { bool success = HandleGPUInternalBreakpointHit(m_gpu_internal_bp.value()); assert(success); if (GetGPUProcess()->HasDyldChangesToReport()) { - response.actions.wait_for_gpu_process_to_resume = true; - auto *process = m_gdb_server->GetCurrentProcess(); - ThreadAMDGPU *thread = (ThreadAMDGPU *)process->GetCurrentThread(); - thread->SetStopReason(lldb::eStopReasonDynamicLoader); - process->Halt(); + if (GetGPUProcess()->IsRunning()) { + response.actions.wait_for_gpu_process_to_resume = true; + response.actions.stop_id = GetGPUProcess()->GetNextStopID(); + auto *process = m_gdb_server->GetCurrentProcess(); + ThreadAMDGPU *thread = (ThreadAMDGPU *)process->GetCurrentThread(); + thread->SetStopReason(lldb::eStopReasonDynamicLoader); + process->Halt(); + } } } return response;