diff options
author | Andrew Burgess <andrew.burgess@embecosm.com> | 2019-10-15 00:02:51 +0100 |
---|---|---|
committer | Andrew Burgess <andrew.burgess@embecosm.com> | 2019-12-04 10:25:13 +0000 |
commit | c2512106f8942dfa944c75add9b9107e28ef0018 (patch) | |
tree | cba039884c22367bad8de1fe445c692cafeb2189 /gdb/mi | |
parent | f97a63c5aa5203994447b3cf8e48f184078f379b (diff) | |
download | gdb-c2512106f8942dfa944c75add9b9107e28ef0018.zip gdb-c2512106f8942dfa944c75add9b9107e28ef0018.tar.gz gdb-c2512106f8942dfa944c75add9b9107e28ef0018.tar.bz2 |
gdb/mi: Add -max-results parameter to some -symbol-info-* commands
Adds a new parameter -max-results to -symbol-info-functions,
-symbol-info-variables, -symbol-info-types, and -symbol-info-modules.
This parameter limits the number of results returned.
This change still leaves -symbol-info-module-functions and
-symbol-info-module-variables always returning all results, fixing
these commands is slightly harder.
There's currently no mechanism for the user of these commands to know
if the result list has been truncated if you get back the maximum
number of results, so if there are exactly 10 functions and you call
'-symbol-info-functions --max-results 10' the reply would appear no
different than if you had 20 functions and called with a max of 10.
Right now, if you get back the maximum then you should assume that
there might be more results available.
One other thing to note is that the global_symbol_searcher::search by
default returns SIZE_MAX results, there's no longer a mechanism to
return an unlimited number of results, though hopefully this will not
be a huge issue.
gdb/ChangeLog:
* mi/mi-symbol-cmds.c (mi_symbol_info): Take extra parameter, and
add it into the search spec.
(parse_max_results_option): New function.
(mi_info_functions_or_variables): Parse -max-results flag and pass
it to mi_symbol_info.
(mi_cmd_symbol_info_modules): Likewise.
(mi_cmd_symbol_info_types): Likewise.
* symtab.c (global_symbol_searcher::add_matching_symbols): Change
return type to bool, change result container into a set, and don't
add new results if we have enough already.
(global_symbol_searcher::add_matching_msymbols): Change return
type to bool, and don't add new results if we have enough already.
(sort_search_symbols_remove_dups): Delete.
(global_symbol_searcher::search): Early exit from search loop when
we have enough results. Use a std::set to collect the results
from calling add_matching_symbols.
* symtab.h (global_symbol_searcher) <set_max_seach_results>: New
member function.
(global_symbol_searcher) <m_max_search_results>: New member
variable.
(global_symbol_searcher) <add_matching_symbols>: Update header
comment and change return type to bool.
(global_symbol_searcher) <add_matching_msymbols>: Update header
comment and change return type to bool.
gdb/doc/ChangeLog:
* doc/gdb.texinfo (GDB/MI Symbol Query): Add documentation of
-max-results to some -symbol-info-* commands.
gdb/testsuite/ChangeLog:
* gdb.mi/mi-sym-info.exp: Add tests for -max-results parameter.
Change-Id: I90a28feb55b388fb46461a096c5db08b6b0bd427
Diffstat (limited to 'gdb/mi')
-rw-r--r-- | gdb/mi/mi-symbol-cmds.c | 46 |
1 files changed, 39 insertions, 7 deletions
diff --git a/gdb/mi/mi-symbol-cmds.c b/gdb/mi/mi-symbol-cmds.c index 2bebd11..edbafe3 100644 --- a/gdb/mi/mi-symbol-cmds.c +++ b/gdb/mi/mi-symbol-cmds.c @@ -111,11 +111,13 @@ output_nondebug_symbol (ui_out *uiout, static void mi_symbol_info (enum search_domain kind, const char *name_regexp, - const char *type_regexp, bool exclude_minsyms) + const char *type_regexp, bool exclude_minsyms, + size_t max_results) { global_symbol_searcher sym_search (kind, name_regexp); sym_search.set_symbol_type_regexp (type_regexp); sym_search.set_exclude_minsyms (exclude_minsyms); + sym_search.set_max_search_results (max_results); std::vector<symbol_search> symbols = sym_search.search (); ui_out *uiout = current_uiout; int i = 0; @@ -166,25 +168,42 @@ mi_symbol_info (enum search_domain kind, const char *name_regexp, } } +/* Helper to parse the option text from an -max-results argument and return + the parsed value. If the text can't be parsed then an error is thrown. */ + +static size_t +parse_max_results_option (char *arg) +{ + char *ptr = arg; + long long val = strtoll (arg, &ptr, 10); + if (arg == ptr || *ptr != '\0' || val > SIZE_MAX || val < 0) + error (_("invalid value for --max-results argument")); + size_t max_results = (size_t) val; + + return max_results; +} + /* Helper for mi_cmd_symbol_info_{functions,variables} - depending on KIND. Processes command line options from ARGV and ARGC. */ static void mi_info_functions_or_variables (enum search_domain kind, char **argv, int argc) { + size_t max_results = SIZE_MAX; const char *regexp = nullptr; const char *t_regexp = nullptr; bool exclude_minsyms = true; enum opt { - INCLUDE_NONDEBUG_OPT, TYPE_REGEXP_OPT, NAME_REGEXP_OPT + INCLUDE_NONDEBUG_OPT, TYPE_REGEXP_OPT, NAME_REGEXP_OPT, MAX_RESULTS_OPT }; static const struct mi_opt opts[] = { {"-include-nondebug" , INCLUDE_NONDEBUG_OPT, 0}, {"-type", TYPE_REGEXP_OPT, 1}, {"-name", NAME_REGEXP_OPT, 1}, + {"-max-results", MAX_RESULTS_OPT, 1}, { 0, 0, 0 } }; @@ -210,10 +229,13 @@ mi_info_functions_or_variables (enum search_domain kind, char **argv, int argc) case NAME_REGEXP_OPT: regexp = oarg; break; + case MAX_RESULTS_OPT: + max_results = parse_max_results_option (oarg); + break; } } - mi_symbol_info (kind, regexp, t_regexp, exclude_minsyms); + mi_symbol_info (kind, regexp, t_regexp, exclude_minsyms, max_results); } /* Type for an iterator over a vector of module_symbol_search results. */ @@ -384,15 +406,17 @@ mi_cmd_symbol_info_module_variables (const char *command, char **argv, void mi_cmd_symbol_info_modules (const char *command, char **argv, int argc) { + size_t max_results = SIZE_MAX; const char *regexp = nullptr; enum opt { - NAME_REGEXP_OPT + NAME_REGEXP_OPT, MAX_RESULTS_OPT }; static const struct mi_opt opts[] = { {"-name", NAME_REGEXP_OPT, 1}, + {"-max-results", MAX_RESULTS_OPT, 1}, { 0, 0, 0 } }; @@ -410,10 +434,13 @@ mi_cmd_symbol_info_modules (const char *command, char **argv, int argc) case NAME_REGEXP_OPT: regexp = oarg; break; + case MAX_RESULTS_OPT: + max_results = parse_max_results_option (oarg); + break; } } - mi_symbol_info (MODULES_DOMAIN, regexp, nullptr, true); + mi_symbol_info (MODULES_DOMAIN, regexp, nullptr, true, max_results); } /* Implement -symbol-info-types command. */ @@ -421,15 +448,17 @@ mi_cmd_symbol_info_modules (const char *command, char **argv, int argc) void mi_cmd_symbol_info_types (const char *command, char **argv, int argc) { + size_t max_results = SIZE_MAX; const char *regexp = nullptr; enum opt { - NAME_REGEXP_OPT + NAME_REGEXP_OPT, MAX_RESULTS_OPT }; static const struct mi_opt opts[] = { {"-name", NAME_REGEXP_OPT, 1}, + {"-max-results", MAX_RESULTS_OPT, 1}, { 0, 0, 0 } }; @@ -447,10 +476,13 @@ mi_cmd_symbol_info_types (const char *command, char **argv, int argc) case NAME_REGEXP_OPT: regexp = oarg; break; + case MAX_RESULTS_OPT: + max_results = parse_max_results_option (oarg); + break; } } - mi_symbol_info (TYPES_DOMAIN, regexp, nullptr, true); + mi_symbol_info (TYPES_DOMAIN, regexp, nullptr, true, max_results); } /* Implement -symbol-info-variables command. */ |