From: Tom Tromey <tromey@adacore.com>
To: gdb-patches@sourceware.org
Cc: Tom Tromey <tromey@adacore.com>
Subject: [PATCH] Fix crash in "document" command
Date: Fri, 18 Nov 2022 09:05:47 -0700 [thread overview]
Message-ID: <20221118160547.1336252-1-tromey@adacore.com> (raw)
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.
---
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\"\\."
--
2.34.3
next reply other threads:[~2022-11-18 16:05 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-11-18 16:05 Tom Tromey [this message]
2022-11-19 12:24 ` Joel Brobecker
2022-11-19 14:52 ` Philippe Waroquiers
2022-11-28 13:49 ` Tom Tromey
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20221118160547.1336252-1-tromey@adacore.com \
--to=tromey@adacore.com \
--cc=gdb-patches@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).