[v2,08/30] Simplify symbol_to_info_string

Message ID 20240118-submit-domain-hacks-2-v2-8-aecab29fa104@tromey.com
State New
Headers
Series Restructure symbol domains |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_gdb_build--master-aarch64 fail Patch failed to apply
linaro-tcwg-bot/tcwg_gdb_build--master-arm fail Patch failed to apply

Commit Message

Tom Tromey Jan. 18, 2024, 8:32 p.m. UTC
  Thi simplifies symbol_to_info_string, removing the 'kind' parameter
and instead having it use the symbol's domain.
---
 gdb/mi/mi-symbol-cmds.c |  2 +-
 gdb/symtab.c            | 44 ++++++++++++++++++--------------------------
 gdb/symtab.h            |  6 ++----
 3 files changed, 21 insertions(+), 31 deletions(-)
  

Patch

diff --git a/gdb/mi/mi-symbol-cmds.c b/gdb/mi/mi-symbol-cmds.c
index d3ec16fcb21..758f5974706 100644
--- a/gdb/mi/mi-symbol-cmds.c
+++ b/gdb/mi/mi-symbol-cmds.c
@@ -87,7 +87,7 @@  output_debug_symbol (ui_out *uiout, enum search_domain kind,
       type_print (sym->type (), "", &tmp_stream, -1);
       uiout->field_string ("type", tmp_stream.string ());
 
-      std::string str = symbol_to_info_string (sym, block, kind);
+      std::string str = symbol_to_info_string (sym, block);
       uiout->field_string ("description", str);
     }
 }
diff --git a/gdb/symtab.c b/gdb/symtab.c
index 7c0a69108d4..b408941f998 100644
--- a/gdb/symtab.c
+++ b/gdb/symtab.c
@@ -5054,19 +5054,19 @@  global_symbol_searcher::search () const
 /* See symtab.h.  */
 
 std::string
-symbol_to_info_string (struct symbol *sym, int block,
-		       enum search_domain kind)
+symbol_to_info_string (struct symbol *sym, int block)
 {
   std::string str;
 
   gdb_assert (block == GLOBAL_BLOCK || block == STATIC_BLOCK);
 
-  if (kind != TYPES_DOMAIN && block == STATIC_BLOCK)
+  if (block == STATIC_BLOCK
+      && sym->domain () == VAR_DOMAIN
+      && sym->aclass () != LOC_TYPEDEF)
     str += "static ";
 
   /* Typedef that is not a C++ class.  */
-  if (kind == TYPES_DOMAIN
-      && sym->domain () != STRUCT_DOMAIN)
+  if (sym->domain () == VAR_DOMAIN && sym->aclass () == LOC_TYPEDEF)
     {
       string_file tmp_stream;
 
@@ -5085,9 +5085,7 @@  symbol_to_info_string (struct symbol *sym, int block,
       str += tmp_stream.string ();
     }
   /* variable, func, or typedef-that-is-c++-class.  */
-  else if (kind < TYPES_DOMAIN
-	   || (kind == TYPES_DOMAIN
-	       && sym->domain () == STRUCT_DOMAIN))
+  else if (sym->domain () == VAR_DOMAIN || sym->domain () == STRUCT_DOMAIN)
     {
       string_file tmp_stream;
 
@@ -5102,23 +5100,21 @@  symbol_to_info_string (struct symbol *sym, int block,
   /* Printing of modules is currently done here, maybe at some future
      point we might want a language specific method to print the module
      symbol so that we can customise the output more.  */
-  else if (kind == MODULES_DOMAIN)
+  else if (sym->domain () == MODULE_DOMAIN)
     str += sym->print_name ();
 
   return str;
 }
 
-/* Helper function for symbol info commands, for example 'info functions',
-   'info variables', etc.  KIND is the kind of symbol we searched for, and
-   BLOCK is the type of block the symbols was found in, either GLOBAL_BLOCK
-   or STATIC_BLOCK.  SYM is the symbol we found.  If LAST is not NULL,
-   print file and line number information for the symbol as well.  Skip
-   printing the filename if it matches LAST.  */
+/* Helper function for symbol info commands, for example 'info
+   functions', 'info variables', etc.  BLOCK is the type of block the
+   symbols was found in, either GLOBAL_BLOCK or STATIC_BLOCK.  SYM is
+   the symbol we found.  If LAST is not NULL, print file and line
+   number information for the symbol as well.  Skip printing the
+   filename if it matches LAST.  */
 
 static void
-print_symbol_info (enum search_domain kind,
-		   struct symbol *sym,
-		   int block, const char *last)
+print_symbol_info (struct symbol *sym, int block, const char *last)
 {
   scoped_switch_to_sym_language_if_auto l (sym);
   struct symtab *s = sym->symtab ();
@@ -5140,7 +5136,7 @@  print_symbol_info (enum search_domain kind,
 	gdb_puts ("\t");
     }
 
-  std::string str = symbol_to_info_string (sym, block, kind);
+  std::string str = symbol_to_info_string (sym, block);
   gdb_printf ("%s\n", str.c_str ());
 }
 
@@ -5236,10 +5232,7 @@  symtab_symbol_info (bool quiet, bool exclude_minsyms,
 	}
       else
 	{
-	  print_symbol_info (kind,
-			     p.symbol,
-			     p.block,
-			     last_filename);
+	  print_symbol_info (p.symbol, p.block, last_filename);
 	  last_filename
 	    = symtab_to_filename_for_display (p.symbol->symtab ());
 	}
@@ -5475,7 +5468,7 @@  rbreak_command (const char *regexp, int from_tty)
 	  string = string_printf ("%s:'%s'", fullname,
 				  p.symbol->linkage_name ());
 	  break_command (&string[0], from_tty);
-	  print_symbol_info (FUNCTIONS_DOMAIN, p.symbol, p.block, NULL);
+	  print_symbol_info (p.symbol, p.block, nullptr);
 	}
       else
 	{
@@ -6838,8 +6831,7 @@  info_module_subcommand (bool quiet, const char *module_regexp,
 	  last_filename = "";
 	}
 
-      print_symbol_info (FUNCTIONS_DOMAIN, q.symbol, q.block,
-			 last_filename);
+      print_symbol_info (q.symbol, q.block, last_filename);
       last_filename
 	= symtab_to_filename_for_display (q.symbol->symtab ());
     }
diff --git a/gdb/symtab.h b/gdb/symtab.h
index 3f2d98add1e..0a5f2633fe8 100644
--- a/gdb/symtab.h
+++ b/gdb/symtab.h
@@ -2664,11 +2664,9 @@  extern std::vector<module_symbol_search> search_module_symbols
 
 /* Convert a global or static symbol SYM (based on BLOCK, which should be
    either GLOBAL_BLOCK or STATIC_BLOCK) into a string for use in 'info'
-   type commands (e.g. 'info variables', 'info functions', etc).  KIND is
-   the type of symbol that was searched for which gave us SYM.  */
+   type commands (e.g. 'info variables', 'info functions', etc).  */
 
-extern std::string symbol_to_info_string (struct symbol *sym, int block,
-					  enum search_domain kind);
+extern std::string symbol_to_info_string (struct symbol *sym, int block);
 
 extern bool treg_matches_sym_type_name (const compiled_regex &treg,
 					const struct symbol *sym);