public inbox for gdb-cvs@sourceware.org
help / color / mirror / Atom feed
* [binutils-gdb] Fix crash in "document" command
@ 2022-11-28 13:49 Tom Tromey
  0 siblings, 0 replies; only message in thread
From: Tom Tromey @ 2022-11-28 13:49 UTC (permalink / raw)
  To: gdb-cvs

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=b70e9270fbafd43a3fece0c7dd52cabd70854dfd

commit b70e9270fbafd43a3fece0c7dd52cabd70854dfd
Author: Tom Tromey <tromey@adacore.com>
Date:   Fri Nov 18 09:04:39 2022 -0700

    Fix crash in "document" command
    
    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 <brobecker@adacore.com>
    Reviewed-By: Philippe Waroquiers <philippe.waroquiers@skynet.be>
    Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=29800

Diff:
---
 gdb/cli/cli-script.c                | 2 ++
 gdb/testsuite/gdb.base/document.exp | 4 ++++
 2 files changed, 6 insertions(+)

diff --git a/gdb/cli/cli-script.c b/gdb/cli/cli-script.c
index 2442f7ae38b..2101d6fface 100644
--- a/gdb/cli/cli-script.c
+++ b/gdb/cli/cli-script.c
@@ -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))
diff --git a/gdb/testsuite/gdb.base/document.exp b/gdb/testsuite/gdb.base/document.exp
index 2d8f6b88090..6f426510d29 100644
--- a/gdb/testsuite/gdb.base/document.exp
+++ b/gdb/testsuite/gdb.base/document.exp
@@ -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\"\\."

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-11-28 13:49 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-28 13:49 [binutils-gdb] Fix crash in "document" command Tom Tromey

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).