This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: RFC: lazily call save_current_space_and_thread


Tom> I think I can actually make make_cleanup_restore_current_thread more
Tom> efficient.  But if not, I will reimplement this with a flag.

This turned out to be pretty easy; I'm not sure why I didn't do it
before.

This patch makes make_cleanup_restore_current_thread more efficient, by
having it not compute the current frame when there is no selected frame.
This approach let me remove another hack I had in my tree.

Built and regtested on x86-64 (compile farm).

Let me know what you think.

Tom

2011-03-08  Tom Tromey  <tromey@redhat.com>

	* thread.c (restore_selected_frame): Handle frame_level == -1.
	(make_cleanup_restore_current_thread): Use
	get_selected_frame_if_set.
	* frame.h (get_selected_frame_if_set): Declare.
	* frame.c (get_selected_frame_if_set): New function.

diff --git a/gdb/frame.c b/gdb/frame.c
index 36fcefe..8ed20b1 100644
--- a/gdb/frame.c
+++ b/gdb/frame.c
@@ -1247,6 +1247,16 @@ get_selected_frame (const char *message)
   return selected_frame;
 }
 
+/* If there is a selected frame, return it.  Otherwise, return NULL.  */
+
+struct frame_info *
+get_selected_frame_if_set (void)
+{
+  if (selected_frame == NULL)
+    return NULL;
+  return get_selected_frame (NULL);
+}
+
 /* This is a variant of get_selected_frame() which can be called when
    the inferior does not have a frame; in that case it will return
    NULL instead of calling error().  */
diff --git a/gdb/frame.h b/gdb/frame.h
index 2c5276e..252b75e 100644
--- a/gdb/frame.h
+++ b/gdb/frame.h
@@ -260,6 +260,9 @@ extern void reinit_frame_cache (void);
    and then return that thread's previously selected frame.  */
 extern struct frame_info *get_selected_frame (const char *message);
 
+/* If there is a selected frame, return it.  Otherwise, return NULL.  */
+extern struct frame_info *get_selected_frame_if_set (void);
+
 /* Select a specific frame.  NULL, apparently implies re-select the
    inner most frame.  */
 extern void select_frame (struct frame_info *);
diff --git a/gdb/thread.c b/gdb/thread.c
index 7d8f6da..f7eccfe 100644
--- a/gdb/thread.c
+++ b/gdb/thread.c
@@ -1019,6 +1019,13 @@ restore_selected_frame (struct frame_id a_frame_id, int frame_level)
   struct frame_info *frame = NULL;
   int count;
 
+  /* This means there was no selected frame.  */
+  if (frame_level == -1)
+    {
+      select_frame (NULL);
+      return;
+    }
+
   gdb_assert (frame_level >= 0);
 
   /* Restore by level first, check if the frame id is the same as
@@ -1137,7 +1144,13 @@ make_cleanup_restore_current_thread (void)
 	  && target_has_registers
 	  && target_has_stack
 	  && target_has_memory)
-	frame = get_selected_frame (NULL);
+	{
+	  /* If we naively call get_selected_frame here, then we can
+	     end up reading debuginfo for the current frame, even
+	     though the user has not selected a frame and we don't
+	     actually need the debuginfo at this point.  */
+	  frame = get_selected_frame_if_set ();
+	}
       else
 	frame = NULL;
 


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]