[1/6] gdb: add invalidate_selected_frame function

Message ID 20221202180052.212745-2-simon.marchi@polymtl.ca
State Committed
Commit 1de4b5156345d7cba14224ee12c1121ff061b066
Headers
Series Make frame_info_ptr automatic |

Commit Message

Simon Marchi Dec. 2, 2022, 6 p.m. UTC
  Instead of using `select_frame (nullptr)` to invalidate the selected
frame, introduce a function to do that.  There is no change in behavior,
but it makes the intent a bit clearer.  It also allows adding an assert
in select_frame that fi is not nullptr, so it avoids passing nullptr by
mistake.

Change-Id: I61643f46bc8eca428334513ebdaadab63997bdd0
---
 gdb/frame.c | 16 ++++++++++++++--
 gdb/frame.h |  3 +--
 2 files changed, 15 insertions(+), 4 deletions(-)
  

Comments

Guinevere Larsen Dec. 7, 2022, 2:09 p.m. UTC | #1
On 02/12/2022 19:00, Simon Marchi via Gdb-patches wrote:
> Instead of using `select_frame (nullptr)` to invalidate the selected
> frame, introduce a function to do that.  There is no change in behavior,
> but it makes the intent a bit clearer.  It also allows adding an assert
> in select_frame that fi is not nullptr, so it avoids passing nullptr by
> mistake.

LGTM, and doesn't introduce any regressions

Reviewed-By: Bruno Larsen <blarsen@redhat.com>
  
Simon Marchi Dec. 7, 2022, 4:54 p.m. UTC | #2
On 12/7/22 09:09, Bruno Larsen wrote:
> On 02/12/2022 19:00, Simon Marchi via Gdb-patches wrote:
>> Instead of using `select_frame (nullptr)` to invalidate the selected
>> frame, introduce a function to do that.  There is no change in behavior,
>> but it makes the intent a bit clearer.  It also allows adding an assert
>> in select_frame that fi is not nullptr, so it avoids passing nullptr by
>> mistake.
> 
> LGTM, and doesn't introduce any regressions
> 
> Reviewed-By: Bruno Larsen <blarsen@redhat.com>

Thanks, I pushed it since it's independent from the rest.

Simon
  

Patch

diff --git a/gdb/frame.c b/gdb/frame.c
index b4079ef833e8..6a6d968b9a97 100644
--- a/gdb/frame.c
+++ b/gdb/frame.c
@@ -1836,11 +1836,23 @@  deprecated_safe_get_selected_frame (void)
   return get_selected_frame (NULL);
 }
 
-/* Select frame FI (or NULL - to invalidate the selected frame).  */
+/* Invalidate the selected frame.  */
+
+static void
+invalidate_selected_frame ()
+{
+  selected_frame = nullptr;
+  selected_frame_level = -1;
+  selected_frame_id = null_frame_id;
+}
+
+/* See frame.h.  */
 
 void
 select_frame (frame_info_ptr fi)
 {
+  gdb_assert (fi != nullptr);
+
   selected_frame = fi;
   selected_frame_level = frame_relative_level (fi);
   if (selected_frame_level == 0)
@@ -2012,7 +2024,7 @@  reinit_frame_cache (void)
     annotate_frames_invalid ();
 
   sentinel_frame = NULL;		/* Invalidate cache */
-  select_frame (NULL);
+  invalidate_selected_frame ();
   frame_stash_invalidate ();
 
   for (frame_info_ptr &iter : frame_info_ptr::frame_list)
diff --git a/gdb/frame.h b/gdb/frame.h
index 100ab1fe48eb..cf8bbc6a52bd 100644
--- a/gdb/frame.h
+++ b/gdb/frame.h
@@ -239,8 +239,7 @@  extern void reinit_frame_cache (void);
    and then return that thread's previously selected frame.  */
 extern frame_info_ptr get_selected_frame (const char *message = nullptr);
 
-/* Select a specific frame.  NULL implies re-select the inner most
-   frame.  */
+/* Select a specific frame.  */
 extern void select_frame (frame_info_ptr);
 
 /* Save the frame ID and frame level of the selected frame in FRAME_ID