Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Andrew Burgess <andrew.burgess@embecosm.com>
To: gdb-patches <gdb-patches@sourceware.org>
Cc: Andrew Burgess <andrew.burgess@embecosm.com>
Subject: [PATCH 2/3] gdb: Split print_symbol_info into two parts
Date: Thu, 26 Sep 2019 23:09:00 -0000	[thread overview]
Message-ID: <c53834289016a8394c1b61ba4c9e3fde88e2acc0.1569539198.git.andrew.burgess@embecosm.com> (raw)
In-Reply-To: <cover.1569539198.git.andrew.burgess@embecosm.com>
In-Reply-To: <cover.1569539198.git.andrew.burgess@embecosm.com>

Split the function print_symbol_info into two parts, the new worker
core returns a string, which print_symbol_info then prints.  This will
be useful in a later commit when some new MI commands will be added
which will use the worker core to fill some MI output fields.

There should be no user visible changes after this commit.

gdb/ChangeLog:

	* symtab.c (symbol_to_info_string): New function, most content
	moved from print_symbol_info, but updated to return a std::string.
	(print_symbol_info): Update to use symbol_to_info_string and print
	returned string.
	* symtab.h (symbol_to_info_string): Declare new function.
---
 gdb/ChangeLog |  8 ++++++
 gdb/symtab.c  | 87 ++++++++++++++++++++++++++++++++++++-----------------------
 gdb/symtab.h  |  8 ++++++
 3 files changed, 70 insertions(+), 33 deletions(-)

diff --git a/gdb/symtab.c b/gdb/symtab.c
index b4316479f53..5f5bbbb33cb 100644
--- a/gdb/symtab.c
+++ b/gdb/symtab.c
@@ -4728,44 +4728,25 @@ search_symbols (const char *regexp, enum search_domain kind,
   return result;
 }
 
-/* Helper function for symtab_symbol_info, this function uses
-   the data returned from search_symbols() to print information
-   regarding the match to gdb_stdout.  If LAST is not NULL,
-   print file and line number information for the symbol as
-   well.  Skip printing the filename if it matches LAST.  */
+/* See symtab.h.  */
 
-static void
-print_symbol_info (enum search_domain kind,
-		   struct symbol *sym,
-		   int block, const char *last)
+std::string
+symbol_to_info_string (struct symbol *sym, int block,
+		       enum search_domain kind)
 {
-  scoped_switch_to_sym_language_if_auto l (sym);
-  struct symtab *s = symbol_symtab (sym);
-
-  if (last != NULL)
-    {
-      const char *s_filename = symtab_to_filename_for_display (s);
+  std::string str;
 
-      if (filename_cmp (last, s_filename) != 0)
-	{
-	  fputs_filtered ("\nFile ", gdb_stdout);
-	  fputs_styled (s_filename, file_name_style.style (), gdb_stdout);
-	  fputs_filtered (":\n", gdb_stdout);
-	}
-
-      if (SYMBOL_LINE (sym) != 0)
-	printf_filtered ("%d:\t", SYMBOL_LINE (sym));
-      else
-	puts_filtered ("\t");
-    }
+  gdb_assert (block == GLOBAL_BLOCK || block == STATIC_BLOCK);
 
   if (kind != TYPES_DOMAIN && block == STATIC_BLOCK)
-    printf_filtered ("static ");
+    str += "static ";
 
   /* Typedef that is not a C++ class.  */
   if (kind == TYPES_DOMAIN
       && SYMBOL_DOMAIN (sym) != STRUCT_DOMAIN)
     {
+      string_file tmp_stream;
+
       /* FIXME: For C (and C++) we end up with a difference in output here
 	 between how a typedef is printed, and non-typedefs are printed.
 	 The TYPEDEF_PRINT code places a ";" at the end in an attempt to
@@ -4775,23 +4756,63 @@ print_symbol_info (enum search_domain kind,
 	 printing of the ";" in this function, which is going to be wrong
 	 for languages that don't require a ";" between statements.  */
       if (TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_TYPEDEF)
-	typedef_print (SYMBOL_TYPE (sym), sym, gdb_stdout);
+	typedef_print (SYMBOL_TYPE (sym), sym, &tmp_stream);
       else
-	type_print (SYMBOL_TYPE (sym), "", gdb_stdout, -1);
-      printf_filtered ("\n");
+	type_print (SYMBOL_TYPE (sym), "", &tmp_stream, -1);
+      str += tmp_stream.string ();
     }
   /* variable, func, or typedef-that-is-c++-class.  */
   else if (kind < TYPES_DOMAIN
 	   || (kind == TYPES_DOMAIN
 	       && SYMBOL_DOMAIN (sym) == STRUCT_DOMAIN))
     {
+      string_file tmp_stream;
+
       type_print (SYMBOL_TYPE (sym),
 		  (SYMBOL_CLASS (sym) == LOC_TYPEDEF
 		   ? "" : SYMBOL_PRINT_NAME (sym)),
-		  gdb_stdout, 0);
+		  &tmp_stream, 0);
+
+      str += tmp_stream.string ();
+      str += ";";
+    }
 
-      printf_filtered (";\n");
+  return str;
+}
+
+/* Helper function for symtab_symbol_info, this function uses
+   the data returned from search_symbols() to print information
+   regarding the match to gdb_stdout.  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)
+{
+  scoped_switch_to_sym_language_if_auto l (sym);
+  struct symtab *s = symbol_symtab (sym);
+
+  if (last != NULL)
+    {
+      const char *s_filename = symtab_to_filename_for_display (s);
+
+      if (filename_cmp (last, s_filename) != 0)
+	{
+	  fputs_filtered ("\nFile ", gdb_stdout);
+	  fputs_styled (s_filename, file_name_style.style (), gdb_stdout);
+	  fputs_filtered (":\n", gdb_stdout);
+	}
+
+      if (SYMBOL_LINE (sym) != 0)
+	printf_filtered ("%d:\t", SYMBOL_LINE (sym));
+      else
+	puts_filtered ("\t");
     }
+
+  std::string str = symbol_to_info_string (sym, block, kind);
+  printf_filtered ("%s\n", str.c_str ());
 }
 
 /* This help function for symtab_symbol_info() prints information
diff --git a/gdb/symtab.h b/gdb/symtab.h
index 1f0fc62a657..f5da8229f2f 100644
--- a/gdb/symtab.h
+++ b/gdb/symtab.h
@@ -2029,6 +2029,14 @@ extern std::vector<symbol_search> search_symbols (const char *,
 						  int,
 						  const char **,
 						  bool);
+
+/* Helper for print_symbol_info, return a string that describes SYM.
+   BLOCK is either GLOBAL_BLOCK or STATIC_BLOCK, and KIND is the type of
+   symbol that was searched for.  */
+
+extern std::string symbol_to_info_string (struct symbol *sym, int block,
+					  enum search_domain kind);
+
 extern bool treg_matches_sym_type_name (const compiled_regex &treg,
 					const struct symbol *sym);
 
-- 
2.14.5


  parent reply	other threads:[~2019-09-26 23:09 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-09-26 23:09 [PATCH 0/3] New MI commands for info functions/types/variables Andrew Burgess
2019-09-26 23:09 ` [PATCH 3/3] gdb/mi: Add new commands -symbol-info-{functions,variables,types} Andrew Burgess
2019-09-27  5:43   ` Eli Zaretskii
2019-10-04  3:01   ` Simon Marchi
2019-10-04 13:46     ` André Pönitz
2019-10-11 12:32     ` Andrew Burgess
2019-09-26 23:09 ` Andrew Burgess [this message]
2019-10-04  1:50   ` [PATCH 2/3] gdb: Split print_symbol_info into two parts Simon Marchi
2019-09-26 23:09 ` [PATCH 1/3] gdb: Don't print a newline in language la_print_typedef methods Andrew Burgess

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=c53834289016a8394c1b61ba4c9e3fde88e2acc0.1569539198.git.andrew.burgess@embecosm.com \
    --to=andrew.burgess@embecosm.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