From: Markus Metzger <markus.t.metzger@intel.com>
To: palves@redhat.com
Cc: gdb-patches@sourceware.org
Subject: [PATCH v2 2/3] gcore, target: allow target to prepare/cleanup for/after core file generation
Date: Tue, 24 Jun 2014 08:51:00 -0000 [thread overview]
Message-ID: <1403599872-25299-2-git-send-email-markus.t.metzger@intel.com> (raw)
In-Reply-To: <1403599872-25299-1-git-send-email-markus.t.metzger@intel.com>
Add new target functions to_prepare_to_generate_core and
to_done_generating_core that are called before and after generating a core
file, respectively.
This allows targets to prepare for core file generation and to clean up
afterwards.
2014-06-24 Markus Metzger <markus.t.metzger@intel.com>
* target.h (target_ops) <to_prepare_to_generate_core>
<to_done_generating_core>: New.
(target_prepare_to_generate_core, target_done_generating_core): New.
* target.c (target_prepare_to_generate_core)
(target_done_generating_core): New.
* target-delegates.c: Regenerate.
* gcore.c: (write_gcore_file): Rename to ...
(write_gcore_file_1): ...this.
(write_gcore_file): Call target_prepare_to_generate_core
and target_done_generating_core.
---
gdb/gcore.c | 27 ++++++++++++++++++++++-----
gdb/target-delegates.c | 30 ++++++++++++++++++++++++++++++
gdb/target.c | 16 ++++++++++++++++
gdb/target.h | 14 ++++++++++++++
4 files changed, 82 insertions(+), 5 deletions(-)
diff --git a/gdb/gcore.c b/gdb/gcore.c
index 7a4ded7..44acbe3 100644
--- a/gdb/gcore.c
+++ b/gdb/gcore.c
@@ -61,12 +61,10 @@ create_gcore_bfd (const char *filename)
return obfd;
}
-/* write_gcore_file -- helper for gcore_command (exported).
- Compose and write the corefile data to the core file. */
-
+/* write_gcore_file_1 -- do the actual work of write_gcore_file. */
-void
-write_gcore_file (bfd *obfd)
+static void
+write_gcore_file_1 (bfd *obfd)
{
struct cleanup *cleanup;
void *note_data = NULL;
@@ -111,6 +109,25 @@ write_gcore_file (bfd *obfd)
do_cleanups (cleanup);
}
+/* write_gcore_file -- helper for gcore_command (exported).
+ Compose and write the corefile data to the core file. */
+
+void
+write_gcore_file (bfd *obfd)
+{
+ volatile struct gdb_exception except;
+
+ target_prepare_to_generate_core ();
+
+ TRY_CATCH (except, RETURN_MASK_ALL)
+ write_gcore_file_1 (obfd);
+
+ target_done_generating_core ();
+
+ if (except.reason < 0)
+ throw_exception (except);
+}
+
static void
do_bfd_delete_cleanup (void *arg)
{
diff --git a/gdb/target-delegates.c b/gdb/target-delegates.c
index 4eefae8..eaab916 100644
--- a/gdb/target-delegates.c
+++ b/gdb/target-delegates.c
@@ -1625,6 +1625,30 @@ delegate_decr_pc_after_break (struct target_ops *self, struct gdbarch *arg1)
}
static void
+delegate_prepare_to_generate_core (struct target_ops *self)
+{
+ self = self->beneath;
+ self->to_prepare_to_generate_core (self);
+}
+
+static void
+tdefault_prepare_to_generate_core (struct target_ops *self)
+{
+}
+
+static void
+delegate_done_generating_core (struct target_ops *self)
+{
+ self = self->beneath;
+ self->to_done_generating_core (self);
+}
+
+static void
+tdefault_done_generating_core (struct target_ops *self)
+{
+}
+
+static void
install_delegators (struct target_ops *ops)
{
if (ops->to_post_attach == NULL)
@@ -1897,6 +1921,10 @@ install_delegators (struct target_ops *ops)
ops->to_get_tailcall_unwinder = delegate_get_tailcall_unwinder;
if (ops->to_decr_pc_after_break == NULL)
ops->to_decr_pc_after_break = delegate_decr_pc_after_break;
+ if (ops->to_prepare_to_generate_core == NULL)
+ ops->to_prepare_to_generate_core = delegate_prepare_to_generate_core;
+ if (ops->to_done_generating_core == NULL)
+ ops->to_done_generating_core = delegate_done_generating_core;
}
static void
@@ -2037,4 +2065,6 @@ install_dummy_methods (struct target_ops *ops)
ops->to_get_unwinder = tdefault_get_unwinder;
ops->to_get_tailcall_unwinder = tdefault_get_tailcall_unwinder;
ops->to_decr_pc_after_break = default_target_decr_pc_after_break;
+ ops->to_prepare_to_generate_core = tdefault_prepare_to_generate_core;
+ ops->to_done_generating_core = tdefault_done_generating_core;
}
diff --git a/gdb/target.c b/gdb/target.c
index 075425d..f384ed0 100644
--- a/gdb/target.c
+++ b/gdb/target.c
@@ -3606,6 +3606,22 @@ target_decr_pc_after_break (struct gdbarch *gdbarch)
return current_target.to_decr_pc_after_break (¤t_target, gdbarch);
}
+/* See target.h. */
+
+void
+target_prepare_to_generate_core (void)
+{
+ current_target.to_prepare_to_generate_core (¤t_target);
+}
+
+/* See target.h. */
+
+void
+target_done_generating_core (void)
+{
+ current_target.to_done_generating_core (¤t_target);
+}
+
static void
debug_to_files_info (struct target_ops *target)
{
diff --git a/gdb/target.h b/gdb/target.h
index e563f2f..96d5cb1 100644
--- a/gdb/target.h
+++ b/gdb/target.h
@@ -1109,6 +1109,14 @@ struct target_ops
struct gdbarch *gdbarch)
TARGET_DEFAULT_FUNC (default_target_decr_pc_after_break);
+ /* Prepare to generate a core file. */
+ void (*to_prepare_to_generate_core) (struct target_ops *)
+ TARGET_DEFAULT_IGNORE ();
+
+ /* Cleanup after generating a core file. */
+ void (*to_done_generating_core) (struct target_ops *)
+ TARGET_DEFAULT_IGNORE ();
+
int to_magic;
/* Need sub-structure for target machine related rather than comm related?
*/
@@ -2261,4 +2269,10 @@ extern CORE_ADDR forward_target_decr_pc_after_break (struct target_ops *ops,
/* See to_decr_pc_after_break. */
extern CORE_ADDR target_decr_pc_after_break (struct gdbarch *gdbarch);
+/* See to_prepare_to_generate_core. */
+extern void target_prepare_to_generate_core (void);
+
+/* See to_done_generating_core. */
+extern void target_done_generating_core (void);
+
#endif /* !defined (TARGET_H) */
--
1.8.3.1
next prev parent reply other threads:[~2014-06-24 8:51 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-06-24 8:51 [PATCH v2 1/3] make_corefile_notes: have caller free returned memory Markus Metzger
2014-06-24 8:51 ` Markus Metzger [this message]
2014-06-24 13:11 ` [PATCH v2 2/3] gcore, target: allow target to prepare/cleanup for/after core file generation Pedro Alves
2014-06-24 8:52 ` [PATCH v2 3/3] btrace: pretend we're not replaying when generating a core file Markus Metzger
2014-06-24 13:19 ` Pedro Alves
2014-06-24 12:58 ` [PATCH v2 1/3] make_corefile_notes: have caller free returned memory Pedro Alves
2014-06-24 13:44 ` Tom Tromey
2014-06-24 14:18 ` Metzger, Markus T
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=1403599872-25299-2-git-send-email-markus.t.metzger@intel.com \
--to=markus.t.metzger@intel.com \
--cc=gdb-patches@sourceware.org \
--cc=palves@redhat.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