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 6D95138708AF for ; Tue, 28 Jul 2020 15:47:02 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 6D95138708AF 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=1595951204; bh=WIBdTRuXAVxkh+HEPfBrb06G2ftHItzaWGmwBeoDouo=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=I+O6dh0XBdEvFUNPSikDdasWqT7/tfhcsKjfmLDMjEJOBO2/hhIYa/a9wOd9liu/p I/R5h9egk/4hfaAFQyQDRLKWMUayZeRsfXMkKpfYEzKnYc2WqsPRJReICFrgPvTHFz Px4/9EE2PD0OQa1C1fGlHwjruRXydW6G4ZrZZys4= 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 1MCKBm-1jsEbO14L4-009PIC; Tue, 28 Jul 2020 17:46:44 +0200 From: Kamil Rytarowski 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 Message-Id: <20200728154602.3824-1-n54@gmx.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200727144338.7033-1-n54@gmx.com> References: <20200727144338.7033-1-n54@gmx.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Provags-ID: V03:K1:b7u9p5DU36tIa+s8QONyccVyQ5ExkhVpLdOmfbSCSt4KKJvpTL5 j03Pe84zs3aIQjEQ0SS/bg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P4TwbyWw/vxcmwZ80lIj AHmAhvWbpH5vwAovAXGTZUNFivDwHHc52p8kaP7p2EEwwfTjx8lMYHgpjkO68ypGAdI134FIF 1AdpPMPuTnBQfG5dXEKBlALNxkpgjkfOnK8ks12lK1dS9XNzgDgDTCpTB3AZQ8QPXVoiSaN0C 05UlvUKz94gISBkr1It1KWla3jvZFXQT7/nokfCvIAJIgXki0jOhWQVWX6tGL7AY3KmGNDcIU PZDJPTd0OyWh9wOPEmmoGYGaPjZXNtoiLe6uglYiqMhOU2//MAyQkZonQWDsgDXKBvU6YK+Hw i6hMJCpim6qU8sYfKorrKlzS0W9hd8gaDhcgrW+5zgVCLo7bhvMd21sfc5U1OTKlHfCoXScLO O9Q+6SwAqMer8C6mQ X-Spam-Status: No, score=-18.6 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: Tue, 28 Jul 2020 15:47:04 -0000 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 (). =2D-- 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 =2D-- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,13 @@ +2020-07-28 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. + * gcore.c (gcore_command): Use target_supports_native_dumpcore () + and target_native_dumpcore (). + 2020-07-28 H.J. Lu PR binutils/26301 diff --git a/gdb/gcore.c b/gdb/gcore.c index 7b653fb74e3..d0e36b1a708 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_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 =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_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_con= ditions () 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", thi= s->beneath ()->shortname ()); + result =3D this->beneath ()->supports_dumpcore (); + fprintf_unfiltered (gdb_stdlog, "<- %s->supports_dumpcore (", this->ben= eath ()->shortname ()); + fputs_unfiltered (") =3D ", 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->beneat= h ()->shortname ()); + result =3D this->beneath ()->dumpcore (arg0); + fprintf_unfiltered (gdb_stdlog, "<- %s->dumpcore (", this->beneath ()->= shortname ()); + target_debug_print_const_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..85a03ed5be8 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_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. */ =2D- 2.26.2