Blame SOURCES/gdb-upstream-framefilters-2of2.patch

2c2fa1
http://sourceware.org/ml/gdb-cvs/2013-05/msg00141.html
2c2fa1
2c2fa1
### src/gdb/ChangeLog	2013/05/17 06:58:33	1.15565
2c2fa1
### src/gdb/ChangeLog	2013/05/17 08:34:18	1.15566
2c2fa1
## -1,3 +1,18 @@
2c2fa1
+2013-05-17  Phil Muldoon  <pmuldoon@redhat.com>
2c2fa1
+
2c2fa1
+	* frame.c (frame_stash): Convert to htab.
2c2fa1
+	(frame_addr_hash): New function.
2c2fa1
+	(frame_addr_hash_eq): New function.
2c2fa1
+	(frame_stash_create): Convert function to create
2c2fa1
+	a hash table.
2c2fa1
+	(frame_stash_add): Convert function to add an entry to a hash
2c2fa1
+	table.
2c2fa1
+	(frame_stash_find): Convert function to search the hash table.
2c2fa1
+	(frame_stash_invalidate): Convert function to empty the hash
2c2fa1
+	table.
2c2fa1
+	(get_frame_id): Only add to stash if a frame_id is created.
2c2fa1
+	(_initialize_frame): Call frame_stash_create.
2c2fa1
+
2c2fa1
 2013-05-16  Yue Lu  <hacklu.newborn@gmail.com>  (tiny change)
2c2fa1
 
2c2fa1
 	* configure.ac: Ensure MIG is available when building for GNU Hurd
2c2fa1
--- src/gdb/frame.c	2013/04/10 15:11:11	1.317
2c2fa1
+++ src/gdb/frame.c	2013/05/17 08:34:18	1.318
2c2fa1
@@ -43,6 +43,7 @@
2c2fa1
 #include "block.h"
2c2fa1
 #include "inline-frame.h"
2c2fa1
 #include "tracepoint.h"
2c2fa1
+#include "hashtab.h"
2c2fa1
 
2c2fa1
 static struct frame_info *get_prev_frame_1 (struct frame_info *this_frame);
2c2fa1
 static struct frame_info *get_prev_frame_raw (struct frame_info *this_frame);
2c2fa1
@@ -128,38 +129,107 @@
2c2fa1
   enum unwind_stop_reason stop_reason;
2c2fa1
 };
2c2fa1
 
2c2fa1
-/* A frame stash used to speed up frame lookups.  */
2c2fa1
+/* A frame stash used to speed up frame lookups.  Create a hash table
2c2fa1
+   to stash frames previously accessed from the frame cache for
2c2fa1
+   quicker subsequent retrieval.  The hash table is emptied whenever
2c2fa1
+   the frame cache is invalidated.  */
2c2fa1
+
2c2fa1
+static htab_t frame_stash;
2c2fa1
+
2c2fa1
+/* Internal function to calculate a hash from the frame_id addresses,
2c2fa1
+   using as many valid addresses as possible.  Frames below level 0
2c2fa1
+   are not stored in the hash table.  */
2c2fa1
+
2c2fa1
+static hashval_t
2c2fa1
+frame_addr_hash (const void *ap)
2c2fa1
+{
2c2fa1
+  const struct frame_info *frame = ap;
2c2fa1
+  const struct frame_id f_id = frame->this_id.value;
2c2fa1
+  hashval_t hash = 0;
2c2fa1
+
2c2fa1
+  gdb_assert (f_id.stack_addr_p || f_id.code_addr_p
2c2fa1
+	      || f_id.special_addr_p);
2c2fa1
+
2c2fa1
+  if (f_id.stack_addr_p)
2c2fa1
+    hash = iterative_hash (&f_id.stack_addr,
2c2fa1
+			   sizeof (f_id.stack_addr), hash);
2c2fa1
+  if (f_id.code_addr_p)
2c2fa1
+    hash = iterative_hash (&f_id.code_addr,
2c2fa1
+			   sizeof (f_id.code_addr), hash);
2c2fa1
+  if (f_id.special_addr_p)
2c2fa1
+    hash = iterative_hash (&f_id.special_addr,
2c2fa1
+			   sizeof (f_id.special_addr), hash);
2c2fa1
 
2c2fa1
-/* We currently only stash one frame at a time, as this seems to be
2c2fa1
-   sufficient for now.  */
2c2fa1
-static struct frame_info *frame_stash = NULL;
2c2fa1
+  return hash;
2c2fa1
+}
2c2fa1
+
2c2fa1
+/* Internal equality function for the hash table.  This function
2c2fa1
+   defers equality operations to frame_id_eq.  */
2c2fa1
+
2c2fa1
+static int
2c2fa1
+frame_addr_hash_eq (const void *a, const void *b)
2c2fa1
+{
2c2fa1
+  const struct frame_info *f_entry = a;
2c2fa1
+  const struct frame_info *f_element = b;
2c2fa1
 
2c2fa1
-/* Add the following FRAME to the frame stash.  */
2c2fa1
+  return frame_id_eq (f_entry->this_id.value,
2c2fa1
+		      f_element->this_id.value);
2c2fa1
+}
2c2fa1
+
2c2fa1
+/* Internal function to create the frame_stash hash table.  100 seems
2c2fa1
+   to be a good compromise to start the hash table at.  */
2c2fa1
+
2c2fa1
+static void
2c2fa1
+frame_stash_create (void)
2c2fa1
+{
2c2fa1
+  frame_stash = htab_create (100,
2c2fa1
+			     frame_addr_hash,
2c2fa1
+			     frame_addr_hash_eq,
2c2fa1
+			     NULL);
2c2fa1
+}
2c2fa1
+
2c2fa1
+/* Internal function to add a frame to the frame_stash hash table.  Do
2c2fa1
+   not store frames below 0 as they may not have any addresses to
2c2fa1
+   calculate a hash.  */
2c2fa1
 
2c2fa1
 static void
2c2fa1
 frame_stash_add (struct frame_info *frame)
2c2fa1
 {
2c2fa1
-  frame_stash = frame;
2c2fa1
+  /* Do not stash frames below level 0.  */
2c2fa1
+  if (frame->level >= 0)
2c2fa1
+    {
2c2fa1
+      struct frame_info **slot;
2c2fa1
+
2c2fa1
+      slot = (struct frame_info **) htab_find_slot (frame_stash,
2c2fa1
+						    frame,
2c2fa1
+						    INSERT);
2c2fa1
+      *slot = frame;
2c2fa1
+    }
2c2fa1
 }
2c2fa1
 
2c2fa1
-/* Search the frame stash for an entry with the given frame ID.
2c2fa1
-   If found, return that frame.  Otherwise return NULL.  */
2c2fa1
+/* Internal function to search the frame stash for an entry with the
2c2fa1
+   given frame ID.  If found, return that frame.  Otherwise return
2c2fa1
+   NULL.  */
2c2fa1
 
2c2fa1
 static struct frame_info *
2c2fa1
 frame_stash_find (struct frame_id id)
2c2fa1
 {
2c2fa1
-  if (frame_stash && frame_id_eq (frame_stash->this_id.value, id))
2c2fa1
-    return frame_stash;
2c2fa1
+  struct frame_info dummy;
2c2fa1
+  struct frame_info *frame;
2c2fa1
 
2c2fa1
-  return NULL;
2c2fa1
+  dummy.this_id.value = id;
2c2fa1
+  frame = htab_find (frame_stash, &dummy);
2c2fa1
+  return frame;
2c2fa1
 }
2c2fa1
 
2c2fa1
-/* Invalidate the frame stash by removing all entries in it.  */
2c2fa1
+/* Internal function to invalidate the frame stash by removing all
2c2fa1
+   entries in it.  This only occurs when the frame cache is
2c2fa1
+   invalidated.  */
2c2fa1
 
2c2fa1
 static void
2c2fa1
 frame_stash_invalidate (void)
2c2fa1
 {
2c2fa1
-  frame_stash = NULL;
2c2fa1
+  htab_empty (frame_stash);
2c2fa1
 }
2c2fa1
 
2c2fa1
 /* Flag to control debugging.  */
2c2fa1
@@ -345,10 +415,9 @@
2c2fa1
 	  fprint_frame_id (gdb_stdlog, fi->this_id.value);
2c2fa1
 	  fprintf_unfiltered (gdb_stdlog, " }\n");
2c2fa1
 	}
2c2fa1
+      frame_stash_add (fi);
2c2fa1
     }
2c2fa1
 
2c2fa1
-  frame_stash_add (fi);
2c2fa1
-
2c2fa1
   return fi->this_id.value;
2c2fa1
 }
2c2fa1
 
2c2fa1
@@ -2451,6 +2520,8 @@
2c2fa1
 {
2c2fa1
   obstack_init (&frame_cache_obstack);
2c2fa1
 
2c2fa1
+  frame_stash_create ();
2c2fa1
+
2c2fa1
   observer_attach_target_changed (frame_observer_target_changed);
2c2fa1
 
2c2fa1
   add_prefix_cmd ("backtrace", class_maintenance, set_backtrace_cmd, _("\