• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

GNU Binutils with patches for OS216


Commit MetaInfo

Revisionce8ccaa665ee9c235dffc179f9e8fc047fad9548 (tree)
Time2019-11-21 13:11:40
AuthorAndrew Burgess <andrew.burgess@embe...>
CommiterSimon Marchi

Log Message

gdb: Split print_symbol_info into two parts

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

Change Summary

Incremental Difference

--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,13 @@
11 2019-11-01 Andrew Burgess <andrew.burgess@embecosm.com>
22
3+ * symtab.c (symbol_to_info_string): New function, most content
4+ moved from print_symbol_info, but updated to return a std::string.
5+ (print_symbol_info): Update to use symbol_to_info_string and print
6+ returned string.
7+ * symtab.h (symbol_to_info_string): Declare new function.
8+
9+2019-11-01 Andrew Burgess <andrew.burgess@embecosm.com>
10+
311 * python/python.c (gdbpy_rbreak): Convert to using
412 global_symbol_searcher.
513 * symtab.c (file_matches): Convert return type to bool, change
--- a/gdb/symtab.c
+++ b/gdb/symtab.c
@@ -4710,44 +4710,25 @@ global_symbol_searcher::search () const
47104710 return result;
47114711 }
47124712
4713-/* Helper function for symtab_symbol_info, this function uses
4714- the data returned from search_symbols() to print information
4715- regarding the match to gdb_stdout. If LAST is not NULL,
4716- print file and line number information for the symbol as
4717- well. Skip printing the filename if it matches LAST. */
4713+/* See symtab.h. */
47184714
4719-static void
4720-print_symbol_info (enum search_domain kind,
4721- struct symbol *sym,
4722- int block, const char *last)
4715+std::string
4716+symbol_to_info_string (struct symbol *sym, int block,
4717+ enum search_domain kind)
47234718 {
4724- scoped_switch_to_sym_language_if_auto l (sym);
4725- struct symtab *s = symbol_symtab (sym);
4719+ std::string str;
47264720
4727- if (last != NULL)
4728- {
4729- const char *s_filename = symtab_to_filename_for_display (s);
4730-
4731- if (filename_cmp (last, s_filename) != 0)
4732- {
4733- printf_filtered (_("\nFile %ps:\n"),
4734- styled_string (file_name_style.style (),
4735- s_filename));
4736- }
4737-
4738- if (SYMBOL_LINE (sym) != 0)
4739- printf_filtered ("%d:\t", SYMBOL_LINE (sym));
4740- else
4741- puts_filtered ("\t");
4742- }
4721+ gdb_assert (block == GLOBAL_BLOCK || block == STATIC_BLOCK);
47434722
47444723 if (kind != TYPES_DOMAIN && block == STATIC_BLOCK)
4745- printf_filtered ("static ");
4724+ str += "static ";
47464725
47474726 /* Typedef that is not a C++ class. */
47484727 if (kind == TYPES_DOMAIN
47494728 && SYMBOL_DOMAIN (sym) != STRUCT_DOMAIN)
47504729 {
4730+ string_file tmp_stream;
4731+
47514732 /* FIXME: For C (and C++) we end up with a difference in output here
47524733 between how a typedef is printed, and non-typedefs are printed.
47534734 The TYPEDEF_PRINT code places a ";" at the end in an attempt to
@@ -4757,28 +4738,69 @@ print_symbol_info (enum search_domain kind,
47574738 printing of the ";" in this function, which is going to be wrong
47584739 for languages that don't require a ";" between statements. */
47594740 if (TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_TYPEDEF)
4760- typedef_print (SYMBOL_TYPE (sym), sym, gdb_stdout);
4741+ typedef_print (SYMBOL_TYPE (sym), sym, &tmp_stream);
47614742 else
4762- type_print (SYMBOL_TYPE (sym), "", gdb_stdout, -1);
4763- printf_filtered ("\n");
4743+ type_print (SYMBOL_TYPE (sym), "", &tmp_stream, -1);
4744+ str += tmp_stream.string ();
47644745 }
47654746 /* variable, func, or typedef-that-is-c++-class. */
47664747 else if (kind < TYPES_DOMAIN
47674748 || (kind == TYPES_DOMAIN
47684749 && SYMBOL_DOMAIN (sym) == STRUCT_DOMAIN))
47694750 {
4751+ string_file tmp_stream;
4752+
47704753 type_print (SYMBOL_TYPE (sym),
47714754 (SYMBOL_CLASS (sym) == LOC_TYPEDEF
47724755 ? "" : SYMBOL_PRINT_NAME (sym)),
4773- gdb_stdout, 0);
4756+ &tmp_stream, 0);
47744757
4775- printf_filtered (";\n");
4758+ str += tmp_stream.string ();
4759+ str += ";";
47764760 }
4761+ else if (kind == MODULES_DOMAIN)
4762+ str += SYMBOL_PRINT_NAME (sym);
4763+
4764+ return str;
4765+}
4766+
4767+/* Helper function for symbol info commands, for example 'info functions',
4768+ 'info variables', etc. KIND is the kind of symbol we searched for, and
4769+ BLOCK is the type of block the symbols was found in, either GLOBAL_BLOCK
4770+ or STATIC_BLOCK. SYM is the symbol we found. If LAST is not NULL,
4771+ print file and line number information for the symbol as well. Skip
4772+ printing the filename if it matches LAST. */
4773+
4774+static void
4775+print_symbol_info (enum search_domain kind,
4776+ struct symbol *sym,
4777+ int block, const char *last)
4778+{
4779+ scoped_switch_to_sym_language_if_auto l (sym);
4780+ struct symtab *s = symbol_symtab (sym);
4781+
4782+ if (last != NULL)
4783+ {
4784+ const char *s_filename = symtab_to_filename_for_display (s);
4785+
4786+ if (filename_cmp (last, s_filename) != 0)
4787+ {
4788+ printf_filtered (_("\nFile %ps:\n"),
4789+ styled_string (file_name_style.style (),
4790+ s_filename));
4791+ }
4792+
4793+ if (SYMBOL_LINE (sym) != 0)
4794+ printf_filtered ("%d:\t", SYMBOL_LINE (sym));
4795+ else
4796+ puts_filtered ("\t");
4797+ }
4798+
47774799 /* Printing of modules is currently done here, maybe at some future
47784800 point we might want a language specific method to print the module
47794801 symbol so that we can customise the output more. */
4780- else if (kind == MODULES_DOMAIN)
4781- printf_filtered ("%s\n", SYMBOL_PRINT_NAME (sym));
4802+ std::string str = symbol_to_info_string (sym, block, kind);
4803+ printf_filtered ("%s\n", str.c_str ());
47824804 }
47834805
47844806 /* This help function for symtab_symbol_info() prints information
--- a/gdb/symtab.h
+++ b/gdb/symtab.h
@@ -2147,6 +2147,14 @@ extern std::vector<module_symbol_search> search_module_symbols
21472147 (const char *module_regexp, const char *regexp,
21482148 const char *type_regexp, search_domain kind);
21492149
2150+/* Convert a global or static symbol SYM (based on BLOCK, which should be
2151+ either GLOBAL_BLOCK or STATIC_BLOCK) into a string for use in 'info'
2152+ type commands (e.g. 'info variables', 'info functions', etc). KIND is
2153+ the type of symbol that was searched for which gave us SYM. */
2154+
2155+extern std::string symbol_to_info_string (struct symbol *sym, int block,
2156+ enum search_domain kind);
2157+
21502158 extern bool treg_matches_sym_type_name (const compiled_regex &treg,
21512159 const struct symbol *sym);
21522160