aboutsummaryrefslogtreecommitdiff
path: root/gdb/cli
diff options
context:
space:
mode:
authorHannes Domani <ssbssa@yahoo.de>2024-02-07 19:59:29 +0100
committerHannes Domani <ssbssa@yahoo.de>2024-02-07 19:59:32 +0100
commit276d9db22d768e6904937b8def1b05771588092b (patch)
tree5c5fc718d8b6b79691a4fc8965a191e0d8aa685b /gdb/cli
parentad7b7cb1f4a4a21b18740e5972b772a82fb05faf (diff)
downloadbinutils-276d9db22d768e6904937b8def1b05771588092b.zip
binutils-276d9db22d768e6904937b8def1b05771588092b.tar.gz
binutils-276d9db22d768e6904937b8def1b05771588092b.tar.bz2
Raise exception if ambiguous name is used in gdb.parameter
Currently gdb.parameter doesn't raise an exception if an ambiguous name is used, it instead returns the value of the last partly matching parameter: ``` (gdb) show print sym Ambiguous show print command "sym": symbol, symbol-filename, symbol-loading. (gdb) show print symbol-loading Printing of symbol loading messages is "full". (gdb) py print(gdb.parameter("print sym")) full ``` It's because lookup_cmd_composition_1 tries to detect ambigous names by checking the return value of find_cmd for CMD_LIST_AMBIGUOUS, which never happens, since only lookup_cmd_1 returns CMD_LIST_AMBIGUOUS. Instead the nfound argument contains the number of found matches. By using it instead, and by setting *CMD to the special value CMD_LIST_AMBIGUOUS in this case, gdbpy_parameter can now show the appropriate error message: ``` (gdb) py print(gdb.parameter("print sym")) Traceback (most recent call last): File "<string>", line 1, in <module> RuntimeError: Parameter `print sym' is ambiguous. Error while executing Python code. (gdb) py print(gdb.parameter("print symbol")) True (gdb) py print(gdb.parameter("print symbol-")) Traceback (most recent call last): File "<string>", line 1, in <module> RuntimeError: Parameter `print symbol-' is ambiguous. Error while executing Python code. (gdb) py print(gdb.parameter("print symbol-load")) full ``` Since the document command also uses lookup_cmd_composition, it needed to check for CMD_LIST_AMBIGUOUS as well, so it now also shows an "Ambiguous command" error message in this case. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=14639 Approved-By: Tom Tromey <tom@tromey.com>
Diffstat (limited to 'gdb/cli')
-rw-r--r--gdb/cli/cli-decode.c13
-rw-r--r--gdb/cli/cli-script.c2
2 files changed, 12 insertions, 3 deletions
diff --git a/gdb/cli/cli-decode.c b/gdb/cli/cli-decode.c
index a69939e..bbabd40 100644
--- a/gdb/cli/cli-decode.c
+++ b/gdb/cli/cli-decode.c
@@ -2549,7 +2549,8 @@ deprecated_cmd_warning (const char *text, struct cmd_list_element *list)
If TEXT is a subcommand (i.e. one that is preceded by a prefix
command) set *PREFIX_CMD.
- Set *CMD to point to the command TEXT indicates.
+ Set *CMD to point to the command TEXT indicates, or to
+ CMD_LIST_AMBIGUOUS if there are multiple possible matches.
If any of *ALIAS, *PREFIX_CMD, or *CMD cannot be determined or do not
exist, they are NULL when we return.
@@ -2589,7 +2590,12 @@ lookup_cmd_composition_1 (const char *text,
*cmd = find_cmd (command.c_str (), len, cur_list, 1, &nfound);
/* We only handle the case where a single command was found. */
- if (*cmd == CMD_LIST_AMBIGUOUS || *cmd == nullptr)
+ if (nfound > 1)
+ {
+ *cmd = CMD_LIST_AMBIGUOUS;
+ return 0;
+ }
+ else if (*cmd == nullptr)
return 0;
else
{
@@ -2623,7 +2629,8 @@ lookup_cmd_composition_1 (const char *text,
If TEXT is a subcommand (i.e. one that is preceded by a prefix
command) set *PREFIX_CMD.
- Set *CMD to point to the command TEXT indicates.
+ Set *CMD to point to the command TEXT indicates, or to
+ CMD_LIST_AMBIGUOUS if there are multiple possible matches.
If any of *ALIAS, *PREFIX_CMD, or *CMD cannot be determined or do not
exist, they are NULL when we return.
diff --git a/gdb/cli/cli-script.c b/gdb/cli/cli-script.c
index 439ba50..f06724a 100644
--- a/gdb/cli/cli-script.c
+++ b/gdb/cli/cli-script.c
@@ -1521,6 +1521,8 @@ do_document_command (const char *comname, int from_tty,
lookup_cmd_composition (comfull, &alias, &prefix_cmd, &c);
if (c == nullptr)
error (_("Undefined command: \"%s\"."), comfull);
+ else if (c == CMD_LIST_AMBIGUOUS)
+ error (_("Ambiguous command: \"%s\"."), comfull);
if (c->theclass != class_user
&& (alias == nullptr || alias->theclass != class_alias))