From patchwork Sun Sep 15 19:26:54 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Philippe Waroquiers X-Patchwork-Id: 34531 Received: (qmail 120865 invoked by alias); 15 Sep 2019 19:27:09 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 120803 invoked by uid 89); 15 Sep 2019 19:27:09 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-22.1 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_SHORT, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.1 spammy=ele X-HELO: mailsec104.isp.belgacom.be Received: from mailsec104.isp.belgacom.be (HELO mailsec104.isp.belgacom.be) (195.238.20.100) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sun, 15 Sep 2019 19:27:07 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=skynet.be; i=@skynet.be; q=dns/txt; s=securemail; t=1568575627; x=1600111627; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=dPyN32z1fuzQ0fGKIqKWSRWwT3o8TsqQr75v+TSPpb8=; b=qgWFTZyMr5gSb3mtJZoyyCtlmN4PZkJLGxggusbLPnq3v3aoGUwSn5me +90jCaVWncb+oWdM6vReLbUnIP0aaw==; Received: from 255.38-242-81.adsl-dyn.isp.belgacom.be (HELO md.home) ([81.242.38.255]) by relay.skynet.be with ESMTP/TLS/DHE-RSA-AES128-GCM-SHA256; 15 Sep 2019 21:27:03 +0200 From: Philippe Waroquiers To: gdb-patches@sourceware.org Cc: Philippe Waroquiers Subject: [RFAv3 2/3] Add tests for new leading-args related commands and arguments. Date: Sun, 15 Sep 2019 21:26:54 +0200 Message-Id: <20190915192655.27801-3-philippe.waroquiers@skynet.be> In-Reply-To: <20190915192655.27801-1-philippe.waroquiers@skynet.be> References: <20190915192655.27801-1-philippe.waroquiers@skynet.be> MIME-Version: 1.0 X-IsSubscribed: yes Test the new leading-args behaviour and completion. Note that gdb.base/leading-args.exp is somewhat copied from with.exp (the test of the with command), while leading-exp.c is a plain copy of with.c. gdb/testsuite/ChangeLog 2019-09-15 Philippe Waroquiers * gdb.base/leading-args.exp: New test. * gdb.base/leading.c: New file. * gdb.base/alias.exp: Update expected error msg for alias foo=bar. --- gdb/testsuite/gdb.base/alias.exp | 2 +- gdb/testsuite/gdb.base/leading-args.c | 41 +++++++ gdb/testsuite/gdb.base/leading-args.exp | 151 ++++++++++++++++++++++++ 3 files changed, 193 insertions(+), 1 deletion(-) create mode 100644 gdb/testsuite/gdb.base/leading-args.c create mode 100644 gdb/testsuite/gdb.base/leading-args.exp diff --git a/gdb/testsuite/gdb.base/alias.exp b/gdb/testsuite/gdb.base/alias.exp index 20722e5dea..764d3ff8ff 100644 --- a/gdb/testsuite/gdb.base/alias.exp +++ b/gdb/testsuite/gdb.base/alias.exp @@ -56,7 +56,7 @@ test_abbrev_alias set6 "alias -a -- set6 = set" 46 test_abbrev_alias -a "alias -a -- -a = set" 47 gdb_test "alias set2=set" "already exists: set2" -gdb_test "alias foo=bar" "Invalid command to alias to: bar" +gdb_test "alias foo=bar" "Undefined command: \"bar\". Try \"help\"." gdb_test_no_output "alias spe = set p elem" gdb_test_no_output "spe 50" diff --git a/gdb/testsuite/gdb.base/leading-args.c b/gdb/testsuite/gdb.base/leading-args.c new file mode 100644 index 0000000000..c6426625d4 --- /dev/null +++ b/gdb/testsuite/gdb.base/leading-args.c @@ -0,0 +1,41 @@ +/* This testcase is part of GDB, the GNU debugger. + + Copyright 2019 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +int xxx1 = 123; + +struct S +{ + int a; + int b; + int c; +}; + +struct S g_s = {1, 2, 3}; + +static void +inc () +{ + g_s.a++;; +} + +int +main () +{ + inc (); + + return 0; +} diff --git a/gdb/testsuite/gdb.base/leading-args.exp b/gdb/testsuite/gdb.base/leading-args.exp new file mode 100644 index 0000000000..ecc308fb51 --- /dev/null +++ b/gdb/testsuite/gdb.base/leading-args.exp @@ -0,0 +1,151 @@ +# This testcase is part of GDB, the GNU debugger. + +# Copyright 2019 Free Software Foundation, Inc. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +# Test the "leading-args" related commands and arguments. + +load_lib completion-support.exp + +standard_testfile .c + +if {[build_executable "failed to prepare" $testfile $srcfile debug]} { + return -1 +} + +clean_restart $binfile + +# Basic/core tests using user-visible commands. +with_test_prefix "basics" { + # Define an alias to pretty print something. + gdb_test "print g_s" " = {a = 1, b = 2, c = 3}" "simple print" + gdb_test_no_output "alias PP = print -pretty --" "alias PP" + gdb_test "show leading-args PP" "leading-args PP = -pretty --" + gdb_test "PP g_s" \ + [multi_line \ + " = {" \ + " a = 1," \ + " b = 2," \ + " c = 3" \ + "}"] + + # Define leading-args for "inspect", should not impact "print". + gdb_test_no_output "set leading-args inspect -pretty --" "inspect -pretty" + gdb_test "show leading-args inspect" "leading-args inspect = -pretty --" + gdb_test "print g_s" " = {a = 1, b = 2, c = 3}" "simple print not impacted" + gdb_test "inspect g_s" \ + [multi_line \ + " = {" \ + " a = 1," \ + " b = 2," \ + " c = 3" \ + "}"] + + # Set hex as default FMT for print. + gdb_test_no_output "set leading-args print -- /x" "print hex" + gdb_test "inspect g_s" \ + [multi_line \ + " = {" \ + " a = 1," \ + " b = 2," \ + " c = 3" \ + "}"] "inspect g_s still pretty" + gdb_test "print g_s" " = {a = 0x1, b = 0x2, c = 0x3}" "simple print hex" + + # Test disabling leading args. + gdb_test "show enable-leading-args" \ + "Whether GDB prepends leading args when running a command is on\." + gdb_test_no_output "set enable-leading-args off" + gdb_test "print g_s" " = {a = 1, b = 2, c = 3}" \ + "simple print with enable-leading-args off" + gdb_test_no_output "set enable-leading-args on" + + + # Define leading-args for an alias of frame apply all + gdb_test_no_output "alias frame apply tout = frame apply all -past-entry -past-main" \ + "alias frame apply tout" + gdb_test "show leading-args frame apply tout" \ + "leading-args frame apply tout = -past-entry -past-main" + + # Show all leading args. + gdb_test "show leading-args" \ + [multi_line \ + "leading-args PP = -pretty --" \ + "leading-args frame apply tout = -past-entry -past-main" \ + "leading-args inspect = -pretty --" \ + "leading-args print = -- /x"] "show leading-args" + + # Clear the leading-args of "inspect". + gdb_test_no_output "set leading-args inspect" "clear inspect leading-args" + gdb_test "show leading-args inspect" "leading-args inspect = " + gdb_test "inspect g_s" " = {a = 1, b = 2, c = 3}" "simple inspect" + +} + +# Check errors. +with_test_prefix "errors" { + # Try an unknown root setting. + gdb_test "set leading-args xxxx yyyy -someoption" \ + "Undefined command: \"xxxx\". Try \"help\"\\." + + # Try ambiguous command. + gdb_test "set leading-args a" \ + "Ambiguous command \"a\":.*" "ambiguous a" + gdb_test "set leading-args frame a" \ + "Ambiguous frame command \"a\":.*" "ambiguous frame a" +} + + +# Check completion. +with_test_prefix "completion" { + test_gdb_complete_unique \ + "alias set pri" \ + "alias set print" + + test_gdb_complete_unique \ + "alias set print items = set pri" \ + "alias set print items = set print" + + test_gdb_complete_unique \ + "alias set print items = set print ele" \ + "alias set print items = set print elements" + + test_gdb_complete_unique \ + "alias btfu = backt" \ + "alias btfu = backtrace" + + test_gdb_complete_unique \ + "alias btfu = backtrace -fu" \ + "alias btfu = backtrace -full" + + test_gdb_complete_unique \ + "alias btfu = backtrace -full -past-e" \ + "alias btfu = backtrace -full -past-entry" + + gdb_test_no_output "alias btfu = backtrace -full -past-entry" \ + "alias btfu" + + # Test completion of 'set leading-args' (sharing most + # of the code that alias command uses to complete after + # the first =. + test_gdb_complete_unique \ + "set leading-args btf" \ + "set leading-args btfu" + + test_gdb_complete_unique \ + "set leading-args btfu -frame-a" \ + "set leading-args btfu -frame-arguments" + +}