[RFAv4,2/3] Add tests for new default-args related commands and arguments.
Commit Message
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 <philippe.waroquiers@skynet.be>
* 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
@@ -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"
new file mode 100644
@@ -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 <http://www.gnu.org/licenses/>. */
+
+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;
+}
new file mode 100644
@@ -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 <http://www.gnu.org/licenses/>.
+
+# 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 = <no default args>"
+ 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"
+
+}