gdb: add lookup_cmd_exact to simplify a common pattern

In code dealing with commands, there's a pattern repeated a few times of
calling lookup_cmd with some speficic arguments and then using strcmp
on the returned command to check for an exact match.
As a later patch would add a few more similar lines of code, this patch
adds a new lookup_cmd_exact function which simplify this use case.

gdb/ChangeLog:

	* cli/cli-decode.c (lookup_cmd_exact): Add.
	* cli/cli-script.c (do_define_command): Use lookup_cmd_exact.
	(define_prefix_command): Ditto.
	* command.h: Add lookup_cmd_exact.
This commit is contained in:
Marco Barisione
2021-05-07 15:43:30 +01:00
parent 97834047e1
commit a9b49cbcd5
3 changed files with 40 additions and 17 deletions

View File

@ -326,6 +326,25 @@ extern struct cmd_list_element *lookup_cmd_1
struct cmd_list_element **result_list, std::string *default_args,
int ignore_help_classes, bool lookup_for_completion_p = false);
/* Look up the command called NAME in the command list LIST.
Unlike LOOKUP_CMD, partial matches are ignored and only exact matches
on NAME are considered.
LIST is a chain of struct cmd_list_element's.
If IGNORE_HELP_CLASSES is true (the default), ignore any command list
elements which are actually help classes rather than commands (i.e.
the function field of the struct cmd_list_element is null).
If found, return the struct cmd_list_element for that command,
otherwise return NULLPTR. */
extern struct cmd_list_element *lookup_cmd_exact
(const char *name,
struct cmd_list_element *list,
bool ignore_help_classes = true);
extern struct cmd_list_element *deprecate_cmd (struct cmd_list_element *,
const char * );