public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Simon Marchi <simon.marchi@efficios.com>
To: gdb-patches@sourceware.org
Cc: Simon Marchi <simon.marchi@efficios.com>
Subject: [PATCH 1/2] gdb: call frame unwinders' dealloc_cache methods through destroying the frame cache
Date: Mon, 30 Jan 2023 15:02:48 -0500	[thread overview]
Message-ID: <20230130200249.131155-2-simon.marchi@efficios.com> (raw)
In-Reply-To: <20230130200249.131155-1-simon.marchi@efficios.com>

Currently, some frame resources are deallocated by iterating on the
frame chain (starting from the sentinel), calling dealloc_cache.  The
problem is that user-created frames are not part of that chain, so we
never call dealloc_cache for them.

I propose to make it so the dealloc_cache callbacks are called when the
frames are removed from the frame_stash hash table, by registering a
deletion function to the hash table.  This happens when
frame_stash_invalidate is called by reinit_frame_cache.  This way, all
frames registered in the cache will get their unwinder's dealloc_cache
callbacks called.

Note that at the moment, the sentinel frames are not registered in the
cache, so we won't call dealloc_cache for them.  However, it's just a
theoritical problem, because the sentinel frame unwinder does not
provide this callback.  Also, a subsequent patch will change things so
that sentinel frames are registered to the cache.

I moved the obstack_free / obstack_init pair below the
frame_stash_invalidate call in reinit_frame_cache, because I assumed
that some dealloc_cache would need to access some data on that obstack,
so it would be better to free it after clearing the hash table.

Change-Id: If4f9b38266b458c4e2f7eb43e933090177c22190
---
 gdb/frame.c | 39 ++++++++++++++++++++++++---------------
 1 file changed, 24 insertions(+), 15 deletions(-)

diff --git a/gdb/frame.c b/gdb/frame.c
index a08a8f47ebc4..fed961b2a8df 100644
--- a/gdb/frame.c
+++ b/gdb/frame.c
@@ -259,6 +259,22 @@ frame_addr_hash_eq (const void *a, const void *b)
   return f_entry->this_id.value == f_element->this_id.value;
 }
 
+/* Deletion function for the frame cache hash table.  */
+
+static void
+frame_info_del (void *frame_v)
+{
+  frame_info *frame = (frame_info *) frame_v;
+
+  if (frame->prologue_cache != nullptr
+      && frame->unwind->dealloc_cache != nullptr)
+    frame->unwind->dealloc_cache (frame, frame->prologue_cache);
+
+  if (frame->base_cache != nullptr
+      && frame->base->unwind->dealloc_cache != nullptr)
+    frame->base->unwind->dealloc_cache (frame, frame->base_cache);
+}
+
 /* Internal function to create the frame_stash hash table.  100 seems
    to be a good compromise to start the hash table at.  */
 
@@ -268,7 +284,7 @@ frame_stash_create (void)
   frame_stash = htab_create (100,
 			     frame_addr_hash,
 			     frame_addr_hash_eq,
-			     NULL);
+			     frame_info_del);
 }
 
 /* Internal function to add a frame to the frame_stash hash table.
@@ -2048,26 +2064,19 @@ reinit_frame_cache (void)
 {
   ++frame_cache_generation;
 
-  /* Tear down all frame caches.  */
-  for (frame_info *fi = sentinel_frame; fi != NULL; fi = fi->prev)
-    {
-      if (fi->prologue_cache && fi->unwind->dealloc_cache)
-	fi->unwind->dealloc_cache (fi, fi->prologue_cache);
-      if (fi->base_cache && fi->base->unwind->dealloc_cache)
-	fi->base->unwind->dealloc_cache (fi, fi->base_cache);
-    }
-
-  /* Since we can't really be sure what the first object allocated was.  */
-  obstack_free (&frame_cache_obstack, 0);
-  obstack_init (&frame_cache_obstack);
-
   if (sentinel_frame != NULL)
     annotate_frames_invalid ();
 
-  sentinel_frame = NULL;		/* Invalidate cache */
   invalidate_selected_frame ();
+
+  /* Invalidate cache.  */
+  sentinel_frame = NULL;
   frame_stash_invalidate ();
 
+  /* Since we can't really be sure what the first object allocated was.  */
+  obstack_free (&frame_cache_obstack, 0);
+  obstack_init (&frame_cache_obstack);
+
   for (frame_info_ptr &iter : frame_info_ptr::frame_list)
     iter.invalidate ();
 
-- 
2.39.1


  reply	other threads:[~2023-01-30 20:02 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-30 20:02 [PATCH 0/2] Fix gdb.base/frame-view.exp on AArch64 Simon Marchi
2023-01-30 20:02 ` Simon Marchi [this message]
2023-02-09  7:40   ` [PATCH 1/2] gdb: call frame unwinders' dealloc_cache methods through destroying the frame cache Tom de Vries
2023-02-09 12:42     ` Tom de Vries
2023-02-09 19:53       ` Simon Marchi
2023-01-30 20:02 ` [PATCH 2/2] gdb: give sentinel for user frames distinct IDs, register sentinel frames to " Simon Marchi
2023-02-07 17:02   ` Alexandra Petlanova Hajkova
2023-02-08 21:37     ` Simon Marchi
2023-02-08 17:05   ` Luis Machado
2023-02-08 21:38     ` Simon Marchi

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=20230130200249.131155-2-simon.marchi@efficios.com \
    --to=simon.marchi@efficios.com \
    --cc=gdb-patches@sourceware.org \
    /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).