public inbox for gdb-prs@sourceware.org
help / color / mirror / Atom feed
From: "simark at simark dot ca" <sourceware-bugzilla@sourceware.org>
To: gdb-prs@sourceware.org
Subject: [Bug gdb/28275] commit_resumed_state assertion failure when killing running inferior and running again
Date: Fri, 29 Oct 2021 12:54:15 +0000	[thread overview]
Message-ID: <bug-28275-4717-HCQXvbIQVr@http.sourceware.org/bugzilla/> (raw)
In-Reply-To: <bug-28275-4717@http.sourceware.org/bugzilla/>

https://sourceware.org/bugzilla/show_bug.cgi?id=28275

--- Comment #3 from Simon Marchi <simark at simark dot ca> ---
Something like this should fix the original issue (when re-running):

>From 0bc259c5c7640fb9bb655b7b279eb0b2ec87c28b Mon Sep 17 00:00:00 2001
From: Simon Marchi <simon.marchi@polymtl.ca>
Date: Fri, 29 Oct 2021 08:36:00 -0400
Subject: [PATCH] gdb: fix commit resumed failed assertion when re-running

Change-Id: Ic7ed0524751d0e5524936b2890048cd4a3d92765
---
 gdb/infcmd.c |  4 ++--
 gdb/target.c | 46 +++++++++++++++++++++-------------------------
 gdb/target.h |  8 ++++----
 3 files changed, 27 insertions(+), 31 deletions(-)

diff --git a/gdb/infcmd.c b/gdb/infcmd.c
index 302db421a21f..57726650f155 100644
--- a/gdb/infcmd.c
+++ b/gdb/infcmd.c
@@ -371,7 +371,6 @@ run_command_1 (const char *args, int from_tty, enum run_how
run_how)
 {
   const char *exec_file;
   struct ui_out *uiout = current_uiout;
-  struct target_ops *run_target;
   int async_exec;

   dont_repeat ();
@@ -403,7 +402,7 @@ run_command_1 (const char *args, int from_tty, enum run_how
run_how)
   /* Do validation and preparation before possibly changing anything
      in the inferior.  */

-  run_target = find_run_target ();
+  process_stratum_target *run_target = find_run_target ();

   prepare_execution_command (run_target, async_exec);

@@ -445,6 +444,7 @@ run_command_1 (const char *args, int from_tty, enum run_how
run_how)
       uiout->flush ();
     }

+  run_target->commit_resumed_state = false;
   run_target->create_inferior (exec_file,
                               current_inferior ()->args (),
                               current_inferior ()->environment.envp (),
diff --git a/gdb/target.c b/gdb/target.c
index 6cff56474873..967551a6ad8e 100644
--- a/gdb/target.c
+++ b/gdb/target.c
@@ -84,7 +84,7 @@ static int default_verify_memory (struct target_ops *self,

 static void tcomplain (void) ATTRIBUTE_NORETURN;

-static struct target_ops *find_default_run_target (const char *);
+static process_stratum_target *find_default_run_target (const char *);

 static int dummy_find_memory_regions (struct target_ops *self,
                                      find_memory_region_ftype ignore1,
@@ -2880,12 +2880,12 @@ show_auto_connect_native_target (struct ui_file *file,
int from_tty,
 /* A pointer to the target that can respond to "run" or "attach".
    Native targets are always singletons and instantiated early at GDB
    startup.  */
-static target_ops *the_native_target;
+static process_stratum_target *the_native_target;

 /* See target.h.  */

 void
-set_native_target (target_ops *target)
+set_native_target (process_stratum_target *target)
 {
   if (the_native_target != NULL)
     internal_error (__FILE__, __LINE__,
@@ -2897,7 +2897,7 @@ set_native_target (target_ops *target)

 /* See target.h.  */

-target_ops *
+process_stratum_target *
 get_native_target ()
 {
   return the_native_target;
@@ -2910,7 +2910,7 @@ get_native_target ()
    If DO_MESG is not NULL, the result is always valid (error() is
    called for errors); else, return NULL on error.  */

-static struct target_ops *
+static process_stratum_target *
 find_default_run_target (const char *do_mesg)
 {
   if (auto_connect_native_target && the_native_target != NULL)
@@ -2923,17 +2923,15 @@ find_default_run_target (const char *do_mesg)

 /* See target.h.  */

-struct target_ops *
-find_attach_target (void)
+process_stratum_target *
+find_attach_target ()
 {
-  /* If a target on the current stack can attach, use it.  */
-  for (target_ops *t = current_inferior ()->top_target ();
-       t != NULL;
-       t = t->beneath ())
-    {
-      if (t->can_attach ())
-       return t;
-    }
+  /* If the current process stratum target can attach, use it.  */
+  process_stratum_target *current_proc_target
+    = current_inferior ()->process_target ();
+  if (current_proc_target != nullptr
+      && current_proc_target->can_attach ())
+    return current_proc_target;

   /* Otherwise, use the default run target for attaching.  */
   return find_default_run_target ("attach");
@@ -2941,17 +2939,15 @@ find_attach_target (void)

 /* See target.h.  */

-struct target_ops *
-find_run_target (void)
+process_stratum_target *
+find_run_target ()
 {
-  /* If a target on the current stack can run, use it.  */
-  for (target_ops *t = current_inferior ()->top_target ();
-       t != NULL;
-       t = t->beneath ())
-    {
-      if (t->can_create_inferior ())
-       return t;
-    }
+  /* If the current process stratum target can run, use it.  */
+  process_stratum_target *current_proc_target
+    = current_inferior ()->process_target ();
+  if (current_proc_target != nullptr
+      && current_proc_target->can_run ())
+    return current_proc_target;

   /* Otherwise, use the default run target.  */
   return find_default_run_target ("run");
diff --git a/gdb/target.h b/gdb/target.h
index 92fc1381db2b..5750a7655670 100644
--- a/gdb/target.h
+++ b/gdb/target.h
@@ -1364,11 +1364,11 @@ typedef gdb::ref_ptr<target_ops, target_ops_ref_policy>
target_ops_ref;
 /* Native target backends call this once at initialization time to
    inform the core about which is the target that can respond to "run"
    or "attach".  Note: native targets are always singletons.  */
-extern void set_native_target (target_ops *target);
+extern void set_native_target (process_stratum_target *target);

 /* Get the registered native target, if there's one.  Otherwise return
    NULL.  */
-extern target_ops *get_native_target ();
+extern process_stratum_target *get_native_target ();

 /* Type that manages a target stack.  See description of target stacks
    and strata at the top of the file.  */
@@ -1430,13 +1430,13 @@ void target_close (struct target_ops *targ);
    current stack supports attaching, then it is returned.  Otherwise,
    the default run target is returned.  */

-extern struct target_ops *find_attach_target (void);
+extern process_stratum_target *find_attach_target (void);

 /* Find the correct target to use for "run".  If a target on the
    current stack supports creating a new inferior, then it is
    returned.  Otherwise, the default run target is returned.  */

-extern struct target_ops *find_run_target (void);
+extern process_stratum_target *find_run_target ();

 /* Some targets don't generate traps when attaching to the inferior,
    or their target_attach implementation takes care of the waiting.
-- 
2.33.1

-- 
You are receiving this mail because:
You are on the CC list for the bug.

  parent reply	other threads:[~2021-10-29 12:54 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-26 14:35 [Bug gdb/28275] New: " simark at simark dot ca
2021-08-26 19:39 ` [Bug gdb/28275] " andrew.burgess at embecosm dot com
2021-10-29  9:22 ` nyanpasu64 at tuta dot io
2021-10-29 12:54 ` simark at simark dot ca [this message]
2022-11-14 15:02 ` vries at gcc dot gnu.org
2022-11-14 15:29 ` simark at simark dot ca
2022-11-14 16:32 ` vries at gcc dot gnu.org
2022-11-15  7:34 ` vries at gcc dot gnu.org
2022-11-15 11:20 ` vries at gcc dot gnu.org
2022-11-15 12:55 ` vries at gcc dot gnu.org
2022-11-16 15:36 ` aburgess at redhat dot com
2022-11-22 15:29 ` brobecker at gnat dot com
2022-11-28 13:03 ` cvs-commit at gcc dot gnu.org
2022-11-28 14:13 ` cvs-commit at gcc dot gnu.org
2022-11-28 14:14 ` simark at simark dot ca
2022-12-01 15:07 ` cvs-commit at gcc dot gnu.org
2022-12-01 15:07 ` cvs-commit at gcc dot gnu.org
2023-01-04  9:15 ` vries at gcc dot gnu.org
2023-01-04  9:57 ` brobecker at gnat dot com

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-28275-4717-HCQXvbIQVr@http.sourceware.org/bugzilla/ \
    --to=sourceware-bugzilla@sourceware.org \
    --cc=gdb-prs@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).