public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Tom Tromey <tromey@redhat.com>
To: gdb-patches@sourceware.org
Cc: Jan Kratochvil <jan.kratochvil@redhat.com>
Subject: [PATCH v2 05/14] add dummy frame destructor
Date: Fri, 20 Jun 2014 16:32:00 -0000	[thread overview]
Message-ID: <1403279874-23781-6-git-send-email-tromey@redhat.com> (raw)
In-Reply-To: <1403279874-23781-1-git-send-email-tromey@redhat.com>

From: Jan Kratochvil <jan.kratochvil@redhat.com>

The compiler code needed a hook into dummy frame destruction, so that
some state could be kept while the inferior call is made and then
destroyed when the inferior call finishes.

This patch adds an optional destructor to dummy frames and a new API
to access it.

2014-06-20  Jan Kratochvil  <jan.kratochvil@redhat.com>

	* dummy-frame.c (struct dummy_frame) <dtor, dtor_data>: New
	fields.
	(pop_dummy_frame): Call the destructor if it exists.
	(register_dummy_frame_dtor, find_dummy_frame_dtor): New
	functions.
	* dummy-frame.h (dummy_frame_dtor_ftype): New typedef.
	(register_dummy_frame_dtor, find_dummy_frame_dtor): Declare.
---
 gdb/ChangeLog     | 10 ++++++++++
 gdb/dummy-frame.c | 39 +++++++++++++++++++++++++++++++++++++++
 gdb/dummy-frame.h | 13 +++++++++++++
 3 files changed, 62 insertions(+)

diff --git a/gdb/dummy-frame.c b/gdb/dummy-frame.c
index 998ca93..b0608a9 100644
--- a/gdb/dummy-frame.c
+++ b/gdb/dummy-frame.c
@@ -43,6 +43,13 @@ struct dummy_frame
   struct frame_id id;
   /* The caller's state prior to the call.  */
   struct infcall_suspend_state *caller_state;
+
+  /* If non-NULL, a destructor that is run when this dummy frame is
+     popped.  */
+  void (*dtor) (void *data);
+
+  /* Arbitrary data that is passed to DTOR.  */
+  void *dtor_data;
 };
 
 static struct dummy_frame *dummy_frame_stack = NULL;
@@ -107,6 +114,9 @@ pop_dummy_frame (struct dummy_frame **dummy_ptr)
 {
   struct dummy_frame *dummy = *dummy_ptr;
 
+  if (dummy->dtor != NULL)
+    dummy->dtor (dummy->dtor_data);
+
   restore_infcall_suspend_state (dummy->caller_state);
 
   iterate_over_breakpoints (pop_dummy_frame_bpt, dummy);
@@ -171,6 +181,35 @@ dummy_frame_discard (struct frame_id dummy_id)
     remove_dummy_frame (dp);
 }
 
+/* See dummy-frame.h.  */
+
+void
+register_dummy_frame_dtor (struct frame_id dummy_id,
+			   dummy_frame_dtor_ftype *dtor, void *dtor_data)
+{
+  struct dummy_frame **dp, *d;
+
+  dp = lookup_dummy_frame (dummy_id);
+  gdb_assert (dp != NULL);
+  d = *dp;
+  gdb_assert (d->dtor == NULL);
+  d->dtor = dtor;
+  d->dtor_data = dtor_data;
+}
+
+/* See dummy-frame.h.  */
+
+int
+find_dummy_frame_dtor (dummy_frame_dtor_ftype *dtor, void *dtor_data)
+{
+  struct dummy_frame *d;
+
+  for (d = dummy_frame_stack; d != NULL; d = d->next)
+    if (d->dtor == dtor && d->dtor_data == dtor_data)
+      return 1;
+  return 0;
+}
+
 /* There may be stale dummy frames, perhaps left over from when an uncaught
    longjmp took us out of a function that was called by the debugger.  Clean
    them up at least once whenever we start a new inferior.  */
diff --git a/gdb/dummy-frame.h b/gdb/dummy-frame.h
index 6db312e..21e7fff 100644
--- a/gdb/dummy-frame.h
+++ b/gdb/dummy-frame.h
@@ -59,4 +59,17 @@ extern void dummy_frame_discard (struct frame_id dummy_id);
 
 extern const struct frame_unwind dummy_frame_unwind;
 
+/* Call DTOR with DTOR_DATA when DUMMY_ID frame gets discarded.
+   Dummy frame with DUMMY_ID must exist.  There must be no other call of
+   register_dummy_frame_dtor for that dummy frame.  */
+typedef void (dummy_frame_dtor_ftype) (void *data);
+extern void register_dummy_frame_dtor (struct frame_id dummy_id,
+				       dummy_frame_dtor_ftype *dtor,
+				       void *dtor_data);
+
+/* Return 1 if there exists dummy frame with registered DTOR and DTOR_DATA.
+   Return 0 otherwise.  */
+extern int find_dummy_frame_dtor (dummy_frame_dtor_ftype *dtor,
+				  void *dtor_data);
+
 #endif /* !defined (DUMMY_FRAME_H)  */
-- 
1.9.3

  parent reply	other threads:[~2014-06-20 16:32 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-06-20 15:58 [PATCH v2 00/15] let gdb reuse gcc's C compiler Tom Tromey
2014-06-20 15:58 ` [PATCH v2 11/14] export dwarf2_reg_to_regnum_or_error Tom Tromey
2014-06-20 15:58 ` [PATCH v2 04/14] add make_unqualified_type Tom Tromey
2014-06-20 15:58 ` [PATCH v2 09/14] split dwarf2_fetch_cfa_info from dwarf2_compile_expr_to_ax Tom Tromey
2014-06-20 15:58 ` [PATCH v2 14/14] the "compile" command Tom Tromey
2014-06-20 19:17   ` Eli Zaretskii
2014-10-08 17:45     ` Jan Kratochvil
2014-10-08 18:42       ` Eli Zaretskii
2014-10-08 19:42         ` Jan Kratochvil
2014-06-20 15:58 ` [PATCH v2 03/14] add some missing ops to DWARF assembler Tom Tromey
2014-06-20 15:58 ` [PATCH v2 01/14] introduce ui_file_write_for_put Tom Tromey
2014-06-20 15:58 ` [PATCH v2 02/14] add gcc/gdb interface files Tom Tromey
2014-06-20 16:26 ` [PATCH v2 13/14] add s390_gcc_target_options Tom Tromey
2014-06-20 16:32 ` Tom Tromey [this message]
2014-06-20 16:32 ` [PATCH v2 12/14] add linux_infcall_mmap Tom Tromey
2014-06-20 16:32 ` [PATCH v2 07/14] add gnu_triplet_regexp gdbarch method Tom Tromey
2014-06-20 16:33 ` [PATCH v2 10/14] make dwarf_expr_frame_base_1 public Tom Tromey
2014-06-20 20:05   ` Doug Evans
2014-06-23  8:18     ` Gary Benson
2014-06-23 14:57       ` Eli Zaretskii
2014-06-24 10:18         ` Gary Benson
2014-06-24 13:04           ` Pedro Alves
2014-10-08 16:57             ` Jan Kratochvil
2014-06-20 16:39 ` [PATCH v2 08/14] introduce call_function_by_hand_dummy Tom Tromey
2014-06-20 16:51 ` [PATCH v2 06/14] add infcall_mmap and gcc_target_options gdbarch methods 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=1403279874-23781-6-git-send-email-tromey@redhat.com \
    --to=tromey@redhat.com \
    --cc=gdb-patches@sourceware.org \
    --cc=jan.kratochvil@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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).