[binutils-gdb] [gdb] Add default argument for get_selected_block

Tom de Vries via Gdb-cvs <[email protected]> Fri, 17 Jul 2026 17:28:26 +0000 (GMT)
Newsgroups gmane.comp.gdb.cvs
Message-ID <[email protected]>
https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3D961a038a825b=
e3154062c62aebac4e8db26728f0

commit 961a038a825be3154062c62aebac4e8db26728f0
Author: Tom de Vries <[email protected]>
Date:   Fri Jul 17 19:28:22 2026 +0200

    [gdb] Add default argument for get_selected_block
   =20
    I noticed that the get_selected_block argument is mostly 0, NULL, or nu=
llptr.
   =20
    Make nullptr the default argument.
   =20
    Approved-By: Tom Tromey <[email protected]>

Diff:
---
 gdb/ada-exp.y    | 2 +-
 gdb/ada-lang.c   | 6 +++---
 gdb/cp-support.c | 6 +++---
 gdb/eval.c       | 4 ++--
 gdb/f-valprint.c | 2 +-
 gdb/frame.h      | 3 ++-
 gdb/linespec.c   | 2 +-
 gdb/printcmd.c   | 4 ++--
 gdb/rust-lang.c  | 2 +-
 gdb/symtab.c     | 2 +-
 gdb/valops.c     | 2 +-
 11 files changed, 18 insertions(+), 17 deletions(-)

diff --git a/gdb/ada-exp.y b/gdb/ada-exp.y
index f36426a2084..a79d0ca83cb 100644
--- a/gdb/ada-exp.y
+++ b/gdb/ada-exp.y
@@ -1342,7 +1342,7 @@ write_object_renaming (struct parser_state *par_state,
     error (_("Could not find renamed symbol"));
=20
   if (orig_left_context =3D=3D NULL)
-    orig_left_context =3D get_selected_block (NULL);
+    orig_left_context =3D get_selected_block ();
=20
   name =3D obstack_strndup (&ada_parser->temp_space, renamed_entity,
 			  renamed_entity_len);
diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index e057e49b7fc..a7019a4522c 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -7424,7 +7424,7 @@ field_alignment (struct type *type, int f)
 static struct symbol *
 ada_find_any_type_symbol (const char *name)
 {
-  return standard_lookup (name, get_selected_block (nullptr),
+  return standard_lookup (name, get_selected_block (),
 			  SEARCH_TYPE_DOMAIN);
 }
=20
@@ -11437,7 +11437,7 @@ get_var_value (const char *name, const char *err_ms=
g)
=20
   std::vector<struct block_symbol> syms
     =3D ada_lookup_symbol_list_worker (lookup_name,
-				     get_selected_block (0),
+				     get_selected_block (),
 				     SEARCH_VFT, true);
=20
   if (syms.size () !=3D 1)
@@ -13753,7 +13753,7 @@ public:
     /* Search upwards from currently selected frame (so that we can
        complete on local vars.  */
=20
-    for (const block *b =3D get_selected_block (0);
+    for (const block *b =3D get_selected_block ();
 	 b !=3D nullptr;
 	 b =3D b->superblock ())
       {
diff --git a/gdb/cp-support.c b/gdb/cp-support.c
index c684d1a1723..335e06a039f 100644
--- a/gdb/cp-support.c
+++ b/gdb/cp-support.c
@@ -1322,7 +1322,7 @@ add_symbol_overload_list_namespace (const char *func_=
name,
     }
=20
   /* Look in the static block.  */
-  block =3D get_selected_block (0);
+  block =3D get_selected_block ();
   block =3D block =3D=3D nullptr ? nullptr : block->static_block ();
   if (block !=3D nullptr)
     {
@@ -1414,7 +1414,7 @@ add_symbol_overload_list_using (const char *func_name,
      look in the appropriate namespaces for new functions to match
      on.  */
=20
-  for (block =3D get_selected_block (0);
+  for (block =3D get_selected_block ();
        block !=3D NULL;
        block =3D block->superblock ())
     for (using_direct *current : block->get_using ())
@@ -1454,7 +1454,7 @@ static void
 add_symbol_overload_list_qualified (const char *func_name,
 				    std::vector<symbol *> *overload_list)
 {
-  const block *selected_block =3D get_selected_block (0);
+  const block *selected_block =3D get_selected_block ();
=20
   /* Search upwards from currently selected frame (so that we can
      complete on local vars.  */
diff --git a/gdb/eval.c b/gdb/eval.c
index 7e07765c9e6..6b2218cc629 100644
--- a/gdb/eval.c
+++ b/gdb/eval.c
@@ -753,7 +753,7 @@ scope_operation::evaluate_funcall (struct type *expect_=
type,
     {
       function =3D cp_lookup_symbol_namespace (type->name (),
 					     name.c_str (),
-					     get_selected_block (0),
+					     get_selected_block (),
 					     SEARCH_FUNCTION_DOMAIN).symbol;
       if (function =3D=3D NULL)
 	error (_("No symbol \"%s\" in namespace \"%s\"."),
@@ -799,7 +799,7 @@ scope_operation::evaluate_funcall (struct type *expect_=
type,
       find_overload_match (arg_view, nullptr,
 			   NON_METHOD, nullptr, function,
 			   nullptr, &symp, nullptr, 1, noside);
-      callee =3D value_of_variable (symp, get_selected_block (0));
+      callee =3D value_of_variable (symp, get_selected_block ());
     }
=20
   return evaluate_subexp_do_call (exp, noside, callee, arg_view,
diff --git a/gdb/f-valprint.c b/gdb/f-valprint.c
index 8a383281a6c..dcefc577425 100644
--- a/gdb/f-valprint.c
+++ b/gdb/f-valprint.c
@@ -551,7 +551,7 @@ f_language::value_print_inner (struct value *val, struc=
t ui_file *stream,
 		  /* While printing namelist items, fetch the appropriate
 		     value field before printing its value.  */
 		  struct block_symbol sym
-		    =3D lookup_symbol (field_name, get_selected_block (nullptr),
+		    =3D lookup_symbol (field_name, get_selected_block (),
 				     SEARCH_VFT, nullptr);
 		  if (sym.symbol =3D=3D nullptr)
 		    error (_("failed to find symbol for name list component %s"),
diff --git a/gdb/frame.h b/gdb/frame.h
index f6553fb7b6d..33a08b1403b 100644
--- a/gdb/frame.h
+++ b/gdb/frame.h
@@ -881,7 +881,8 @@ extern const struct block *get_frame_block (const frame=
_info_ptr &,
    it occurs in the CLI code and makes it possible for commands to
    work, even when the inferior has no state.  */
=20
-extern const struct block *get_selected_block (CORE_ADDR *addr_in_block);
+extern const struct block *get_selected_block
+  (CORE_ADDR *addr_in_block =3D nullptr);
=20
 extern struct symbol *get_frame_function (const frame_info_ptr &);
=20
diff --git a/gdb/linespec.c b/gdb/linespec.c
index fd7918df5a1..b6505ba283d 100644
--- a/gdb/linespec.c
+++ b/gdb/linespec.c
@@ -1184,7 +1184,7 @@ get_current_search_block (void)
   /* get_selected_block can change the current language when there is
      no selected frame yet.  */
   scoped_restore_current_language save_language;
-  return get_selected_block (0);
+  return get_selected_block ();
 }
=20
 /* Iterate over static and global blocks.  */
diff --git a/gdb/printcmd.c b/gdb/printcmd.c
index a337a6b7db9..662f43fbef8 100644
--- a/gdb/printcmd.c
+++ b/gdb/printcmd.c
@@ -2123,7 +2123,7 @@ do_one_display (struct display *d)
   if (d->block)
     {
       if (d->pspace =3D=3D current_program_space)
-	within_current_scope =3D d->block->contains (get_selected_block (0),
+	within_current_scope =3D d->block->contains (get_selected_block (),
 						   true);
       else
 	within_current_scope =3D 0;
@@ -2289,7 +2289,7 @@ Num Enb Expression\n"));
       else if (d->format.format)
 	gdb_printf ("/%c ", d->format.format);
       gdb_puts (d->exp_string.c_str ());
-      if (d->block && !d->block->contains (get_selected_block (0), true))
+      if (d->block && !d->block->contains (get_selected_block (), true))
 	gdb_printf (_(" (cannot be evaluated in the current context)"));
       gdb_printf ("\n");
     }
diff --git a/gdb/rust-lang.c b/gdb/rust-lang.c
index 517d6333d12..2a95c03178a 100644
--- a/gdb/rust-lang.c
+++ b/gdb/rust-lang.c
@@ -1746,7 +1746,7 @@ rust_structop::evaluate_funcall (struct type *expect_=
type,
   std::string name =3D (std::string (type->name ()) + "::"
 		      + std::get<1> (m_storage));
=20
-  const struct block *block =3D get_selected_block (0);
+  const struct block *block =3D get_selected_block ();
   struct block_symbol sym =3D lookup_symbol (name.c_str (), block,
 					   SEARCH_FUNCTION_DOMAIN,
 					   nullptr);
diff --git a/gdb/symtab.c b/gdb/symtab.c
index 4ca6f92ff9a..5d5076f2e77 100644
--- a/gdb/symtab.c
+++ b/gdb/symtab.c
@@ -5979,7 +5979,7 @@ default_collect_symbol_completion_matches_break_on
      this places which match our text string.  Only complete on types
      visible from current context.  */
=20
-  b =3D get_selected_block (0);
+  b =3D get_selected_block ();
   surrounding_static_block =3D b =3D=3D nullptr ? nullptr : b->static_bloc=
k ();
   surrounding_global_block =3D b =3D=3D nullptr ? nullptr : b->global_bloc=
k ();
   if (surrounding_static_block !=3D NULL)
diff --git a/gdb/valops.c b/gdb/valops.c
index ab6fd5079e1..76be9c58e6a 100644
--- a/gdb/valops.c
+++ b/gdb/valops.c
@@ -3813,7 +3813,7 @@ value_maybe_namespace_elt (const struct type *curtype,
   struct value *result;
=20
   sym =3D cp_lookup_symbol_namespace (namespace_name, name,
-				    get_selected_block (0), SEARCH_VFT);
+				    get_selected_block (), SEARCH_VFT);
=20
   if (sym.symbol =3D=3D NULL)
     return NULL;