aboutsummaryrefslogtreecommitdiff
path: root/gdb/cli/cli-script.c
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/cli-script.c
parentad7b7cb1f4a4a21b18740e5972b772a82fb05faf (diff)
downloadgdb-276d9db22d768e6904937b8def1b05771588092b.zip
gdb-276d9db22d768e6904937b8def1b05771588092b.tar.gz
gdb-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/cli-script.c')
-rw-r--r--gdb/cli/cli-script.c2
1 files changed, 2 insertions, 0 deletions
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))