public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Tom de Vries <tdevries@suse.de>
To: gdb-patches@sourceware.org
Subject: [PATCH v3 2/3] [gdb] Eliminate local var pspace in inferior.c
Date: Thu,  9 Nov 2023 16:00:20 +0100	[thread overview]
Message-ID: <20231109150021.5504-3-tdevries@suse.de> (raw)
In-Reply-To: <20231109150021.5504-1-tdevries@suse.de>

Eliminate local var pspace from functions add_inferior_with_spaces and
clone_inferior_command.

This interchanges the order of the new program space / new inferior events.

Update test-case gdb.python/py-progspace-events.exp to reflect that.

Tested on top of trunk on x86_64-linux and ppc64le-linux.
Tested on top of gdb-14-branch on ppc64-linux.

Suggested-By: Simon Marchi <simon.marchi@polymtl.ca>
---
 gdb/inferior.c                                | 20 +++++++------------
 .../gdb.python/py-progspace-events.exp        |  4 ++--
 2 files changed, 9 insertions(+), 15 deletions(-)

diff --git a/gdb/inferior.c b/gdb/inferior.c
index 37b4fad6e44..e0c5567579f 100644
--- a/gdb/inferior.c
+++ b/gdb/inferior.c
@@ -843,16 +843,13 @@ remove_inferior_command (const char *args, int from_tty)
 struct inferior *
 add_inferior_with_spaces (void)
 {
-  struct program_space *pspace;
-  struct inferior *inf;
+  struct inferior *inf = add_inferior (0);
 
   /* If all inferiors share an address space on this system, this
      doesn't really return a new address space; otherwise, it
      really does.  */
-  pspace = new program_space (maybe_new_address_space ());
-  inf = add_inferior (0);
-  inf->pspace = pspace;
-  inf->aspace = pspace->aspace;
+  inf->pspace = new program_space (maybe_new_address_space ());
+  inf->aspace = inf->pspace->aspace;
 
   /* Setup the inferior's initial arch, based on information obtained
      from the global "set ..." options.  */
@@ -1012,16 +1009,13 @@ clone_inferior_command (const char *args, int from_tty)
 
   for (i = 0; i < copies; ++i)
     {
-      struct program_space *pspace;
-      struct inferior *inf;
+      struct inferior *inf = add_inferior (0);
 
       /* If all inferiors share an address space on this system, this
 	 doesn't really return a new address space; otherwise, it
 	 really does.  */
-      pspace = new program_space (maybe_new_address_space ());
-      inf = add_inferior (0);
-      inf->pspace = pspace;
-      inf->aspace = pspace->aspace;
+      inf->pspace = new program_space (maybe_new_address_space ());
+      inf->aspace = inf->pspace->aspace;
       inf->set_arch (orginf->arch ());
 
       switch_to_inferior_and_push_target (inf, no_connection, orginf);
@@ -1031,7 +1025,7 @@ clone_inferior_command (const char *args, int from_tty)
       if (inf->tdesc_info.from_user_p ())
 	inf->tdesc_info = orginf->tdesc_info;
 
-      clone_program_space (pspace, orginf->pspace);
+      clone_program_space (inf->pspace, orginf->pspace);
 
       /* Copy properties from the original inferior to the new one.  */
       inf->set_args (orginf->args ());
diff --git a/gdb/testsuite/gdb.python/py-progspace-events.exp b/gdb/testsuite/gdb.python/py-progspace-events.exp
index 60ae290c0b2..fb3e3e86899 100644
--- a/gdb/testsuite/gdb.python/py-progspace-events.exp
+++ b/gdb/testsuite/gdb.python/py-progspace-events.exp
@@ -118,8 +118,8 @@ gdb_continue_to_end
 # manually added and removed.
 gdb_test "add-inferior" \
     [multi_line \
-	 "^NewProgspaceEvent: <gdb.Progspace object at $hex>" \
-	 "\\\[New inferior 3\\\]" \
+	 "^\\\[New inferior 3\\\]" \
+	 "NewProgspaceEvent: <gdb.Progspace object at $hex>" \
 	 "Added inferior 3\[^\r\n\]*"]
 gdb_test "remove-inferior 3" \
     "^FreeProgspaceEvent: <gdb.Progspace object at $hex>"
-- 
2.35.3


  parent reply	other threads:[~2023-11-09 14:59 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-09 15:00 [PATCH v3 0/3] [gdb] Fix segfault in for_each_block Tom de Vries
2023-11-09 15:00 ` [PATCH v3 1/3] [gdb] Fix segfault in for_each_block, part 1 Tom de Vries
2023-11-09 18:19   ` Simon Marchi
2023-11-10  8:14     ` Tom de Vries
2023-11-09 15:00 ` Tom de Vries [this message]
2023-11-09 16:31   ` [PATCH v3 2/3] [gdb] Eliminate local var pspace in inferior.c Simon Marchi
2023-11-10  8:15     ` Tom de Vries
2023-11-09 15:00 ` [PATCH v3 3/3] [gdb] Fix segfault in for_each_block, part 2 Tom de Vries

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=20231109150021.5504-3-tdevries@suse.de \
    --to=tdevries@suse.de \
    --cc=gdb-patches@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).