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