gdb: Split print_symbol_info into two parts
authorAndrew Burgess <andrew.burgess@embecosm.com>
Tue, 24 Sep 2019 22:22:05 +0000 (23:22 +0100)
committerAndrew Burgess <andrew.burgess@embecosm.com>
Wed, 27 Nov 2019 12:01:48 +0000 (12:01 +0000)
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.

Change-Id: I6454ce43cacb61d32fbadb9e3655e70823085777

gdb/ChangeLog
gdb/symtab.c
gdb/symtab.h

index 56536c459ee559d4abe37523a749ea7bf57af9e1..63e0519c547c7eda7ce0eecc32eb1bb4f40d82a3 100644 (file)
@@ -1,3 +1,11 @@
+2019-11-27  Andrew Burgess  <andrew.burgess@embecosm.com>
+
+       * 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.
+
 2019-11-27  Andrew Burgess  <andrew.burgess@embecosm.com>
 
        * python/python.c (gdbpy_rbreak): Convert to using
index e5ed42a49b6d35b7e9d027fb1f75151b1de4d47d..8f46321f43d79019446180e62296d3f6a7c0a4d0 100644 (file)
@@ -4712,44 +4712,25 @@ global_symbol_searcher::search () const
   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);
-
-      if (filename_cmp (last, s_filename) != 0)
-       {
-         printf_filtered (_("\nFile %ps:\n"),
-                          styled_string (file_name_style.style (),
-                                         s_filename));
-       }
+  std::string str;
 
-      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
@@ -4759,28 +4740,69 @@ 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
                   ? "" : sym->print_name ()),
-                 gdb_stdout, 0);
+                 &tmp_stream, 0);
 
-      printf_filtered (";\n");
+      str += tmp_stream.string ();
+      str += ";";
     }
   /* 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)
-    printf_filtered ("%s\n", sym->print_name ());
+    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.  */
+
+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)
+       {
+         printf_filtered (_("\nFile %ps:\n"),
+                          styled_string (file_name_style.style (),
+                                         s_filename));
+       }
+
+      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
index 680c334086b7f0435357ec4fd3e3f3c43e307283..a52f2a5db2e11147c8536c8fd62c80c983a672b7 100644 (file)
@@ -2140,6 +2140,14 @@ extern std::vector<module_symbol_search> search_module_symbols
        (const char *module_regexp, const char *regexp,
         const char *type_regexp, search_domain kind);
 
+/* 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.  */
+
+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);
 
This page took 0.034395 seconds and 4 git commands to generate.