mib created this revision.
mib added reviewers: jingham, JDevlieghere.
Herald added a project: All.
mib requested review of this revision.
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.

This patch should address an issue that caused the process public run
lock to not be updated during a process launch/attach when the process
stops.

That caused the public run lock to report its state as running while the
process state is stopped. This prevents the users to interact with the
process (through the command line or via the SBAPI) since it's
considered still running.

To address that, this patch refactors the name of the internal hijack
listeners to a specific pattern `lldb.internal.<action>.hijack` that
are used to ensure that we've attached to or launched a process successfully.

Then, when updating the process public state, after updating the state
value, if the process is not hijacked externally, meaning if the process
doens't have a hijack listener that matches the internal hijack
listeners pattern, we can update the public run lock accordingly.

Signed-off-by: Med Ismail Bennani <medismail.benn...@gmail.com>


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D148400

Files:
  lldb/include/lldb/Target/Process.h
  lldb/source/Target/Process.cpp
  lldb/source/Target/Target.cpp

Index: lldb/source/Target/Target.cpp
===================================================================
--- lldb/source/Target/Target.cpp
+++ lldb/source/Target/Target.cpp
@@ -3157,8 +3157,8 @@
   // its own hijacking listener or if the process is created by the target
   // manually, without the platform).
   if (!launch_info.GetHijackListener())
-    launch_info.SetHijackListener(
-        Listener::MakeListener("lldb.Target.Launch.hijack"));
+    launch_info.SetHijackListener(Listener::MakeListener(
+        Process::GetLaunchSynchronousHijackListenerName().data()));
 
   // If we're not already connected to the process, and if we have a platform
   // that can launch a process for debugging, go ahead and do that here.
@@ -3336,8 +3336,8 @@
   ListenerSP hijack_listener_sp;
   const bool async = attach_info.GetAsync();
   if (!async) {
-    hijack_listener_sp =
-        Listener::MakeListener("lldb.Target.Attach.attach.hijack");
+    hijack_listener_sp = Listener::MakeListener(
+        Process::GetAttachSynchronousHijackListenerName().data());
     attach_info.SetHijackListener(hijack_listener_sp);
   }
 
Index: lldb/source/Target/Process.cpp
===================================================================
--- lldb/source/Target/Process.cpp
+++ lldb/source/Target/Process.cpp
@@ -401,6 +401,24 @@
   return class_name;
 }
 
+llvm::StringRef Process::GetAttachSynchronousHijackListenerName() {
+  static ConstString class_name(
+      "lldb.internal.Process.AttachSynchronous.hijack");
+  return class_name.GetCString();
+}
+
+llvm::StringRef Process::GetLaunchSynchronousHijackListenerName() {
+  static ConstString class_name(
+      "lldb.internal.Process.LaunchSynchronous.hijack");
+  return class_name.GetCString();
+}
+
+llvm::StringRef Process::GetResumeSynchronousHijackListenerName() {
+  static ConstString class_name(
+      "lldb.internal.Process.ResumeSynchronous.hijack");
+  return class_name.GetCString();
+}
+
 Process::Process(lldb::TargetSP target_sp, ListenerSP listener_sp)
     : Process(target_sp, listener_sp, UnixSignals::CreateForHost()) {
   // This constructor just delegates to the full Process constructor,
@@ -1368,8 +1386,6 @@
   return error;
 }
 
-static const char *g_resume_sync_name = "lldb.Process.ResumeSynchronous.hijack";
-
 Status Process::ResumeSynchronous(Stream *stream) {
   Log *log(GetLog(LLDBLog::State | LLDBLog::Process));
   LLDB_LOGF(log, "Process::ResumeSynchronous -- locking run lock");
@@ -1380,7 +1396,7 @@
   }
 
   ListenerSP listener_sp(
-      Listener::MakeListener(g_resume_sync_name));
+      Listener::MakeListener(GetResumeSynchronousHijackListenerName().data()));
   HijackProcessEvents(listener_sp);
 
   Status error = PrivateResume();
@@ -1408,7 +1424,7 @@
   if (IsHijackedForEvent(eBroadcastBitStateChanged)) {
     const char *hijacking_name = GetHijackingListenerName();
     if (hijacking_name &&
-        strcmp(hijacking_name, g_resume_sync_name))
+        strstr(hijacking_name, "lldb.internal") != hijacking_name)
       return true;
   }
   return false;
@@ -1418,7 +1434,8 @@
   if (IsHijackedForEvent(eBroadcastBitStateChanged)) {
     const char *hijacking_name = GetHijackingListenerName();
     if (hijacking_name &&
-        strcmp(hijacking_name, g_resume_sync_name) == 0)
+        strcmp(hijacking_name,
+               GetResumeSynchronousHijackListenerName().data()) == 0)
       return true;
   }
   return false;
Index: lldb/include/lldb/Target/Process.h
===================================================================
--- lldb/include/lldb/Target/Process.h
+++ lldb/include/lldb/Target/Process.h
@@ -369,6 +369,10 @@
 
   static ConstString &GetStaticBroadcasterClass();
 
+  static llvm::StringRef GetAttachSynchronousHijackListenerName();
+  static llvm::StringRef GetLaunchSynchronousHijackListenerName();
+  static llvm::StringRef GetResumeSynchronousHijackListenerName();
+
   ConstString &GetBroadcasterClass() const override {
     return GetStaticBroadcasterClass();
   }
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to