Skip to content

Commit

Permalink
Fix crash in "document" command
Browse files Browse the repository at this point in the history
PR cli/29800 points out that "document" will now crash when the
argument is an undefined command.  This is a regression due to the
"document user-defined aliases" patch.

Approved-By: Joel Brobecker <[email protected]>
Reviewed-By: Philippe Waroquiers <[email protected]>
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=29800
  • Loading branch information
tromey committed Nov 28, 2022
1 parent 76cd77d commit b70e927
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
2 changes: 2 additions & 0 deletions gdb/cli/cli-script.c
Original file line number Diff line number Diff line change
Expand Up @@ -1515,6 +1515,8 @@ do_document_command (const char *comname, int from_tty,
validate_comname (&comname);

lookup_cmd_composition (comfull, &alias, &prefix_cmd, &c);
if (c == nullptr)
error (_("Undefined command: \"%s\"."), comfull);

if (c->theclass != class_user
&& (alias == nullptr || alias->theclass != class_alias))
Expand Down
4 changes: 4 additions & 0 deletions gdb/testsuite/gdb.base/document.exp
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,7 @@ gdb_test_multiple "define do-document" "" {
}
gdb_test_no_output "do-document" "invoke do-document"
gdb_test "help do-document" "usage: do-document" "invoke help do-document"

# Test that document of a non-existing command prints an error. There
# was a regression at one point causing this to crash.
gdb_test "document nosuchcommand" "Undefined command: \"nosuchcommand\"\\."

0 comments on commit b70e927

Please sign in to comment.