binutils-gdb/gdb/cli
Hannes Domani 276d9db22d 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>
2024-02-07 19:59:32 +01:00
..
cli-cmds.c gdb: fix "list ." related crash 2024-01-23 16:58:55 +01:00
cli-cmds.h Update copyright year range in header of all files managed by GDB 2024-01-12 15:49:57 +00:00
cli-decode.c Raise exception if ambiguous name is used in gdb.parameter 2024-02-07 19:59:32 +01:00
cli-decode.h Update copyright year range in header of all files managed by GDB 2024-01-12 15:49:57 +00:00
cli-dump.c Update copyright year range in header of all files managed by GDB 2024-01-12 15:49:57 +00:00
cli-interp.c Update copyright year range in header of all files managed by GDB 2024-01-12 15:49:57 +00:00
cli-interp.h Update copyright year range in header of all files managed by GDB 2024-01-12 15:49:57 +00:00
cli-logging.c Update copyright year range in header of all files managed by GDB 2024-01-12 15:49:57 +00:00
cli-option.c Update copyright year range in header of all files managed by GDB 2024-01-12 15:49:57 +00:00
cli-option.h Update copyright year range in header of all files managed by GDB 2024-01-12 15:49:57 +00:00
cli-script.c Raise exception if ambiguous name is used in gdb.parameter 2024-02-07 19:59:32 +01:00
cli-script.h Update copyright year range in header of all files managed by GDB 2024-01-12 15:49:57 +00:00
cli-setshow.c Update copyright year range in header of all files managed by GDB 2024-01-12 15:49:57 +00:00
cli-setshow.h Update copyright year range in header of all files managed by GDB 2024-01-12 15:49:57 +00:00
cli-style.c Update copyright year range in header of all files managed by GDB 2024-01-12 15:49:57 +00:00
cli-style.h Update copyright year range in header of all files managed by GDB 2024-01-12 15:49:57 +00:00
cli-utils.c Update copyright year range in header of all files managed by GDB 2024-01-12 15:49:57 +00:00
cli-utils.h Update copyright year range in header of all files managed by GDB 2024-01-12 15:49:57 +00:00