From patchwork Fri Nov 18 16:05:47 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 60838 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 0C96C3853D4D for ; Fri, 18 Nov 2022 16:06:19 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0C96C3853D4D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1668787579; bh=Sy5qfw/C3itqT2CI6GY8sZiJtaLFruxIXbsytZ+qEkE=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=nfoKruEE9HYPQoykA2nrKyYzyn4pj+dMvY5/SU4mJX7eTI7XNXYkCd1+yYXMUCu2S rhEsHtIz73/kmA0WipC1mNXVo+78TsQWkHlabGdkM5qKEC7iRE234Diu/pOBibM3qc 4IROVTeS/d5ovovgPdOfyX3YSJXtu2BT1IahuBTU= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-io1-xd2b.google.com (mail-io1-xd2b.google.com [IPv6:2607:f8b0:4864:20::d2b]) by sourceware.org (Postfix) with ESMTPS id 9042D3857C51 for ; Fri, 18 Nov 2022 16:05:54 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 9042D3857C51 Received: by mail-io1-xd2b.google.com with SMTP id y6so4121727iof.9 for ; Fri, 18 Nov 2022 08:05:54 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=Sy5qfw/C3itqT2CI6GY8sZiJtaLFruxIXbsytZ+qEkE=; b=RJMI9oe9ii+kEsnRIC/BX8r483Xs5QP8ljNTsPtvKtoKHkOJZzdy8hA/DqiuBITg5K FLAAGwMjM0hsIUAfPI4yIME2S9+2UDSHgPkJGhZVxp/NjP0t3jp3H9BJpKlYdvc/7Mmd b8ohfrmczpQ/ZaN0eIm+xwMh31HKvB/Bxxr2N3mp2PY/o8/zbiR9lKxveN6+9JAJogdY Hu1mju+upI5JKPG5TL6XVacmbOtQ1QhsT99eaijdUCLxsRHbVkjoZQHVSDEa67NUkp2i qPU2Ar6iOqlLuqlgdaK9i0vsZaQmt+wWsIwBORi/zHKaWfB/wLXEI1nH9Nm1nx6g5Nkg fT7A== X-Gm-Message-State: ANoB5pm9RHQQ9FVT7wlUKTL8d3FCfG1PMcFDCJbSIn4edNXnACj/TxpU Am8lXEXoU3Cq3FSHAjtb+OOGAo9xnKzBaA== X-Google-Smtp-Source: AA0mqf7UQVF3v/JPO8Mni91YaPBIvi8qf0lTNBa8ngcPjCOJUR1bNQ3gVBokyPvW/I+4u58T8SnNvg== X-Received: by 2002:a02:cb96:0:b0:363:9f1c:e5 with SMTP id u22-20020a02cb96000000b003639f1c00e5mr3510738jap.187.1668787553780; Fri, 18 Nov 2022 08:05:53 -0800 (PST) Received: from localhost.localdomain (97-122-76-186.hlrn.qwest.net. [97.122.76.186]) by smtp.gmail.com with ESMTPSA id m22-20020a02a156000000b003751b68b84esm1316875jah.32.2022.11.18.08.05.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Nov 2022 08:05:53 -0800 (PST) To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH] Fix crash in "document" command Date: Fri, 18 Nov 2022 09:05:47 -0700 Message-Id: <20221118160547.1336252-1-tromey@adacore.com> X-Mailer: git-send-email 2.34.3 MIME-Version: 1.0 X-Spam-Status: No, score=-11.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Tom Tromey via Gdb-patches From: Tom Tromey Reply-To: Tom Tromey Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" 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\"\\."