Index: lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.h =================================================================== --- lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.h +++ lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.h @@ -86,6 +86,8 @@ const NativeProcessProtocol::Factory &m_process_factory; lldb::tid_t m_current_tid = LLDB_INVALID_THREAD_ID; lldb::tid_t m_continue_tid = LLDB_INVALID_THREAD_ID; + NativeProcessProtocol *m_current_process; + NativeProcessProtocol *m_continue_process; std::recursive_mutex m_debugged_process_mutex; std::unique_ptr m_debugged_process_up; @@ -254,7 +256,7 @@ // In any case, the function assumes that exactly one inferior is being // debugged and rejects pid values that do no match that inferior. llvm::Expected ReadTid(StringExtractorGDBRemote &packet, - bool allow_all = false); + bool allow_all, lldb::pid_t default_pid); // For GDBRemoteCommunicationServerLLGS only GDBRemoteCommunicationServerLLGS(const GDBRemoteCommunicationServerLLGS &) = Index: lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp =================================================================== --- lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp +++ lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp @@ -70,6 +70,7 @@ : GDBRemoteCommunicationServerCommon("gdb-remote.server", "gdb-remote.server.rx_packet"), m_mainloop(mainloop), m_process_factory(process_factory), + m_current_process(nullptr), m_continue_process(nullptr), m_stdio_communication("process.stdio") { RegisterPacketHandlers(); } @@ -249,6 +250,7 @@ if (!process_or) return Status(process_or.takeError()); m_debugged_process_up = std::move(*process_or); + m_continue_process = m_current_process = m_debugged_process_up.get(); } // Handle mirroring of inferior stdout/stderr over the gdb-remote protocol as @@ -318,6 +320,7 @@ return status; } m_debugged_process_up = std::move(*process_or); + m_continue_process = m_current_process = m_debugged_process_up.get(); // Setup stdout/stderr mapping from inferior. auto terminal_fd = m_debugged_process_up->GetTerminalFileDescriptor(); @@ -735,15 +738,15 @@ Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_PROCESS | LIBLLDB_LOG_THREAD)); // Ensure we have a debugged process. - if (!m_debugged_process_up || - (m_debugged_process_up->GetID() == LLDB_INVALID_PROCESS_ID)) + if (!m_current_process || + (m_current_process->GetID() == LLDB_INVALID_PROCESS_ID)) return SendErrorResponse(50); LLDB_LOG(log, "preparing packet for pid {0} tid {1}", - m_debugged_process_up->GetID(), tid); + m_current_process->GetID(), tid); // Ensure we can get info on the given thread. - NativeThreadProtocol *thread = m_debugged_process_up->GetThreadByID(tid); + NativeThreadProtocol *thread = m_current_process->GetThreadByID(tid); if (!thread) return SendErrorResponse(51); @@ -766,7 +769,7 @@ LLDB_LOG( log, "pid {0}, tid {1}, got signal signo = {2}, reason = {3}, exc_type = {4}", - m_debugged_process_up->GetID(), tid, signum, int(tid_stop_info.reason), + m_current_process->GetID(), tid, signum, int(tid_stop_info.reason), tid_stop_info.details.exception.type); // Print the signal number. @@ -804,9 +807,9 @@ uint32_t thread_index = 0; NativeThreadProtocol *listed_thread; - for (listed_thread = m_debugged_process_up->GetThreadAtIndex(thread_index); + for (listed_thread = m_current_process->GetThreadAtIndex(thread_index); listed_thread; ++thread_index, - listed_thread = m_debugged_process_up->GetThreadAtIndex(thread_index)) { + listed_thread = m_current_process->GetThreadAtIndex(thread_index)) { if (thread_index > 0) response.PutChar(','); response.Printf("%" PRIx64, listed_thread->GetID()); @@ -821,7 +824,7 @@ if (thread_index > 1) { const bool threads_with_valid_stop_info_only = true; llvm::Expected threads_info = GetJSONThreadsInfo( - *m_debugged_process_up, threads_with_valid_stop_info_only); + *m_current_process, threads_with_valid_stop_info_only); if (threads_info) { response.PutCString("jstopinfo:"); StreamString unescaped_response; @@ -831,7 +834,7 @@ } else { LLDB_LOG_ERROR(log, threads_info.takeError(), "failed to prepare a jstopinfo field for pid {1}: {0}", - m_debugged_process_up->GetID()); + m_current_process->GetID()); } } @@ -839,8 +842,7 @@ response.PutCString("thread-pcs"); char delimiter = ':'; for (NativeThreadProtocol *thread; - (thread = m_debugged_process_up->GetThreadAtIndex(i)) != nullptr; - ++i) { + (thread = m_current_process->GetThreadAtIndex(i)) != nullptr; ++i) { NativeRegisterContext& reg_ctx = thread->GetRegisterContext(); uint32_t reg_to_read = reg_ctx.ConvertRegisterKindToRegisterNumber( @@ -1173,19 +1175,19 @@ StringExtractorGDBRemote &packet) { // Fail if we don't have a current process. - if (!m_debugged_process_up || - (m_debugged_process_up->GetID() == LLDB_INVALID_PROCESS_ID)) + if (!m_current_process || + (m_current_process->GetID() == LLDB_INVALID_PROCESS_ID)) return SendErrorResponse(Status("Process not running.")); - return SendJSONResponse(m_debugged_process_up->TraceSupported()); + return SendJSONResponse(m_current_process->TraceSupported()); } GDBRemoteCommunication::PacketResult GDBRemoteCommunicationServerLLGS::Handle_jLLDBTraceStop( StringExtractorGDBRemote &packet) { // Fail if we don't have a current process. - if (!m_debugged_process_up || - (m_debugged_process_up->GetID() == LLDB_INVALID_PROCESS_ID)) + if (!m_current_process || + (m_current_process->GetID() == LLDB_INVALID_PROCESS_ID)) return SendErrorResponse(Status("Process not running.")); packet.ConsumeFront("jLLDBTraceStop:"); @@ -1194,7 +1196,7 @@ if (!stop_request) return SendErrorResponse(stop_request.takeError()); - if (Error err = m_debugged_process_up->TraceStop(*stop_request)) + if (Error err = m_current_process->TraceStop(*stop_request)) return SendErrorResponse(std::move(err)); return SendOKResponse(); @@ -1205,8 +1207,8 @@ StringExtractorGDBRemote &packet) { // Fail if we don't have a current process. - if (!m_debugged_process_up || - (m_debugged_process_up->GetID() == LLDB_INVALID_PROCESS_ID)) + if (!m_current_process || + (m_current_process->GetID() == LLDB_INVALID_PROCESS_ID)) return SendErrorResponse(Status("Process not running.")); packet.ConsumeFront("jLLDBTraceStart:"); @@ -1215,8 +1217,7 @@ if (!request) return SendErrorResponse(request.takeError()); - if (Error err = - m_debugged_process_up->TraceStart(packet.Peek(), request->type)) + if (Error err = m_current_process->TraceStart(packet.Peek(), request->type)) return SendErrorResponse(std::move(err)); return SendOKResponse(); @@ -1227,8 +1228,8 @@ StringExtractorGDBRemote &packet) { // Fail if we don't have a current process. - if (!m_debugged_process_up || - (m_debugged_process_up->GetID() == LLDB_INVALID_PROCESS_ID)) + if (!m_current_process || + (m_current_process->GetID() == LLDB_INVALID_PROCESS_ID)) return SendErrorResponse(Status("Process not running.")); packet.ConsumeFront("jLLDBTraceGetState:"); @@ -1237,7 +1238,7 @@ if (!request) return SendErrorResponse(request.takeError()); - return SendJSONResponse(m_debugged_process_up->TraceGetState(request->type)); + return SendJSONResponse(m_current_process->TraceGetState(request->type)); } GDBRemoteCommunication::PacketResult @@ -1245,8 +1246,8 @@ StringExtractorGDBRemote &packet) { // Fail if we don't have a current process. - if (!m_debugged_process_up || - (m_debugged_process_up->GetID() == LLDB_INVALID_PROCESS_ID)) + if (!m_current_process || + (m_current_process->GetID() == LLDB_INVALID_PROCESS_ID)) return SendErrorResponse(Status("Process not running.")); packet.ConsumeFront("jLLDBTraceGetBinaryData:"); @@ -1257,7 +1258,7 @@ return SendErrorResponse(Status(request.takeError())); if (Expected> bytes = - m_debugged_process_up->TraceGetBinaryData(*request)) { + m_current_process->TraceGetBinaryData(*request)) { StreamGDBRemote response; response.PutEscapedBytes(bytes->data(), bytes->size()); return SendPacketNoLock(response.GetString()); @@ -1269,11 +1270,11 @@ GDBRemoteCommunicationServerLLGS::Handle_qProcessInfo( StringExtractorGDBRemote &packet) { // Fail if we don't have a current process. - if (!m_debugged_process_up || - (m_debugged_process_up->GetID() == LLDB_INVALID_PROCESS_ID)) + if (!m_current_process || + (m_current_process->GetID() == LLDB_INVALID_PROCESS_ID)) return SendErrorResponse(68); - lldb::pid_t pid = m_debugged_process_up->GetID(); + lldb::pid_t pid = m_current_process->GetID(); if (pid == LLDB_INVALID_PROCESS_ID) return SendErrorResponse(1); @@ -1290,16 +1291,16 @@ GDBRemoteCommunication::PacketResult GDBRemoteCommunicationServerLLGS::Handle_qC(StringExtractorGDBRemote &packet) { // Fail if we don't have a current process. - if (!m_debugged_process_up || - (m_debugged_process_up->GetID() == LLDB_INVALID_PROCESS_ID)) + if (!m_current_process || + (m_current_process->GetID() == LLDB_INVALID_PROCESS_ID)) return SendErrorResponse(68); // Make sure we set the current thread so g and p packets return the data the // gdb will expect. - lldb::tid_t tid = m_debugged_process_up->GetCurrentThreadID(); + lldb::tid_t tid = m_current_process->GetCurrentThreadID(); SetCurrentThreadID(tid); - NativeThreadProtocol *thread = m_debugged_process_up->GetCurrentThread(); + NativeThreadProtocol *thread = m_current_process->GetCurrentThread(); if (!thread) return SendErrorResponse(69); @@ -1315,15 +1316,15 @@ StopSTDIOForwarding(); - if (!m_debugged_process_up) { + if (!m_current_process) { LLDB_LOG(log, "No debugged process found."); return PacketResult::Success; } - Status error = m_debugged_process_up->Kill(); + Status error = m_current_process->Kill(); if (error.Fail()) LLDB_LOG(log, "Failed to kill debugged process {0}: {1}", - m_debugged_process_up->GetID(), error); + m_current_process->GetID(), error); // No OK response for kill packet. // return SendOKResponse (); @@ -1370,7 +1371,7 @@ LLDB_LOGF(log, "GDBRemoteCommunicationServerLLGS::%s called", __FUNCTION__); // Ensure we have a native process. - if (!m_debugged_process_up) { + if (!m_continue_process) { LLDB_LOGF(log, "GDBRemoteCommunicationServerLLGS::%s no debugged process " "shared pointer", @@ -1423,20 +1424,20 @@ } else { // Send the signal to the process since we weren't targeting a specific // continue thread with the signal. - error = m_debugged_process_up->Signal(signo); + error = m_continue_process->Signal(signo); if (error.Fail()) { LLDB_LOG(log, "failed to send signal for process {0}: {1}", - m_debugged_process_up->GetID(), error); + m_continue_process->GetID(), error); return SendErrorResponse(0x52); } } // Resume the threads. - error = m_debugged_process_up->Resume(resume_actions); + error = m_continue_process->Resume(resume_actions); if (error.Fail()) { LLDB_LOG(log, "failed to resume threads for process {0}: {1}", - m_debugged_process_up->GetID(), error); + m_continue_process->GetID(), error); return SendErrorResponse(0x38); } @@ -1461,7 +1462,7 @@ } // Ensure we have a native process. - if (!m_debugged_process_up) { + if (!m_continue_process) { LLDB_LOGF(log, "GDBRemoteCommunicationServerLLGS::%s no debugged process " "shared pointer", @@ -1473,14 +1474,14 @@ ResumeActionList actions(StateType::eStateRunning, LLDB_INVALID_SIGNAL_NUMBER); - Status error = m_debugged_process_up->Resume(actions); + Status error = m_continue_process->Resume(actions); if (error.Fail()) { - LLDB_LOG(log, "c failed for process {0}: {1}", - m_debugged_process_up->GetID(), error); + LLDB_LOG(log, "c failed for process {0}: {1}", m_continue_process->GetID(), + error); return SendErrorResponse(GDBRemoteServerError::eErrorResume); } - LLDB_LOG(log, "continued process {0}", m_debugged_process_up->GetID()); + LLDB_LOG(log, "continued process {0}", m_continue_process->GetID()); // No response required from continue. return PacketResult::Success; } @@ -1523,7 +1524,7 @@ } // Ensure we have a native process. - if (!m_debugged_process_up) { + if (!m_continue_process) { LLDB_LOG(log, "no debugged process"); return SendErrorResponse(0x36); } @@ -1576,7 +1577,8 @@ // Consume the separator. packet.GetChar(); - llvm::Expected tid_ret = ReadTid(packet, /*allow_all=*/true); + llvm::Expected tid_ret = + ReadTid(packet, /*allow_all=*/true, m_continue_process->GetID()); if (!tid_ret) return SendErrorResponse(tid_ret.takeError()); @@ -1588,14 +1590,14 @@ thread_actions.Append(thread_action); } - Status error = m_debugged_process_up->Resume(thread_actions); + Status error = m_continue_process->Resume(thread_actions); if (error.Fail()) { LLDB_LOG(log, "vCont failed for process {0}: {1}", - m_debugged_process_up->GetID(), error); + m_continue_process->GetID(), error); return SendErrorResponse(GDBRemoteServerError::eErrorResume); } - LLDB_LOG(log, "continued process {0}", m_debugged_process_up->GetID()); + LLDB_LOG(log, "continued process {0}", m_continue_process->GetID()); // No response required from vCont. return PacketResult::Success; } @@ -1605,8 +1607,8 @@ LLDB_LOG(log, "setting current thread id to {0}", tid); m_current_tid = tid; - if (m_debugged_process_up) - m_debugged_process_up->SetCurrentThreadID(m_current_tid); + if (m_current_process) + m_current_process->SetCurrentThreadID(m_current_tid); } void GDBRemoteCommunicationServerLLGS::SetContinueThreadID(lldb::tid_t tid) { @@ -1622,10 +1624,10 @@ // Handle the $? gdbremote command. // If no process, indicate error - if (!m_debugged_process_up) + if (!m_current_process) return SendErrorResponse(02); - return SendStopReasonForState(m_debugged_process_up->GetState()); + return SendStopReasonForState(m_current_process->GetState()); } GDBRemoteCommunication::PacketResult @@ -1646,8 +1648,8 @@ case eStateSuspended: case eStateStopped: case eStateCrashed: { - assert(m_debugged_process_up != nullptr); - lldb::tid_t tid = m_debugged_process_up->GetCurrentThreadID(); + assert(m_current_process != nullptr); + lldb::tid_t tid = m_current_process->GetCurrentThreadID(); // Make sure we set the current thread so g and p packets return the data // the gdb will expect. SetCurrentThreadID(tid); @@ -1657,11 +1659,11 @@ case eStateInvalid: case eStateUnloaded: case eStateExited: - return SendWResponse(m_debugged_process_up.get()); + return SendWResponse(m_current_process); default: LLDB_LOG(log, "pid {0}, current state reporting not handled: {1}", - m_debugged_process_up->GetID(), process_state); + m_current_process->GetID(), process_state); break; } @@ -1672,12 +1674,12 @@ GDBRemoteCommunicationServerLLGS::Handle_qRegisterInfo( StringExtractorGDBRemote &packet) { // Fail if we don't have a current process. - if (!m_debugged_process_up || - (m_debugged_process_up->GetID() == LLDB_INVALID_PROCESS_ID)) + if (!m_current_process || + (m_current_process->GetID() == LLDB_INVALID_PROCESS_ID)) return SendErrorResponse(68); // Ensure we have a thread. - NativeThreadProtocol *thread = m_debugged_process_up->GetThreadAtIndex(0); + NativeThreadProtocol *thread = m_current_process->GetThreadAtIndex(0); if (!thread) return SendErrorResponse(69); @@ -1772,11 +1774,11 @@ Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_THREAD)); // Fail if we don't have a current process. - if (!m_debugged_process_up || - (m_debugged_process_up->GetID() == LLDB_INVALID_PROCESS_ID)) { + if (!m_current_process || + (m_current_process->GetID() == LLDB_INVALID_PROCESS_ID)) { LLDB_LOG(log, "no process ({0}), returning OK", - m_debugged_process_up ? "invalid process id" - : "null m_debugged_process_up"); + m_current_process ? "invalid process id" + : "null m_current_process"); return SendOKResponse(); } @@ -1787,9 +1789,9 @@ NativeThreadProtocol *thread; uint32_t thread_index; for (thread_index = 0, - thread = m_debugged_process_up->GetThreadAtIndex(thread_index); + thread = m_current_process->GetThreadAtIndex(thread_index); thread; ++thread_index, - thread = m_debugged_process_up->GetThreadAtIndex(thread_index)) { + thread = m_current_process->GetThreadAtIndex(thread_index)) { LLDB_LOG(log, "iterated thread {0}(tid={2})", thread_index, thread->GetID()); if (thread_index > 0) @@ -2010,9 +2012,8 @@ // Build the reginfos response. StreamGDBRemote response; - RegisterValue reg_value( - makeArrayRef(reg_bytes, reg_size), - m_debugged_process_up->GetArchitecture().GetByteOrder()); + RegisterValue reg_value(makeArrayRef(reg_bytes, reg_size), + m_current_process->GetArchitecture().GetByteOrder()); Status error = reg_context.WriteRegister(reg_info, reg_value); if (error.Fail()) { LLDB_LOGF(log, @@ -2030,8 +2031,8 @@ Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_THREAD)); // Fail if we don't have a current process. - if (!m_debugged_process_up || - (m_debugged_process_up->GetID() == LLDB_INVALID_PROCESS_ID)) { + if (!m_current_process || + (m_current_process->GetID() == LLDB_INVALID_PROCESS_ID)) { LLDB_LOGF( log, "GDBRemoteCommunicationServerLLGS::%s failed, no process available", @@ -2050,11 +2051,14 @@ } const char h_variant = packet.GetChar(); + lldb::pid_t default_pid; switch (h_variant) { case 'g': + default_pid = m_current_process->GetID(); break; case 'c': + default_pid = m_continue_process->GetID(); break; default: @@ -2067,7 +2071,8 @@ } // Parse out the thread number. - llvm::Expected tid_ret = ReadTid(packet, /*allow_all=*/true); + llvm::Expected tid_ret = + ReadTid(packet, /*allow_all=*/true, default_pid); if (!tid_ret) return SendErrorResponse(tid_ret.takeError()); @@ -2075,7 +2080,7 @@ // Ensure we have the given thread when not specifying -1 (all threads) or 0 // (any thread). if (tid != LLDB_INVALID_THREAD_ID && tid != 0) { - NativeThreadProtocol *thread = m_debugged_process_up->GetThreadByID(tid); + NativeThreadProtocol *thread = m_current_process->GetThreadByID(tid); if (!thread) { LLDB_LOGF(log, "GDBRemoteCommunicationServerLLGS::%s failed, tid %" PRIu64 @@ -2109,8 +2114,8 @@ Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_THREAD)); // Fail if we don't have a current process. - if (!m_debugged_process_up || - (m_debugged_process_up->GetID() == LLDB_INVALID_PROCESS_ID)) { + if (!m_current_process || + (m_current_process->GetID() == LLDB_INVALID_PROCESS_ID)) { LLDB_LOGF( log, "GDBRemoteCommunicationServerLLGS::%s failed, no process available", @@ -2145,21 +2150,21 @@ Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_PROCESS | LIBLLDB_LOG_THREAD)); // Fail if we don't have a current process. - if (!m_debugged_process_up || - (m_debugged_process_up->GetID() == LLDB_INVALID_PROCESS_ID)) { + if (!m_current_process || + (m_current_process->GetID() == LLDB_INVALID_PROCESS_ID)) { LLDB_LOG(log, "failed, no process available"); return SendErrorResponse(0x15); } // Interrupt the process. - Status error = m_debugged_process_up->Interrupt(); + Status error = m_current_process->Interrupt(); if (error.Fail()) { - LLDB_LOG(log, "failed for process {0}: {1}", m_debugged_process_up->GetID(), + LLDB_LOG(log, "failed for process {0}: {1}", m_current_process->GetID(), error); return SendErrorResponse(GDBRemoteServerError::eErrorResume); } - LLDB_LOG(log, "stopped process {0}", m_debugged_process_up->GetID()); + LLDB_LOG(log, "stopped process {0}", m_current_process->GetID()); // No response required from stop all. return PacketResult::Success; @@ -2170,8 +2175,8 @@ StringExtractorGDBRemote &packet) { Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_PROCESS)); - if (!m_debugged_process_up || - (m_debugged_process_up->GetID() == LLDB_INVALID_PROCESS_ID)) { + if (!m_current_process || + (m_current_process->GetID() == LLDB_INVALID_PROCESS_ID)) { LLDB_LOGF( log, "GDBRemoteCommunicationServerLLGS::%s failed, no process available", @@ -2213,13 +2218,13 @@ // Retrieve the process memory. size_t bytes_read = 0; - Status error = m_debugged_process_up->ReadMemoryWithoutTrap( + 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_debugged_process_up->GetID(), read_addr, + __FUNCTION__, m_current_process->GetID(), read_addr, error.AsCString()); return SendErrorResponse(0x08); } @@ -2228,8 +2233,7 @@ LLDB_LOGF(log, "GDBRemoteCommunicationServerLLGS::%s pid %" PRIu64 " mem 0x%" PRIx64 ": read 0 of %" PRIu64 " requested bytes", - __FUNCTION__, m_debugged_process_up->GetID(), read_addr, - byte_count); + __FUNCTION__, m_current_process->GetID(), read_addr, byte_count); return SendErrorResponse(0x08); } @@ -2251,8 +2255,8 @@ GDBRemoteCommunicationServerLLGS::Handle__M(StringExtractorGDBRemote &packet) { Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_PROCESS)); - if (!m_debugged_process_up || - (m_debugged_process_up->GetID() == LLDB_INVALID_PROCESS_ID)) { + if (!m_current_process || + (m_current_process->GetID() == LLDB_INVALID_PROCESS_ID)) { LLDB_LOGF( log, "GDBRemoteCommunicationServerLLGS::%s failed, no process available", @@ -2287,8 +2291,7 @@ } } - llvm::Expected addr = - m_debugged_process_up->AllocateMemory(size, perms); + llvm::Expected addr = m_current_process->AllocateMemory(size, perms); if (!addr) return SendErrorResponse(addr.takeError()); @@ -2301,8 +2304,8 @@ GDBRemoteCommunicationServerLLGS::Handle__m(StringExtractorGDBRemote &packet) { Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_PROCESS)); - if (!m_debugged_process_up || - (m_debugged_process_up->GetID() == LLDB_INVALID_PROCESS_ID)) { + if (!m_current_process || + (m_current_process->GetID() == LLDB_INVALID_PROCESS_ID)) { LLDB_LOGF( log, "GDBRemoteCommunicationServerLLGS::%s failed, no process available", @@ -2319,7 +2322,7 @@ if (addr == LLDB_INVALID_ADDRESS) return SendIllFormedResponse(packet, "Address not valid"); - if (llvm::Error Err = m_debugged_process_up->DeallocateMemory(addr)) + if (llvm::Error Err = m_current_process->DeallocateMemory(addr)) return SendErrorResponse(std::move(Err)); return SendOKResponse(); @@ -2329,8 +2332,8 @@ GDBRemoteCommunicationServerLLGS::Handle_M(StringExtractorGDBRemote &packet) { Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_PROCESS)); - if (!m_debugged_process_up || - (m_debugged_process_up->GetID() == LLDB_INVALID_PROCESS_ID)) { + if (!m_current_process || + (m_current_process->GetID() == LLDB_INVALID_PROCESS_ID)) { LLDB_LOGF( log, "GDBRemoteCommunicationServerLLGS::%s failed, no process available", @@ -2379,8 +2382,7 @@ LLDB_LOG(log, "pid {0} mem {1:x}: asked to write {2} bytes, but only found {3} " "to convert.", - m_debugged_process_up->GetID(), write_addr, byte_count, - convert_count); + m_current_process->GetID(), write_addr, byte_count, convert_count); return SendIllFormedResponse(packet, "M content byte length specified did " "not match hex-encoded content " "length"); @@ -2388,17 +2390,17 @@ // Write the process memory. size_t bytes_written = 0; - Status error = m_debugged_process_up->WriteMemory(write_addr, &buf[0], - byte_count, bytes_written); + Status error = m_current_process->WriteMemory(write_addr, &buf[0], + byte_count, bytes_written); if (error.Fail()) { LLDB_LOG(log, "pid {0} mem {1:x}: failed to write. Error: {2}", - m_debugged_process_up->GetID(), write_addr, error); + m_current_process->GetID(), write_addr, error); return SendErrorResponse(0x09); } if (bytes_written == 0) { LLDB_LOG(log, "pid {0} mem {1:x}: wrote 0 of {2} requested bytes", - m_debugged_process_up->GetID(), write_addr, byte_count); + m_current_process->GetID(), write_addr, byte_count); return SendErrorResponse(0x09); } @@ -2417,8 +2419,8 @@ // Ensure we have a process running; otherwise, we can't figure this out // since we won't have a NativeProcessProtocol. - if (!m_debugged_process_up || - (m_debugged_process_up->GetID() == LLDB_INVALID_PROCESS_ID)) { + if (!m_current_process || + (m_current_process->GetID() == LLDB_INVALID_PROCESS_ID)) { LLDB_LOGF( log, "GDBRemoteCommunicationServerLLGS::%s failed, no process available", @@ -2428,8 +2430,7 @@ // Test if we can get any region back when asking for the region around NULL. MemoryRegionInfo region_info; - const Status error = - m_debugged_process_up->GetMemoryRegionInfo(0, region_info); + const Status error = m_current_process->GetMemoryRegionInfo(0, region_info); if (error.Fail()) { // We don't support memory region info collection for this // NativeProcessProtocol. @@ -2445,8 +2446,8 @@ Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_PROCESS)); // Ensure we have a process. - if (!m_debugged_process_up || - (m_debugged_process_up->GetID() == LLDB_INVALID_PROCESS_ID)) { + if (!m_current_process || + (m_current_process->GetID() == LLDB_INVALID_PROCESS_ID)) { LLDB_LOGF( log, "GDBRemoteCommunicationServerLLGS::%s failed, no process available", @@ -2467,7 +2468,7 @@ // Get the memory region info for the target address. MemoryRegionInfo region_info; const Status error = - m_debugged_process_up->GetMemoryRegionInfo(read_addr, region_info); + m_current_process->GetMemoryRegionInfo(read_addr, region_info); if (error.Fail()) { // Return the error message. @@ -2522,8 +2523,8 @@ GDBRemoteCommunication::PacketResult GDBRemoteCommunicationServerLLGS::Handle_Z(StringExtractorGDBRemote &packet) { // Ensure we have a process. - if (!m_debugged_process_up || - (m_debugged_process_up->GetID() == LLDB_INVALID_PROCESS_ID)) { + if (!m_current_process || + (m_current_process->GetID() == LLDB_INVALID_PROCESS_ID)) { Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_PROCESS)); LLDB_LOG(log, "failed, no process available"); return SendErrorResponse(0x15); @@ -2593,22 +2594,22 @@ if (want_breakpoint) { // Try to set the breakpoint. const Status error = - m_debugged_process_up->SetBreakpoint(addr, size, want_hardware); + m_current_process->SetBreakpoint(addr, size, want_hardware); if (error.Success()) return SendOKResponse(); Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_BREAKPOINTS)); LLDB_LOG(log, "pid {0} failed to set breakpoint: {1}", - m_debugged_process_up->GetID(), error); + m_current_process->GetID(), error); return SendErrorResponse(0x09); } else { // Try to set the watchpoint. - const Status error = m_debugged_process_up->SetWatchpoint( + const Status error = m_current_process->SetWatchpoint( addr, size, watch_flags, want_hardware); if (error.Success()) return SendOKResponse(); Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_WATCHPOINTS)); LLDB_LOG(log, "pid {0} failed to set watchpoint: {1}", - m_debugged_process_up->GetID(), error); + m_current_process->GetID(), error); return SendErrorResponse(0x09); } } @@ -2616,8 +2617,8 @@ GDBRemoteCommunication::PacketResult GDBRemoteCommunicationServerLLGS::Handle_z(StringExtractorGDBRemote &packet) { // Ensure we have a process. - if (!m_debugged_process_up || - (m_debugged_process_up->GetID() == LLDB_INVALID_PROCESS_ID)) { + if (!m_current_process || + (m_current_process->GetID() == LLDB_INVALID_PROCESS_ID)) { Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_PROCESS)); LLDB_LOG(log, "failed, no process available"); return SendErrorResponse(0x15); @@ -2681,21 +2682,21 @@ if (want_breakpoint) { // Try to clear the breakpoint. const Status error = - m_debugged_process_up->RemoveBreakpoint(addr, want_hardware); + m_current_process->RemoveBreakpoint(addr, want_hardware); if (error.Success()) return SendOKResponse(); Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_BREAKPOINTS)); LLDB_LOG(log, "pid {0} failed to remove breakpoint: {1}", - m_debugged_process_up->GetID(), error); + m_current_process->GetID(), error); return SendErrorResponse(0x09); } else { // Try to clear the watchpoint. - const Status error = m_debugged_process_up->RemoveWatchpoint(addr); + const Status error = m_current_process->RemoveWatchpoint(addr); if (error.Success()) return SendOKResponse(); Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_WATCHPOINTS)); LLDB_LOG(log, "pid {0} failed to remove watchpoint: {1}", - m_debugged_process_up->GetID(), error); + m_current_process->GetID(), error); return SendErrorResponse(0x09); } } @@ -2705,8 +2706,8 @@ Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_PROCESS | LIBLLDB_LOG_THREAD)); // Ensure we have a process. - if (!m_debugged_process_up || - (m_debugged_process_up->GetID() == LLDB_INVALID_PROCESS_ID)) { + if (!m_continue_process || + (m_continue_process->GetID() == LLDB_INVALID_PROCESS_ID)) { LLDB_LOGF( log, "GDBRemoteCommunicationServerLLGS::%s failed, no process available", @@ -2724,7 +2725,7 @@ // Double check that we have such a thread. // TODO investigate: on MacOSX we might need to do an UpdateThreads () here. - NativeThreadProtocol *thread = m_debugged_process_up->GetThreadByID(tid); + NativeThreadProtocol *thread = m_continue_process->GetThreadByID(tid); if (!thread) return SendErrorResponse(0x33); @@ -2737,12 +2738,12 @@ // All other threads stop while we're single stepping a thread. actions.SetDefaultThreadActionIfNeeded(eStateStopped, 0); - Status error = m_debugged_process_up->Resume(actions); + Status error = m_continue_process->Resume(actions); if (error.Fail()) { LLDB_LOGF(log, "GDBRemoteCommunicationServerLLGS::%s pid %" PRIu64 " tid %" PRIu64 " Resume() failed with error: %s", - __FUNCTION__, m_debugged_process_up->GetID(), tid, + __FUNCTION__, m_continue_process->GetID(), tid, error.AsCString()); return SendErrorResponse(0x49); } @@ -2754,7 +2755,7 @@ llvm::Expected> GDBRemoteCommunicationServerLLGS::BuildTargetXml() { // Ensure we have a thread. - NativeThreadProtocol *thread = m_debugged_process_up->GetThreadAtIndex(0); + NativeThreadProtocol *thread = m_current_process->GetThreadAtIndex(0); if (!thread) return llvm::createStringError(llvm::inconvertibleErrorCode(), "No thread available"); @@ -2769,7 +2770,7 @@ response.Printf(""); response.Printf("%s", - m_debugged_process_up->GetArchitecture() + m_current_process->GetArchitecture() .GetTriple() .getArchName() .str() @@ -2858,22 +2859,22 @@ GDBRemoteCommunicationServerLLGS::ReadXferObject(llvm::StringRef object, llvm::StringRef annex) { // Make sure we have a valid process. - if (!m_debugged_process_up || - (m_debugged_process_up->GetID() == LLDB_INVALID_PROCESS_ID)) { + if (!m_current_process || + (m_current_process->GetID() == LLDB_INVALID_PROCESS_ID)) { return llvm::createStringError(llvm::inconvertibleErrorCode(), "No process available"); } if (object == "auxv") { // Grab the auxv data. - auto buffer_or_error = m_debugged_process_up->GetAuxvData(); + auto buffer_or_error = m_current_process->GetAuxvData(); if (!buffer_or_error) return llvm::errorCodeToError(buffer_or_error.getError()); return std::move(*buffer_or_error); } if (object == "libraries-svr4") { - auto library_list = m_debugged_process_up->GetLoadedSVR4Libraries(); + auto library_list = m_current_process->GetLoadedSVR4Libraries(); if (!library_list) return library_list.takeError(); @@ -2996,7 +2997,7 @@ Status error = reg_context.ReadAllRegisterValues(register_data_sp); if (error.Fail()) { LLDB_LOG(log, "pid {0} failed to save all register values: {1}", - m_debugged_process_up->GetID(), error); + m_current_process->GetID(), error); return SendErrorResponse(0x75); } @@ -3059,7 +3060,7 @@ if (it == m_saved_registers_map.end()) { LLDB_LOG(log, "pid {0} does not have a register set save buffer for id {1}", - m_debugged_process_up->GetID(), save_id); + m_current_process->GetID(), save_id); return SendErrorResponse(0x77); } register_data_sp = it->second; @@ -3071,7 +3072,7 @@ Status error = reg_context.WriteAllRegisterValues(register_data_sp); if (error.Fail()) { LLDB_LOG(log, "pid {0} failed to restore all register values: {1}", - m_debugged_process_up->GetID(), error); + m_current_process->GetID(), error); return SendErrorResponse(0x77); } @@ -3111,7 +3112,7 @@ } // Notify we attached by sending a stop packet. - return SendStopReasonForState(m_debugged_process_up->GetState()); + return SendStopReasonForState(m_current_process->GetState()); } GDBRemoteCommunication::PacketResult @@ -3141,7 +3142,7 @@ } // Notify we attached by sending a stop packet. - return SendStopReasonForState(m_debugged_process_up->GetState()); + return SendStopReasonForState(m_current_process->GetState()); } GDBRemoteCommunication::PacketResult @@ -3177,7 +3178,7 @@ } // Notify we attached by sending a stop packet. - return SendStopReasonForState(m_debugged_process_up->GetState()); + return SendStopReasonForState(m_current_process->GetState()); } GDBRemoteCommunication::PacketResult @@ -3187,8 +3188,8 @@ StopSTDIOForwarding(); // Fail if we don't have a current process. - if (!m_debugged_process_up || - (m_debugged_process_up->GetID() == LLDB_INVALID_PROCESS_ID)) { + if (!m_current_process || + (m_current_process->GetID() == LLDB_INVALID_PROCESS_ID)) { LLDB_LOGF( log, "GDBRemoteCommunicationServerLLGS::%s failed, no process available", @@ -3210,16 +3211,16 @@ return SendIllFormedResponse(packet, "D failed to parse the process id"); } - if (pid != LLDB_INVALID_PROCESS_ID && m_debugged_process_up->GetID() != pid) { + if (pid != LLDB_INVALID_PROCESS_ID && m_current_process->GetID() != pid) { return SendIllFormedResponse(packet, "Invalid pid"); } - const Status error = m_debugged_process_up->Detach(); + const Status error = m_current_process->Detach(); if (error.Fail()) { LLDB_LOGF(log, "GDBRemoteCommunicationServerLLGS::%s failed to detach from " "pid %" PRIu64 ": %s\n", - __FUNCTION__, m_debugged_process_up->GetID(), error.AsCString()); + __FUNCTION__, m_current_process->GetID(), error.AsCString()); return SendErrorResponse(0x01); } @@ -3249,19 +3250,19 @@ Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_PROCESS | LIBLLDB_LOG_THREAD)); // Ensure we have a debugged process. - if (!m_debugged_process_up || - (m_debugged_process_up->GetID() == LLDB_INVALID_PROCESS_ID)) + if (!m_current_process || + (m_current_process->GetID() == LLDB_INVALID_PROCESS_ID)) return SendErrorResponse(50); - LLDB_LOG(log, "preparing packet for pid {0}", m_debugged_process_up->GetID()); + LLDB_LOG(log, "preparing packet for pid {0}", m_current_process->GetID()); StreamString response; const bool threads_with_valid_stop_info_only = false; - llvm::Expected threads_info = GetJSONThreadsInfo( - *m_debugged_process_up, threads_with_valid_stop_info_only); + llvm::Expected threads_info = + GetJSONThreadsInfo(*m_current_process, threads_with_valid_stop_info_only); if (!threads_info) { LLDB_LOG_ERROR(log, threads_info.takeError(), "failed to prepare a packet for pid {1}: {0}", - m_debugged_process_up->GetID()); + m_current_process->GetID()); return SendErrorResponse(52); } @@ -3275,8 +3276,8 @@ GDBRemoteCommunicationServerLLGS::Handle_qWatchpointSupportInfo( StringExtractorGDBRemote &packet) { // Fail if we don't have a current process. - if (!m_debugged_process_up || - m_debugged_process_up->GetID() == LLDB_INVALID_PROCESS_ID) + if (!m_current_process || + m_current_process->GetID() == LLDB_INVALID_PROCESS_ID) return SendErrorResponse(68); packet.SetFilePos(strlen("qWatchpointSupportInfo")); @@ -3285,7 +3286,7 @@ if (packet.GetChar() != ':') return SendErrorResponse(67); - auto hw_debug_cap = m_debugged_process_up->GetHardwareDebugSupportInfo(); + auto hw_debug_cap = m_current_process->GetHardwareDebugSupportInfo(); StreamGDBRemote response; if (hw_debug_cap == llvm::None) @@ -3300,8 +3301,8 @@ GDBRemoteCommunicationServerLLGS::Handle_qFileLoadAddress( StringExtractorGDBRemote &packet) { // Fail if we don't have a current process. - if (!m_debugged_process_up || - m_debugged_process_up->GetID() == LLDB_INVALID_PROCESS_ID) + if (!m_current_process || + m_current_process->GetID() == LLDB_INVALID_PROCESS_ID) return SendErrorResponse(67); packet.SetFilePos(strlen("qFileLoadAddress:")); @@ -3313,7 +3314,7 @@ lldb::addr_t file_load_address = LLDB_INVALID_ADDRESS; Status error = - m_debugged_process_up->GetFileLoadAddress(file_name, file_load_address); + m_current_process->GetFileLoadAddress(file_name, file_load_address); if (error.Fail()) return SendErrorResponse(69); @@ -3349,10 +3350,10 @@ } // Fail if we don't have a current process. - if (!m_debugged_process_up) + if (!m_current_process) return SendErrorResponse(68); - Status error = m_debugged_process_up->IgnoreSignals(signals); + Status error = m_current_process->IgnoreSignals(signals); if (error.Fail()) return SendErrorResponse(69); @@ -3387,8 +3388,8 @@ NativeThreadProtocol *GDBRemoteCommunicationServerLLGS::GetThreadFromSuffix( StringExtractorGDBRemote &packet) { // We have no thread if we don't have a process. - if (!m_debugged_process_up || - m_debugged_process_up->GetID() == LLDB_INVALID_PROCESS_ID) + if (!m_current_process || + m_current_process->GetID() == LLDB_INVALID_PROCESS_ID) return nullptr; // If the client hasn't asked for thread suffix support, there will not be a @@ -3399,9 +3400,9 @@ return nullptr; else if (current_tid == 0) { // Pick a thread. - return m_debugged_process_up->GetThreadAtIndex(0); + return m_current_process->GetThreadAtIndex(0); } else - return m_debugged_process_up->GetThreadByID(current_tid); + return m_current_process->GetThreadByID(current_tid); } Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_THREAD)); @@ -3431,7 +3432,7 @@ packet.SetFilePos(packet.GetFilePos() + strlen("thread:")); const lldb::tid_t tid = packet.GetHexMaxU64(false, 0); if (tid != 0) - return m_debugged_process_up->GetThreadByID(tid); + return m_current_process->GetThreadByID(tid); return nullptr; } @@ -3441,9 +3442,9 @@ // Use whatever the debug process says is the current thread id since the // protocol either didn't specify or specified we want any/all threads // marked as the current thread. - if (!m_debugged_process_up) + if (!m_current_process) return LLDB_INVALID_THREAD_ID; - return m_debugged_process_up->GetCurrentThreadID(); + return m_current_process->GetCurrentThreadID(); } // Use the specific current thread id set by the gdb remote protocol. return m_current_tid; @@ -3464,9 +3465,9 @@ FileSpec GDBRemoteCommunicationServerLLGS::FindModuleFile(const std::string &module_path, const ArchSpec &arch) { - if (m_debugged_process_up) { + if (m_current_process) { FileSpec file_spec; - if (m_debugged_process_up + if (m_current_process ->GetLoadedModuleFileSpec(module_path.c_str(), file_spec) .Success()) { if (FileSystem::Instance().Exists(file_spec)) @@ -3502,13 +3503,12 @@ return result; } -llvm::Expected -GDBRemoteCommunicationServerLLGS::ReadTid(StringExtractorGDBRemote &packet, - bool allow_all) { - assert(m_debugged_process_up); - assert(m_debugged_process_up->GetID() != LLDB_INVALID_PROCESS_ID); +llvm::Expected GDBRemoteCommunicationServerLLGS::ReadTid( + StringExtractorGDBRemote &packet, bool allow_all, lldb::pid_t default_pid) { + assert(m_current_process); + assert(m_current_process->GetID() != LLDB_INVALID_PROCESS_ID); - auto pid_tid = packet.GetPidTid(m_debugged_process_up->GetID()); + auto pid_tid = packet.GetPidTid(default_pid); if (!pid_tid) return llvm::make_error(inconvertibleErrorCode(), "Malformed thread-id"); @@ -3527,7 +3527,7 @@ llvm::formatv("TID value {0} not allowed", tid == 0 ? 0 : -1)); if (pid != StringExtractorGDBRemote::AllProcesses) { - if (pid != m_debugged_process_up->GetID()) + if (pid != m_current_process->GetID()) return llvm::make_error( inconvertibleErrorCode(), llvm::formatv("PID {0} not debugged", pid)); }