Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Pedro Alves <palves@redhat.com>
To: gdb-patches@sourceware.org
Subject: [PATCH 2/3] Eliminate the 'the_core_target' global
Date: Thu, 03 May 2018 16:22:00 -0000	[thread overview]
Message-ID: <20180503162234.15371-3-palves@redhat.com> (raw)
In-Reply-To: <20180503162234.15371-1-palves@redhat.com>

(previously called 'core_target', but since renamed because
'core_target' is the name of the target_ops class now.)

This eliminates the "the_core_target" global, as preparation for being
able to have more than one core loaded.  When we get there, we will
instantiate one core_target object per core instead.

Essentially, this replaces the reference to the_core_target in
core_file_command by a reference to core_bfd, which is per
program_space.

Currently, core_file_command calls 'the_core_target->detach()' even if
the core target is not open and pushed on the target stack.  If it is
indeed not open, then the practical effect is that
core_target::detach() prints "No core file now.".  That is preserved
by printing that directly from within core_file_command if not
debugging a core.

gdb/ChangeLog:
yyyy-mm-dd  Pedro Alves  <palves@redhat.com>

	* corefile.c (core_file_command): Move to corelow.c.
	* corelow.c (the_core_target): Delete.
	(core_file_command): Moved from corefile.c.  Check exec_bfd
	instead of the_core_target.  Use target_detach instead of calling
	into the_core_target directly.
	(maybe_say_no_core_file_now): New.
	(core_target::detach): Use it.
	(_initialize_corelow): Remove references to the_core_target.
	* gdbcore.h (the_core_target): Delete.
---
 gdb/corefile.c | 18 ------------------
 gdb/corelow.c  | 42 +++++++++++++++++++++++++++++++-----------
 gdb/gdbcore.h  |  4 ----
 3 files changed, 31 insertions(+), 33 deletions(-)

diff --git a/gdb/corefile.c b/gdb/corefile.c
index e0c7540140..06b26863f3 100644
--- a/gdb/corefile.c
+++ b/gdb/corefile.c
@@ -51,24 +51,6 @@ static int exec_file_hook_count = 0;		/* Size of array.  */
 
 \f
 
-/* Backward compatability with old way of specifying core files.  */
-
-void
-core_file_command (const char *filename, int from_tty)
-{
-  dont_repeat ();		/* Either way, seems bogus.  */
-
-  if (!filename)
-    {
-      gdb_assert (the_core_target != NULL);
-
-      the_core_target->detach (current_inferior (), from_tty);
-    }
-  else
-    core_target_open (filename, from_tty);
-}
-\f
-
 /* If there are two or more functions that wish to hook into
    exec_file_command, this function will call all of the hook
    functions.  */
diff --git a/gdb/corelow.c b/gdb/corelow.c
index 97a957c8fc..3b71a1b856 100644
--- a/gdb/corelow.c
+++ b/gdb/corelow.c
@@ -92,9 +92,6 @@ public:
   bool info_proc (const char *, enum info_proc_what) override;
 };
 
-/* See gdbcore.h.  */
-struct target_ops *the_core_target;
-
 /* List of all available core_fns.  On gdb startup, each core file
    register reader calls deprecated_add_core_fns() to register
    information on each core format it is prepared to read.  */
@@ -309,6 +306,36 @@ add_to_thread_list (bfd *abfd, asection *asect, void *reg_sect_arg)
     inferior_ptid = ptid;			/* Yes, make it current.  */
 }
 
+/* Issue a message saying we have no core to debug, if FROM_TTY.  */
+
+static void
+maybe_say_no_core_file_now (int from_tty)
+{
+  if (from_tty)
+    printf_filtered (_("No core file now.\n"));
+}
+
+/* Backward compatability with old way of specifying core files.  */
+
+void
+core_file_command (const char *filename, int from_tty)
+{
+  dont_repeat ();		/* Either way, seems bogus.  */
+
+  if (filename == NULL)
+    {
+      if (core_bfd != NULL)
+	{
+	  target_detach (current_inferior (), from_tty);
+	  gdb_assert (core_bfd == NULL);
+	}
+      else
+	maybe_say_no_core_file_now (from_tty);
+    }
+  else
+    core_target_open (filename, from_tty);
+}
+
 /* See gdbcore.h.  */
 
 void
@@ -513,8 +540,7 @@ core_target::detach (inferior *inf, int from_tty)
 {
   unpush_target (this);
   reinit_frame_cache ();
-  if (from_tty)
-    printf_filtered (_("No core file now.\n"));
+  maybe_say_no_core_file_now (from_tty);
 }
 
 /* Try to retrieve registers from a section in core_bfd, and supply
@@ -1021,11 +1047,5 @@ core_target::info_proc (const char *args, enum info_proc_what request)
 void
 _initialize_corelow (void)
 {
-  if (the_core_target != NULL)
-    internal_error (__FILE__, __LINE__,
-		    _("core target already exists (\"%s\")."),
-		    the_core_target->longname ());
-  the_core_target = &core_ops;
-
   add_target (core_target_info, core_target_open, filename_completer);
 }
diff --git a/gdb/gdbcore.h b/gdb/gdbcore.h
index d06ccc3507..04a4b4767a 100644
--- a/gdb/gdbcore.h
+++ b/gdb/gdbcore.h
@@ -135,10 +135,6 @@ extern void specify_exec_file_hook (void (*hook) (const char *filename));
 
 #define core_bfd (current_program_space->cbfd)
 
-/* corelow.c target.  It is never NULL after GDB initialization.  */
-
-extern struct target_ops *the_core_target;
-
 /* Whether to open exec and core files read-only or read-write.  */
 
 extern int write_files;
-- 
2.14.3


  reply	other threads:[~2018-05-03 16:22 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-05-03 16:22 [PATCH 0/3] Torward multiple simultaneous core instances Pedro Alves
2018-05-03 16:22 ` Pedro Alves [this message]
2018-05-04 15:59   ` [PATCH 2/3] Eliminate the 'the_core_target' global Tom Tromey
2018-05-03 16:22 ` [PATCH 3/3] Heap-allocate core_target instances Pedro Alves
2018-05-04 16:36   ` Tom Tromey
2018-05-06 15:38     ` Pedro Alves
2018-05-07 14:26       ` Tom Tromey
2018-05-11 19:40         ` Pedro Alves
2018-05-03 16:22 ` [PATCH 1/3] Move core_bfd to program space Pedro Alves
2018-05-04 15:41   ` Tom Tromey
2018-05-04 16:09     ` Pedro Alves
2018-05-04 16:46       ` Tom Tromey

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=20180503162234.15371-3-palves@redhat.com \
    --to=palves@redhat.com \
    --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