[PATCH v4 21/44] gdb: allow creating and attaching to inferiors without threads

Markus Metzger <[email protected]>
Newsgroups gmane.comp.gdb.patches
Message-ID <[email protected]>
An Intel GPU device is modeled as an inferior and GPU software threads are
modeled as threads.  Software threads represent the work that has been
dispatched to a GPU device.  When a thread completes its work, it exits.
When new work is dispatched to a GPU device, new software threads are
created.

In such a model, when no work is currently dispatched to a GPU device, we
are left with the GPU inferior representing the GPU device but no threads.
---
 gdb/infcmd.c | 46 +++++++++++++++++++++++++++++++++++-----------
 1 file changed, 35 insertions(+), 11 deletions(-)

diff --git a/gdb/infcmd.c b/gdb/infcmd.c
index 3e943123519..c2a860cb288 100644
--- a/gdb/infcmd.c
+++ b/gdb/infcmd.c
@@ -58,6 +58,7 @@
 #include "cli/cli-style.h"
 #include "gdbsupport/selftest.h"
 #include "finish-thread-state.h"
+#include "event-top.h"
 
 /* Local functions: */
 
@@ -383,18 +384,21 @@ post_create_inferior (int from_tty, bool set_pspace_solib_ops)
   /* Now that we know the register layout, retrieve current PC.  But
      if the PC is unavailable (e.g., we're opening a core file with
      missing registers info), ignore it.  */
-  thread_info *thr = inferior_thread ();
-
-  thr->clear_stop_pc ();
-  try
-    {
-      regcache *rc = get_thread_regcache (thr);
-      thr->set_stop_pc (regcache_read_pc (rc));
-    }
-  catch (const gdb_exception_error &ex)
+  if (inferior_ptid != null_ptid)
     {
-      if (ex.error != NOT_AVAILABLE_ERROR)
-	throw;
+      thread_info *thr = inferior_thread ();
+
+      thr->clear_stop_pc ();
+      try
+	{
+	  regcache *rc = get_thread_regcache (thr);
+	  thr->set_stop_pc (regcache_read_pc (rc));
+	}
+      catch (const gdb_exception_error &ex)
+	{
+	  if (ex.error != NOT_AVAILABLE_ERROR)
+	    throw;
+	}
     }
 
   if (set_pspace_solib_ops)
@@ -2905,6 +2909,26 @@ attach_command (const char *args, int from_tty)
        finished.  */
   target_terminal::inferior ();
 
+  /* If the attach does not create a thread, there's nothing to stop.
+
+     Also leave setting up any inferior it created to the target.  */
+  if (inferior_ptid == null_ptid)
+    {
+      target_terminal::ours_for_output ();
+
+      /* We disabled stdin in prepare_execution_command ().  There won't
+	 be any normal_stop () to enable them again.  Do so now.  */
+      if (async_exec == 0)
+	{
+	  SWITCH_THRU_ALL_UIS ()
+	    {
+	      async_enable_stdin ();
+	    }
+	}
+
+      return;
+    }
+
   inferior->needs_setup = true;
 
   if (target_is_non_stop_p ())
-- 
2.43.0

________________________________________
Intel Deutschland GmbH 

Registered Address: Dornacher Strasse 1, 85622 Feldkirchen, Germany 

Tel: +49 (89) 99143-0 

www.intel.de 

Managing Directors: Candice Moore, Jeffrey Schneiderman, Ramachandran Sitaraman

Chairperson of the Supervisory Board: Sonja Pierer

Registered Seat: Munich Commercial Register B: Amtsgericht Munich HRB 186928

This e-mail and any attachments may contain confidential material for
the sole use of the intended recipient(s). Any review or distribution
by others is strictly prohibited. If you are not the intended
recipient, please contact the sender and delete all copies.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.