From patchwork Tue Nov 26 23:25:46 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Simon Marchi (Code Review)" X-Patchwork-Id: 36281 Received: (qmail 21946 invoked by alias); 26 Nov 2019 23:25:56 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 21930 invoked by uid 89); 26 Nov 2019 23:25:56 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-20.8 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_STOCKGEN autolearn=ham version=3.3.1 spammy= X-HELO: mx1.osci.io Received: from polly.osci.io (HELO mx1.osci.io) (8.43.85.229) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 26 Nov 2019 23:25:54 +0000 Received: by mx1.osci.io (Postfix, from userid 994) id DCD0720373; Tue, 26 Nov 2019 18:25:52 -0500 (EST) Received: from gnutoolchain-gerrit.osci.io (gnutoolchain-gerrit.osci.io [8.43.85.239]) by mx1.osci.io (Postfix) with ESMTP id D9538201F1; Tue, 26 Nov 2019 18:25:48 -0500 (EST) Received: from localhost (localhost [127.0.0.1]) by gnutoolchain-gerrit.osci.io (Postfix) with ESMTP id B3E9F28173; Tue, 26 Nov 2019 18:25:48 -0500 (EST) X-Gerrit-PatchSet: 6 Date: Tue, 26 Nov 2019 18:25:46 -0500 From: "Andrew Burgess (Code Review)" To: Tom Tromey , Simon Marchi , gdb-patches@sourceware.org Cc: Joel Brobecker Auto-Submitted: auto-generated X-Gerrit-MessageType: newpatchset Subject: [review v6] gdb: Split print_symbol_info into two parts X-Gerrit-Change-Id: I6454ce43cacb61d32fbadb9e3655e70823085777 X-Gerrit-Change-Number: 265 X-Gerrit-ChangeURL: X-Gerrit-Commit: 7d6915d773285511beafb9d09415f12f42bb2aaa In-Reply-To: References: Reply-To: andrew.burgess@embecosm.com, simon.marchi@polymtl.ca, tromey@sourceware.org, brobecker@adacore.com, gdb-patches@sourceware.org MIME-Version: 1.0 Content-Disposition: inline User-Agent: Gerrit/3.0.3-79-g83ff7f88f1 Message-Id: <20191126232548.B3E9F28173@gnutoolchain-gerrit.osci.io> Change URL: https://gnutoolchain-gerrit.osci.io/r/c/binutils-gdb/+/265 ...................................................................... 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 --- M gdb/ChangeLog M gdb/symtab.c M gdb/symtab.h 3 files changed, 81 insertions(+), 43 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index b71f660..49c95ad 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,5 +1,13 @@ 2019-11-26 Andrew Burgess + * 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-26 Andrew Burgess + * python/python.c (gdbpy_rbreak): Convert to using global_symbol_searcher. * symtab.c (file_matches): Convert return type to bool, change diff --git a/gdb/symtab.c b/gdb/symtab.c index a758192..89160ad 100644 --- a/gdb/symtab.c +++ b/gdb/symtab.c @@ -4709,11 +4709,69 @@ 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. */ + +std::string +symbol_to_info_string (struct symbol *sym, int block, + enum search_domain kind) +{ + std::string str; + + gdb_assert (block == GLOBAL_BLOCK || block == STATIC_BLOCK); + + if (kind != TYPES_DOMAIN && block == STATIC_BLOCK) + 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 + appear C-like, while TYPE_PRINT doesn't. + + For the struct printing case below, things are worse, we force + 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, &tmp_stream); + else + 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 ()), + &tmp_stream, 0); + + 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) + 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, @@ -4740,44 +4798,8 @@ puts_filtered ("\t"); } - if (kind != TYPES_DOMAIN && block == STATIC_BLOCK) - printf_filtered ("static "); - - /* Typedef that is not a C++ class. */ - if (kind == TYPES_DOMAIN - && SYMBOL_DOMAIN (sym) != STRUCT_DOMAIN) - { - /* 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 - appear C-like, while TYPE_PRINT doesn't. - - For the struct printing case below, things are worse, we force - 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); - else - type_print (SYMBOL_TYPE (sym), "", gdb_stdout, -1); - printf_filtered ("\n"); - } - /* variable, func, or typedef-that-is-c++-class. */ - else if (kind < TYPES_DOMAIN - || (kind == TYPES_DOMAIN - && SYMBOL_DOMAIN (sym) == STRUCT_DOMAIN)) - { - type_print (SYMBOL_TYPE (sym), - (SYMBOL_CLASS (sym) == LOC_TYPEDEF - ? "" : sym->print_name ()), - gdb_stdout, 0); - - printf_filtered (";\n"); - } - /* 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 ()); + 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 105b93c..efb55b2 100644 --- a/gdb/symtab.h +++ b/gdb/symtab.h @@ -2126,6 +2126,14 @@ (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);