Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Kamil Rytarowski <n54@gmx.com>
To: gdb-patches@sourceware.org, jhb@FreeBSD.org, tom@tromey.com
Subject: [PATCH v2 1/2] gdb: Implement native dumpcore function
Date: Tue, 28 Jul 2020 17:46:01 +0200	[thread overview]
Message-ID: <20200728154602.3824-1-n54@gmx.com> (raw)
In-Reply-To: <20200727144338.7033-1-n54@gmx.com>

Add new API for systems with native kernel support for dumping
a process on demand. Wire it into the gdb's gcore functionality.

gdb/ChangeLog:

       * target.h (supports_native_dumpcore, native_dumpcore): New
       function declarations.
       * target.c (supports_native_dumpcore, native_dumpcore): New
       functions.
       * target-delegates.c: Rebuild.
       * gcore.c (gcore_command): Use target_supports_native_dumpcore ()
       and target_native_dumpcore ().
---
 gdb/ChangeLog          | 10 ++++++++
 gdb/gcore.c            | 21 ++++++++++------
 gdb/target-delegates.c | 55 ++++++++++++++++++++++++++++++++++++++++++
 gdb/target.h           | 18 ++++++++++++++
 4 files changed, 96 insertions(+), 8 deletions(-)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index defca83c263..118bb4f89a2 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,13 @@
+2020-07-28  Kamil Rytarowski  <n54@gmx.com>
+
+	* target.h (supports_native_dumpcore, native_dumpcore): New
+	function declarations.
+	* target.c (supports_native_dumpcore, native_dumpcore): New
+	functions.
+	* target-delegates.c: Rebuild.
+	* gcore.c (gcore_command): Use target_supports_native_dumpcore ()
+	and target_native_dumpcore ().
+
 2020-07-28  H.J. Lu  <hongjiu.lu@intel.com>

 	PR binutils/26301
diff --git a/gdb/gcore.c b/gdb/gcore.c
index 7b653fb74e3..d0e36b1a708 100644
--- a/gdb/gcore.c
+++ b/gdb/gcore.c
@@ -145,17 +145,22 @@ gcore_command (const char *args, int from_tty)
 		      "Opening corefile '%s' for output.\n",
 		      corefilename.get ());

-  /* Open the output file.  */
-  gdb_bfd_ref_ptr obfd (create_gcore_bfd (corefilename.get ()));
+  if (target_supports_dumpcore ())
+    target_dumpcore (corefilename.get ());
+  else
+    {
+      /* Open the output file.  */
+      gdb_bfd_ref_ptr obfd (create_gcore_bfd (corefilename.get ()));

-  /* Arrange to unlink the file on failure.  */
-  gdb::unlinker unlink_file (corefilename.get ());
+      /* Arrange to unlink the file on failure.  */
+      gdb::unlinker unlink_file (corefilename.get ());

-  /* Call worker function.  */
-  write_gcore_file (obfd.get ());
+      /* Call worker function.  */
+      write_gcore_file (obfd.get ());

-  /* Succeeded.  */
-  unlink_file.keep ();
+      /* Succeeded.  */
+      unlink_file.keep ();
+    }

   fprintf_filtered (gdb_stdout, "Saved corefile %s\n", corefilename.get ());
 }
diff --git a/gdb/target-delegates.c b/gdb/target-delegates.c
index c28af097183..c7e0811caf2 100644
--- a/gdb/target-delegates.c
+++ b/gdb/target-delegates.c
@@ -108,6 +108,8 @@ struct dummy_target : public target_ops
   bool supports_disable_randomization () override;
   bool supports_string_tracing () override;
   bool supports_evaluation_of_breakpoint_conditions () override;
+  bool supports_dumpcore () override;
+  bool dumpcore (const char *arg0) override;
   bool can_run_breakpoint_commands () override;
   struct gdbarch *thread_architecture (ptid_t arg0) override;
   struct address_space *thread_address_space (ptid_t arg0) override;
@@ -277,6 +279,8 @@ struct debug_target : public target_ops
   bool supports_disable_randomization () override;
   bool supports_string_tracing () override;
   bool supports_evaluation_of_breakpoint_conditions () override;
+  bool supports_dumpcore () override;
+  bool dumpcore (const char *arg0) override;
   bool can_run_breakpoint_commands () override;
   struct gdbarch *thread_architecture (ptid_t arg0) override;
   struct address_space *thread_address_space (ptid_t arg0) override;
@@ -2825,6 +2829,57 @@ debug_target::supports_evaluation_of_breakpoint_conditions ()
   return result;
 }

+bool
+target_ops::supports_dumpcore ()
+{
+  return this->beneath ()->supports_dumpcore ();
+}
+
+bool
+dummy_target::supports_dumpcore ()
+{
+  return false;
+}
+
+bool
+debug_target::supports_dumpcore ()
+{
+  bool result;
+  fprintf_unfiltered (gdb_stdlog, "-> %s->supports_dumpcore (...)\n", this->beneath ()->shortname ());
+  result = this->beneath ()->supports_dumpcore ();
+  fprintf_unfiltered (gdb_stdlog, "<- %s->supports_dumpcore (", this->beneath ()->shortname ());
+  fputs_unfiltered (") = ", gdb_stdlog);
+  target_debug_print_bool (result);
+  fputs_unfiltered ("\n", gdb_stdlog);
+  return result;
+}
+
+bool
+target_ops::dumpcore (const char *arg0)
+{
+  return this->beneath ()->dumpcore (arg0);
+}
+
+bool
+dummy_target::dumpcore (const char *arg0)
+{
+  return false;
+}
+
+bool
+debug_target::dumpcore (const char *arg0)
+{
+  bool result;
+  fprintf_unfiltered (gdb_stdlog, "-> %s->dumpcore (...)\n", this->beneath ()->shortname ());
+  result = this->beneath ()->dumpcore (arg0);
+  fprintf_unfiltered (gdb_stdlog, "<- %s->dumpcore (", this->beneath ()->shortname ());
+  target_debug_print_const_char_p (arg0);
+  fputs_unfiltered (") = ", gdb_stdlog);
+  target_debug_print_bool (result);
+  fputs_unfiltered ("\n", gdb_stdlog);
+  return result;
+}
+
 bool
 target_ops::can_run_breakpoint_commands ()
 {
diff --git a/gdb/target.h b/gdb/target.h
index 4e8d4cccd5c..85a03ed5be8 100644
--- a/gdb/target.h
+++ b/gdb/target.h
@@ -881,6 +881,14 @@ struct target_ops
     virtual bool supports_evaluation_of_breakpoint_conditions ()
       TARGET_DEFAULT_RETURN (false);

+    /* Does this target support native dumpcore API?  */
+    virtual bool supports_dumpcore ()
+      TARGET_DEFAULT_RETURN (false);
+
+    /* Generate the core file with native target API.  */
+    virtual bool dumpcore (const char *filename)
+      TARGET_DEFAULT_RETURN (false);
+
     /* Does this target support evaluation of breakpoint commands on its
        end?  */
     virtual bool can_run_breakpoint_commands ()
@@ -1499,6 +1507,16 @@ int target_supports_disable_randomization (void);
 #define target_supports_evaluation_of_breakpoint_conditions() \
   (current_top_target ()->supports_evaluation_of_breakpoint_conditions) ()

+/* Does this target support dumpcore API?  */
+
+#define target_supports_dumpcore() \
+  (current_top_target ()->supports_dumpcore) ()
+
+/* Generate the core file with target API.  */
+
+#define target_dumpcore(x) \
+  (current_top_target ()->dumpcore (x))
+
 /* Returns true if this target can handle breakpoint commands
    on its end.  */

--
2.26.2



  parent reply	other threads:[~2020-07-28 15:47 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-27 14:43 [PATCH] " Kamil Rytarowski
2020-07-27 15:47 ` John Baldwin
2020-07-27 21:09 ` Tom Tromey
2020-07-28 15:46 ` Kamil Rytarowski [this message]
2020-07-28 15:46   ` [PATCH v2 2/2] gdb: Implement native dumpcore function for NetBSD Kamil Rytarowski
2020-08-05 16:24     ` Tom Tromey
2020-08-13 17:16       ` Kamil Rytarowski
2020-07-28 18:56   ` [PATCH v2 1/2] gdb: Implement native dumpcore function Christian Biesinger
2020-07-28 20:39     ` Kamil Rytarowski
2020-07-29 15:45       ` Tom Tromey
2020-08-05 16:23   ` Tom Tromey
2020-08-13 17:15     ` Kamil Rytarowski

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=20200728154602.3824-1-n54@gmx.com \
    --to=n54@gmx.com \
    --cc=gdb-patches@sourceware.org \
    --cc=jhb@FreeBSD.org \
    --cc=tom@tromey.com \
    /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