[RFA 2/3] Test for slash_command.

Philippe Waroquiers
2019-04-13T19:00:42Z

gdb/testsuite/ChangeLog
2019-04-13 Philippe Waroquiers <philippe.waroquiers@skynet.be>

* gdb.base/slash_command.exp: New testcase.
* gdb.base/slash_command.c: New file.
---
gdb/testsuite/gdb.base/slash_command.c | 38 +++++++
gdb/testsuite/gdb.base/slash_command.exp | 125 +++++++++++++++++++++++
2 files changed, 163 insertions(+)
create mode 100644 gdb/testsuite/gdb.base/slash_command.c
create mode 100644 gdb/testsuite/gdb.base/slash_command.exp

diff --git a/gdb/testsuite/gdb.base/slash_command.c b/gdb/testsuite/gdb.base/slash_command.c
new file mode 100644
index 0000000000..d54dfaaf2c
--- /dev/null
+++ b/gdb/testsuite/gdb.base/slash_command.c
@@ -0,0 +1,38 @@
+/* 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/>. */
+
+
+static int x;
+
+int my_foo_function (int a)
+{
+ x += a;
+ return x;
+}
+
+int
+main ()
+{
+ int some_ints[5];
+
+ some_ints[0] = 0;
+ some_ints[1] = 1;
+ some_ints[2] = 2;
+ some_ints[3] = 3;
+ some_ints[4] = 4;
+ return my_foo_function (some_ints[4]) > 0; /* break here */
+}
diff --git a/gdb/testsuite/gdb.base/slash_command.exp b/gdb/testsuite/gdb.base/slash_command.exp
new file mode 100644
index 0000000000..eb83057d2c
--- /dev/null
+++ b/gdb/testsuite/gdb.base/slash_command.exp
@@ -0,0 +1,125 @@
+# 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/>.
+
+# This file verifies the logic to temporarily change some settings
+# using the slash command.
+
+standard_testfile
+
+if {[prepare_for_testing "failed to prepare" $testfile $srcfile debug]} {
+ return -1
+}
+
+if { ![runto_main] } then {
+ fail "can't run to main"
+ return 0
+}
+set loc [gdb_get_line_number "break here"]
+gdb_test "break $loc" ".*" "set breakpoint"
+gdb_continue_to_breakpoint "continue to breakpoint"
+
+# 'set language' == /lX
+proc check_info_function { prefix slash_seq desired_layout } {
+ gdb_test "$slash_seq info functions my_foo_function" \
+ [multi_line \
+ "All functions matching regular expression \"my_foo_function\":" \
+ "" \
+ "File .*slash_command.c:" \
+ $desired_layout
+ ] \
+ $prefix
+
+}
+check_info_function "lang_auto" "" \
+ "${decimal}: int my_foo_function\\(int\\);"
+check_info_function "slash_switch_to_Ada" "/lA" \
+ "${decimal}: function my_foo_function \\(a1: int\\) return int;.*"
+check_info_function "lang_auto_after_slash" "" \
+ "${decimal}: int my_foo_function\\(int\\);"
+gdb_test "set language ada"
+check_info_function "set_switch_to_Ada" "" \
+ "${decimal}: function my_foo_function \\(a1: int\\) return int;.*"
+gdb_test "set language auto"
+
+# 'set print elements' == /Xe
+gdb_test "print some_ints" " = \\{0, 1, 2, 3, 4\\}" "default print"
+gdb_test "/2e print some_ints" "= \\{0, 1\.\.\.\\}" "temp print 2"
+gdb_test "set print elements 2" "" "set default print 2"
+gdb_test "print some_ints" "= \\{0, 1\.\.\.\\}" "default print 2"
+gdb_test "/2e print some_ints" "= \\{0, 1\.\.\.\\}" "temp print 2, default 2"
+gdb_test "/3e print some_ints" "= \\{0, 1, 2\.\.\.\\}" "temp print 3, default 2"
+gdb_test "print some_ints" "= \\{0, 1\.\.\.\\}" "default re-print 2"
+gdb_test "set print elements 200"
+gdb_test "show print elements" "is 200." "default show elt 200"
+gdb_test "/100e show print elements" "is 100." "temp show elt 100"
+gdb_test "/e show print elements" "is unlimited." "temp show elt unlimited"
+
+# 'set print array' == /a
+gdb_test "/a print some_ints" \
+ [multi_line \
+ "\\{0," \
+ " 1," \
+ " 2," \
+ " 3," \
+ " 4}" \
+ ] \
+ "temp pretty array"
+gdb_test "set print array on" "" "set default print array on"
+gdb_test "/!a print some_ints" \
+ " = \\{0, 1, 2, 3, 4\\}" "temp print array off"
+gdb_test "set print array off" "" "set default print array off"
+
+# 'set print array-indexes' == /i
+set array_index_match \
+ "= \\{\\\[0] = 0, \\\[1] = 1, \\\[2] = 2, \\\[3] = 3, \\\[4] = 4\\}"
+gdb_test "/i print some_ints" \
+ $array_index_match \
+ "temp print array-indexes"
+gdb_test "set print array-indexes on" "" "set default print array-indexes on"
+gdb_test "/i print some_ints" \
+ $array_index_match \
+ "temp print array-indexes default on"
+gdb_test "set print array-indexes off" "" "set default print array-indexes off"
+
+
+# Now, test some combinations of all the above.
+foreach slash_seq {
+ "/lAai2e"
+ "/ai2elA"
+ "/2eailA"} {
+ gdb_test "$slash_seq print some_ints" \
+ [multi_line \
+ "= \\\(0 => 0," \
+ " 1 => 1\.\.\.\\\).*" \
+ ] \
+ "combination $slash_seq"
+}
+
+
+# Error handling.
+gdb_test "/123a show print array" \
+ [multi_line \
+ "Value type for / setting \"a\" \\\(set print array\\\) is 'Boolean on\\\|off'\." \
+ "Found unexpected 'Unsigned integer \\\(0 means unlimited\\\)' qualifier at \"123a show print array\""
+ ] \
+ "unsigned integer must be followed by unsigned setting."
+
+gdb_test "/!e show print elements" \
+ [multi_line \
+ "Value type for / setting \"e\" \\\(set print elements\\\) is 'Unsigned integer \\\(0 means unlimited\\\)'\." \
+ "Found unexpected 'Boolean on\\\|off' qualifier at \"!e show print elements\"" \
+ ] \
+ "! must be followed by boolean setting."
+
--
2.20.1