From patchwork Sat Feb 8 14:09:12 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Philippe Waroquiers X-Patchwork-Id: 37758 Received: (qmail 37623 invoked by alias); 8 Feb 2020 14:09:56 -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 37588 invoked by uid 89); 8 Feb 2020 14:09:54 -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: mailsec114.isp.belgacom.be Received: from mailsec114.isp.belgacom.be (HELO mailsec114.isp.belgacom.be) (195.238.20.110) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sat, 08 Feb 2020 14:09:52 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=skynet.be; i=@skynet.be; q=dns/txt; s=securemail; t=1581170992; x=1612706992; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=P8ZhjgjwD0rRPUDvib3pywTq9HOf/9FMPOp9cZDjLd0=; b=hVzDJJHt49glj3kCUZTXAoySmJjAq+2sH0BKhktrjSg0D0BXZpT07SwS JH4VOT69zhzjU4OIbbogKAiwzYt6JQ==; IronPort-SDR: msSMAPkxD0PHRAlwCfMf7n8Aub6kgakDjrgeDwObTq1+tGn86ftP8HG2TEWzGyIsNw/kxjcA1F uH+LEonNQVg6RQcX4RqKnQW6LzslC203cyfI00dp7gY6Z6CRdbfiUf50zDnbmvPp139K0WKXo9 Wi14BcUMpWfD8UZL/G+2+zN3ov2r4GGebFPuhUSqobytdB8IpjRqO0yELx8eleHEnesdMfIKVO FAIUo35lQEP0rmtQK41phdSdXh9oaj+f6WcLJcQ7YHJwIGa8bcqenhGhT63a8Fh03oiVeHtJFH Yps= Received: from 156.47-242-81.adsl-dyn.isp.belgacom.be (HELO md.home) ([81.242.47.156]) by relay.skynet.be with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 08 Feb 2020 15:09:19 +0100 From: Philippe Waroquiers To: gdb-patches@sourceware.org Cc: Philippe Waroquiers Subject: [RFAv4 2/3] Add tests for new default-args related commands and arguments. Date: Sat, 8 Feb 2020 15:09:12 +0100 Message-Id: <20200208140913.13298-3-philippe.waroquiers@skynet.be> In-Reply-To: <20200208140913.13298-1-philippe.waroquiers@skynet.be> References: <20200208140913.13298-1-philippe.waroquiers@skynet.be> MIME-Version: 1.0 X-IsSubscribed: yes Test the new default-args behaviour and completion. Note that gdb.base/default-args.exp is somewhat copied from with.exp (the test of the with command), while default-exp.c is a plain copy of with.c. gdb/testsuite/ChangeLog YYYY-MM-DD Philippe Waroquiers * gdb.base/default-args.exp: New test. * gdb.base/default.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/default-args.c | 41 +++++++ gdb/testsuite/gdb.base/default-args.exp | 151 ++++++++++++++++++++++++ 3 files changed, 193 insertions(+), 1 deletion(-) create mode 100644 gdb/testsuite/gdb.base/default-args.c create mode 100644 gdb/testsuite/gdb.base/default-args.exp diff --git a/gdb/testsuite/gdb.base/alias.exp b/gdb/testsuite/gdb.base/alias.exp index be78d9e936..d98c3a38f1 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/default-args.c b/gdb/testsuite/gdb.base/default-args.c new file mode 100644 index 0000000000..c6426625d4 --- /dev/null +++ b/gdb/testsuite/gdb.base/default-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/default-args.exp b/gdb/testsuite/gdb.base/default-args.exp new file mode 100644 index 0000000000..3b486a6c7a --- /dev/null +++ b/gdb/testsuite/gdb.base/default-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 "default-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 default-args PP" "default-args PP = -pretty --" + gdb_test "PP g_s" \ + [multi_line \ + " = {" \ + " a = 1," \ + " b = 2," \ + " c = 3" \ + "}"] + + # Define default-args for "inspect", should not impact "print". + gdb_test_no_output "set default-args inspect -pretty --" "inspect -pretty" + gdb_test "show default-args inspect" "default-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 default-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 default args. + gdb_test "show enable-default-args" \ + "Whether GDB prepends default args when running a command is on\." + gdb_test_no_output "set enable-default-args off" + gdb_test "print g_s" " = {a = 1, b = 2, c = 3}" \ + "simple print with enable-default-args off" + gdb_test_no_output "set enable-default-args on" + + + # Define default-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 default-args frame apply tout" \ + "default-args frame apply tout = -past-entry -past-main" + + # Show all default args. + gdb_test "show default-args" \ + [multi_line \ + "default-args PP = -pretty --" \ + "default-args frame apply tout = -past-entry -past-main" \ + "default-args inspect = -pretty --" \ + "default-args print = -- /x"] "show default-args" + + # Clear the default-args of "inspect". + gdb_test_no_output "set default-args inspect" "clear inspect default-args" + gdb_test "show default-args inspect" "default-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 default-args xxxx yyyy -someoption" \ + "Undefined command: \"xxxx\". Try \"help\"\\." + + # Try ambiguous command. + gdb_test "set default-args a" \ + "Ambiguous command \"a\":.*" "ambiguous a" + gdb_test "set default-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 default-args' (sharing most + # of the code that alias command uses to complete after + # the first =. + test_gdb_complete_unique \ + "set default-args btf" \ + "set default-args btfu" + + test_gdb_complete_unique \ + "set default-args btfu -frame-a" \ + "set default-args btfu -frame-arguments" + +}