Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [PATCH] [gdb] Add default argument for get_selected_block
@ 2026-07-17  7:09 Tom de Vries
  2026-07-17 14:29 ` Tom Tromey
  0 siblings, 1 reply; 2+ messages in thread
From: Tom de Vries @ 2026-07-17  7:09 UTC (permalink / raw)
  To: gdb-patches

I noticed that the get_selected_block argument is mostly 0, NULL, or nullptr.

Make nullptr the default argument.
---
 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"));
 
   if (orig_left_context == NULL)
-    orig_left_context = get_selected_block (NULL);
+    orig_left_context = get_selected_block ();
 
   name = obstack_strndup (&ada_parser->temp_space, renamed_entity,
 			  renamed_entity_len);
diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index 85b08af8c06..6ec99447d34 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -7412,7 +7412,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);
 }
 
@@ -11425,7 +11425,7 @@ get_var_value (const char *name, const char *err_msg)
 
   std::vector<struct block_symbol> syms
     = ada_lookup_symbol_list_worker (lookup_name,
-				     get_selected_block (0),
+				     get_selected_block (),
 				     SEARCH_VFT, true);
 
   if (syms.size () != 1)
@@ -13741,7 +13741,7 @@ class ada_language : public language_defn
     /* Search upwards from currently selected frame (so that we can
        complete on local vars.  */
 
-    for (const block *b = get_selected_block (0);
+    for (const block *b = get_selected_block ();
 	 b != nullptr;
 	 b = 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,
     }
 
   /* Look in the static block.  */
-  block = get_selected_block (0);
+  block = get_selected_block ();
   block = block == nullptr ? nullptr : block->static_block ();
   if (block != 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.  */
 
-  for (block = get_selected_block (0);
+  for (block = get_selected_block ();
        block != NULL;
        block = 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 = get_selected_block (0);
+  const block *selected_block = get_selected_block ();
 
   /* 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 = cp_lookup_symbol_namespace (type->name (),
 					     name.c_str (),
-					     get_selected_block (0),
+					     get_selected_block (),
 					     SEARCH_FUNCTION_DOMAIN).symbol;
       if (function == 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 = value_of_variable (symp, get_selected_block (0));
+      callee = value_of_variable (symp, get_selected_block ());
     }
 
   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, struct ui_file *stream,
 		  /* While printing namelist items, fetch the appropriate
 		     value field before printing its value.  */
 		  struct block_symbol sym
-		    = lookup_symbol (field_name, get_selected_block (nullptr),
+		    = lookup_symbol (field_name, get_selected_block (),
 				     SEARCH_VFT, nullptr);
 		  if (sym.symbol == nullptr)
 		    error (_("failed to find symbol for name list component %s"),
diff --git a/gdb/frame.h b/gdb/frame.h
index f6553fb7b6d..7ee85fd9851 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.  */
 
-extern const struct block *get_selected_block (CORE_ADDR *addr_in_block);
+extern const struct block *get_selected_block (CORE_ADDR *addr_in_block
+					       = nullptr);
 
 extern struct symbol *get_frame_function (const frame_info_ptr &);
 
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 ();
 }
 
 /* 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 == current_program_space)
-	within_current_scope = d->block->contains (get_selected_block (0),
+	within_current_scope = d->block->contains (get_selected_block (),
 						   true);
       else
 	within_current_scope = 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 = (std::string (type->name ()) + "::"
 		      + std::get<1> (m_storage));
 
-  const struct block *block = get_selected_block (0);
+  const struct block *block = get_selected_block ();
   struct block_symbol sym = 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.  */
 
-  b = get_selected_block (0);
+  b = get_selected_block ();
   surrounding_static_block = b == nullptr ? nullptr : b->static_block ();
   surrounding_global_block = b == nullptr ? nullptr : b->global_block ();
   if (surrounding_static_block != 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;
 
   sym = cp_lookup_symbol_namespace (namespace_name, name,
-				    get_selected_block (0), SEARCH_VFT);
+				    get_selected_block (), SEARCH_VFT);
 
   if (sym.symbol == NULL)
     return NULL;

base-commit: d36b7ef85a30cda5ea19110920f61727be2fd984
-- 
2.51.0


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] [gdb] Add default argument for get_selected_block
  2026-07-17  7:09 [PATCH] [gdb] Add default argument for get_selected_block Tom de Vries
@ 2026-07-17 14:29 ` Tom Tromey
  0 siblings, 0 replies; 2+ messages in thread
From: Tom Tromey @ 2026-07-17 14:29 UTC (permalink / raw)
  To: Tom de Vries; +Cc: gdb-patches

>>>>> "Tom" == Tom de Vries <tdevries@suse.de> writes:

Tom> I noticed that the get_selected_block argument is mostly 0, NULL, or nullptr.
Tom> Make nullptr the default argument.

Ok.
Approved-By: Tom Tromey <tom@tromey.com>

Tom

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-07-17 14:30 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-07-17  7:09 [PATCH] [gdb] Add default argument for get_selected_block Tom de Vries
2026-07-17 14:29 ` Tom Tromey

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox