From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mout.gmx.net (mout.gmx.net [212.227.17.20]) by sourceware.org (Postfix) with ESMTPS id 4BA773857C65 for ; Mon, 27 Jul 2020 14:44:21 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 4BA773857C65 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gmx.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=n54@gmx.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1595861058; bh=muY9lTkk0ZlZ9pP9WNyhti2l7/Bxdhph8l9CrRnZgXo=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date; b=GVC9gfMnVkc3GpVywucgv/AOvl8gjfHl7gc8twg4twwo/vTWiJV5AIBmE27UzQXSf FJOPz2rSROd0AfMqKbCToHlZ54g50s+RT3XfpEWLKWG7LDzD2EFAQHsQ/YAWPHkEmM nMnILZZoAre1aYt8I5uwVGdmMnwkwjrFvvFy+HbI= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from localhost.localdomain ([89.79.191.25]) by mail.gmx.com (mrgmx104 [212.227.17.174]) with ESMTPSA (Nemesis) id 1Ml6m4-1keais18lo-00lUti; Mon, 27 Jul 2020 16:44:18 +0200 From: Kamil Rytarowski To: gdb-patches@sourceware.org Subject: [PATCH] gdb: Implement native dumpcore function Date: Mon, 27 Jul 2020 16:43:38 +0200 Message-Id: <20200727144338.7033-1-n54@gmx.com> X-Mailer: git-send-email 2.26.2 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Provags-ID: V03:K1:K03Ey0agXlVLTDJQRl6zmy3Tk3MPTu/3gWXRl16iw9zbG7lx+9G A1IWNIBnaStGSqNbqgJqIaGGn3lPpkSyiOqzAegiVA7VPnBvjPWtbLrTMBwaEaKndzf0m3q fmZ3ptZAGcnWq625uD3JhhJjWmzlkAqZKHK0shLpj2z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+yavzMo1rgEqd3iAhRjnq3ycLVtciCpMRdLhlWpfcA3b01fHtH/S21jmI/drG yAzrnzbmbXH7qB0JUEBStXVfFu3ISe0u+bTAOzBipkHyM960PWo4swmAuQHcs5EOqNwhRaCn/ wCCMzbcFyB/rKAVKd73irr/JN564AJvs6Bd75EOmjmPU/WTrbKRLTo1rKbjxnUumvA9HSeTwB t3YuaqJNmgIDIdXYOT22F07LFRnBT17UhaSkNHBbaVj+3B21cro9fCsws3xS0OHyjYg4ATNIf rRT+42lAW79Lkl22/ X-Spam-Status: No, score=-18.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_BARRACUDACENTRAL, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 27 Jul 2020 14:44:23 -0000 Add new API for systems with native kernel support for dumping a process on demand. Wire it into the gdb's gcore functionality. Define supports_native_dumpcore and native_dumpcore for NetBSD, that wraps the ptrace(2) call with the PT_DUMPCORE operation. 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. * nbsd-nat.h (nbsd_nat_target::supports_native_dumpcore) (nbsd_nat_target::native_dumpcore): New declarations. * nbsd-nat.c (nbsd_nat_target::supports_native_dumpcore) (nbsd_nat_target::native_dumpcore): New functions. * gcore.c (gcore_command): Use target_supports_native_dumpcore () and target_native_dumpcore (). =2D-- gdb/ChangeLog | 14 +++++++++++ gdb/gcore.c | 21 ++++++++++------ gdb/nbsd-nat.c | 18 ++++++++++++++ gdb/nbsd-nat.h | 2 ++ gdb/target-delegates.c | 55 ++++++++++++++++++++++++++++++++++++++++++ gdb/target.h | 18 ++++++++++++++ 6 files changed, 120 insertions(+), 8 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index a768df0d76c..fac4c8b51f3 100644 =2D-- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,17 @@ +2020-07-27 Kamil Rytarowski + + * target.h (supports_native_dumpcore, native_dumpcore): New + function declarations. + * target.c (supports_native_dumpcore, native_dumpcore): New + functions. + * target-delegates.c: Rebuild. + * nbsd-nat.h (nbsd_nat_target::supports_native_dumpcore) + (nbsd_nat_target::native_dumpcore): New declarations. + * nbsd-nat.c (nbsd_nat_target::supports_native_dumpcore) + (nbsd_nat_target::native_dumpcore): New functions. + * gcore.c (gcore_command): Use target_supports_native_dumpcore () + and target_native_dumpcore (). + 2020-07-22 Simon Marchi Tankut Baris Aktemur diff --git a/gdb/gcore.c b/gdb/gcore.c index 7b653fb74e3..7fdd147a779 100644 =2D-- 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_native_dumpcore ()) + target_native_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/nbsd-nat.c b/gdb/nbsd-nat.c index a9405ebf862..c95cd041497 100644 =2D-- a/gdb/nbsd-nat.c +++ b/gdb/nbsd-nat.c @@ -845,3 +845,21 @@ nbsd_nat_target::supports_multi_process () { return true; } + +/* Implement the "supports_native_dumpcore" target_ops method. */ + +bool +nbsd_nat_target::supports_native_dumpcore () +{ + return true; +} + +/* Implement the "native_dumpcore" target_ops method. */ + +bool +nbsd_nat_target::native_dumpcore (char *filename) +{ + pid_t pid =3D inferior_ptid.pid (); + + return ptrace(PT_DUMPCORE, pid, filename, strlen(filename)) !=3D -1; +} diff --git a/gdb/nbsd-nat.h b/gdb/nbsd-nat.h index 0a7048ecf35..1348a0dda45 100644 =2D-- a/gdb/nbsd-nat.h +++ b/gdb/nbsd-nat.h @@ -49,6 +49,8 @@ struct nbsd_nat_target : public inf_ptrace_target override; bool supports_multi_process () override; + bool supports_native_dumpcore () override; + bool native_dumpcore (char* filename) override; }; #endif /* nbsd-nat.h */ diff --git a/gdb/target-delegates.c b/gdb/target-delegates.c index c28af097183..a45b49b2bb1 100644 =2D-- 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_native_dumpcore () override; + bool native_dumpcore (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_native_dumpcore () override; + bool native_dumpcore (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_con= ditions () return result; } +bool +target_ops::supports_native_dumpcore () +{ + return this->beneath ()->supports_native_dumpcore (); +} + +bool +dummy_target::supports_native_dumpcore () +{ + return false; +} + +bool +debug_target::supports_native_dumpcore () +{ + bool result; + fprintf_unfiltered (gdb_stdlog, "-> %s->supports_native_dumpcore (...)\= n", this->beneath ()->shortname ()); + result =3D this->beneath ()->supports_native_dumpcore (); + fprintf_unfiltered (gdb_stdlog, "<- %s->supports_native_dumpcore (", th= is->beneath ()->shortname ()); + fputs_unfiltered (") =3D ", gdb_stdlog); + target_debug_print_bool (result); + fputs_unfiltered ("\n", gdb_stdlog); + return result; +} + +bool +target_ops::native_dumpcore (char *arg0) +{ + return this->beneath ()->native_dumpcore (arg0); +} + +bool +dummy_target::native_dumpcore (char *arg0) +{ + return false; +} + +bool +debug_target::native_dumpcore (char *arg0) +{ + bool result; + fprintf_unfiltered (gdb_stdlog, "-> %s->native_dumpcore (...)\n", this-= >beneath ()->shortname ()); + result =3D this->beneath ()->native_dumpcore (arg0); + fprintf_unfiltered (gdb_stdlog, "<- %s->native_dumpcore (", this->benea= th ()->shortname ()); + target_debug_print_char_p (arg0); + fputs_unfiltered (") =3D ", 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..24f462dd38e 100644 =2D-- 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_native_dumpcore () + TARGET_DEFAULT_RETURN (false); + + /* Generate the core file with native target API. */ + virtual bool native_dumpcore (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 native dumpcore API? */ + +#define target_supports_native_dumpcore() \ + (current_top_target ()->supports_native_dumpcore) () + +/* Generate the core file with native target API. */ + +#define target_native_dumpcore(x) \ + (current_top_target ()->native_dumpcore (x)) + /* Returns true if this target can handle breakpoint commands on its end. */ =2D- 2.26.2