[lldb] [Process/FreeBSDRemote] Fix attaching via lldb-server
authorMichał Górny <mgorny@moritz.systems>
Sat, 31 Oct 2020 09:30:13 +0000 (10:30 +0100)
committerMichał Górny <mgorny@moritz.systems>
Tue, 3 Nov 2020 08:45:50 +0000 (09:45 +0100)
Fix two bugs that caused attaching to a process in a pre-connected
lldb-server to fail.  These are:

1. Prematurely reporting status in NativeProcessFreeBSD::Attach().
   The SetState() call defaulted to notify the process, and LLGS tried
   to send the stopped packet before the process instance was assigned
   to it.  While at it, add an assert for that in LLGS.

2. Duplicate call to ReinitializeThreads() (via SetupTrace()) that
   overwrote the stopped status in threads.  Now SetupTrace() is called
   directly by NativeProcessFreeBSD::Attach() (not the Factory) in place
   of ReinitializeThreads().

This fixes at least commands/process/attach/TestProcessAttach.py
and python_api/hello_world/TestHelloWorld.py.

Differential Revision: https://reviews.llvm.org/D90525

lldb/source/Plugins/Process/FreeBSDRemote/NativeProcessFreeBSD.cpp
lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp

index 0a4e8ed6bcbfdee03d5c1eb502516ed3185f8188..a59fccb5cb65e5e207b0180129fdf3de72f977d9 100644 (file)
@@ -698,8 +698,9 @@ Status NativeProcessFreeBSD::Attach() {
       0)
     return Status(errno, eErrorTypePOSIX);
 
-  /* Initialize threads */
-  status = ReinitializeThreads();
+  // Initialize threads and tracing status
+  // NB: this needs to be called before we set thread state
+  status = SetupTrace();
   if (status.Fail())
     return status;
 
@@ -707,7 +708,8 @@ Status NativeProcessFreeBSD::Attach() {
     static_cast<NativeThreadFreeBSD &>(*thread).SetStoppedBySignal(SIGSTOP);
 
   // Let our process instance know the thread has stopped.
-  SetState(StateType::eStateStopped);
+  SetCurrentThreadID(m_threads.front()->GetID());
+  SetState(StateType::eStateStopped, false);
   return Status();
 }
 
index d19becca823f04cc0362cc00fe05e631b80d43dc..3b6f740a59833652edfc7aa5842d78439aed374b 100644 (file)
@@ -1728,6 +1728,7 @@ GDBRemoteCommunicationServerLLGS::SendStopReasonForState(
   case eStateSuspended:
   case eStateStopped:
   case eStateCrashed: {
+    assert(m_debugged_process_up != nullptr);
     lldb::tid_t tid = m_debugged_process_up->GetCurrentThreadID();
     // Make sure we set the current thread so g and p packets return the data
     // the gdb will expect.