public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Tom Tromey <tom@tromey.com>
To: gdb-patches@sourceware.org
Subject: [PATCH 07/29] Simplify symbol_to_info_string
Date: Mon, 20 Nov 2023 20:53:38 -0700	[thread overview]
Message-ID: <20231120-submit-domain-hacks-2-v1-7-29650d01b198@tromey.com> (raw)
In-Reply-To: <20231120-submit-domain-hacks-2-v1-0-29650d01b198@tromey.com>

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(-)

diff --git a/gdb/mi/mi-symbol-cmds.c b/gdb/mi/mi-symbol-cmds.c
index d26378e8310..7492d007fba 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 5ec56f4f2af..6abebcd929c 100644
--- a/gdb/symtab.c
+++ b/gdb/symtab.c
@@ -4957,19 +4957,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;
 
@@ -4988,9 +4988,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;
 
@@ -5005,23 +5003,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 ();
@@ -5043,7 +5039,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 ());
 }
 
@@ -5139,10 +5135,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 ());
 	}
@@ -5378,7 +5371,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
 	{
@@ -6739,8 +6732,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 21c84cbe006..71d37e84a43 100644
--- a/gdb/symtab.h
+++ b/gdb/symtab.h
@@ -2639,11 +2639,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);

-- 
2.41.0


  parent reply	other threads:[~2023-11-21  3:53 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-21  3:53 [PATCH 00/29] Restructure symbol domains Tom Tromey
2023-11-21  3:53 ` [PATCH 01/29] Fix bug in cooked index scanner Tom Tromey
2023-11-21  3:53 ` [PATCH 02/29] Small cleanup in DWARF reader Tom Tromey
2023-11-21  3:53 ` [PATCH 03/29] Make nsalias.exp more reliable Tom Tromey
2023-11-21  3:53 ` [PATCH 04/29] Fix latent bug in mdebugread.c Tom Tromey
2023-11-21  3:53 ` [PATCH 05/29] Give names to unspecified types Tom Tromey
2023-11-21  3:53 ` [PATCH 06/29] Remove NR_DOMAINS Tom Tromey
2023-11-21  3:53 ` Tom Tromey [this message]
2023-11-21  3:53 ` [PATCH 08/29] Split up a big 'if' in symtab.c Tom Tromey
2023-11-21  3:53 ` [PATCH 09/29] Use a .def file for domain_enum Tom Tromey
2023-11-21  3:53 ` [PATCH 10/29] Add two new symbol domains Tom Tromey
2023-11-21  3:53 ` [PATCH 11/29] Add domain_search_flags Tom Tromey
2023-11-21  3:53 ` [PATCH 12/29] Replace search_domain with domain_search_flags Tom Tromey
2023-11-21  3:53 ` [PATCH 13/29] Remove a check of VAR_DOMAIN Tom Tromey
2023-11-21  3:53 ` [PATCH 14/29] Introduce "scripting" domains Tom Tromey
2023-11-21  3:53 ` [PATCH 15/29] Use domain_search_flags in lookup_global_symbol_language Tom Tromey
2023-11-21  3:53 ` [PATCH 16/29] Use domain_search_flags in lookup_symbol et al Tom Tromey
2023-11-21  3:53 ` [PATCH 17/29] Remove some obsolete Python constants Tom Tromey
2023-11-21  3:53 ` [PATCH 18/29] Remove old symbol_matches_domain Tom Tromey
2023-11-21  3:53 ` [PATCH 19/29] Use the new symbol domains Tom Tromey
2023-11-21  3:53 ` [PATCH 20/29] Simplify some symbol searches in Ada code Tom Tromey
2023-11-21  3:53 ` [PATCH 21/29] Simplify some symbol searches in linespec.c Tom Tromey
2023-11-21  3:53 ` [PATCH 22/29] Only search for "main" as a function Tom Tromey
2023-11-21  3:53 ` [PATCH 23/29] Only look for functions in expand_symtabs_for_function Tom Tromey
2023-11-21  3:53 ` [PATCH 24/29] Use a function-domain search in inside_main_func Tom Tromey
2023-11-21  3:53 ` [PATCH 25/29] Only search types in cp_lookup_rtti_type Tom Tromey
2023-11-21  3:53 ` [PATCH 26/29] Only search types in lookup_typename Tom Tromey
2023-11-21  3:53 ` [PATCH 27/29] Only search for functions in rust_structop::evaluate_funcall Tom Tromey
2023-11-21  3:53 ` [PATCH 28/29] Refine search in cp_search_static_and_baseclasses Tom Tromey
2023-11-21  3:54 ` [PATCH 29/29] Document new Python and Guile constants Tom Tromey
2023-11-21 11:39   ` Eli Zaretskii
2024-01-23  0:34     ` Tom Tromey
2024-01-23 18:11       ` Eli Zaretskii
2023-11-21 18:37 ` [PATCH 00/29] Restructure symbol domains John Baldwin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20231120-submit-domain-hacks-2-v1-7-29650d01b198@tromey.com \
    --to=tom@tromey.com \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).