aboutsummaryrefslogtreecommitdiff
path: root/gdb/testsuite
diff options
context:
space:
mode:
Diffstat (limited to 'gdb/testsuite')
-rw-r--r--gdb/testsuite/ChangeLog9
-rw-r--r--gdb/testsuite/gdb.base/nested-subp1.c37
-rw-r--r--gdb/testsuite/gdb.base/nested-subp1.exp55
-rw-r--r--gdb/testsuite/gdb.base/nested-subp2.c48
-rw-r--r--gdb/testsuite/gdb.base/nested-subp2.exp64
-rw-r--r--gdb/testsuite/gdb.base/nested-subp3.c66
-rw-r--r--gdb/testsuite/gdb.base/nested-subp3.exp55
7 files changed, 334 insertions, 0 deletions
diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog
index bf7f1eb..15ad42c 100644
--- a/gdb/testsuite/ChangeLog
+++ b/gdb/testsuite/ChangeLog
@@ -1,3 +1,12 @@
+2015-08-25 Pierre-Marie de Rodat <derodat@adacore.com>
+
+ * gdb.base/nested-subp1.exp: New file.
+ * gdb.base/nested-subp1.c: New file.
+ * gdb.base/nested-subp2.exp: New file.
+ * gdb.base/nested-subp2.c: New file.
+ * gdb.base/nested-subp3.exp: New file.
+ * gdb.base/nested-subp3.c: New file.
+
2015-08-24 Pedro Alves <palves@redhat.com>
* gdb.server/connect-without-multi-process.c: New file.
diff --git a/gdb/testsuite/gdb.base/nested-subp1.c b/gdb/testsuite/gdb.base/nested-subp1.c
new file mode 100644
index 0000000..967eb2f
--- /dev/null
+++ b/gdb/testsuite/gdb.base/nested-subp1.c
@@ -0,0 +1,37 @@
+/* This test program is part of GDB, the GNU debugger.
+
+ Copyright 2015 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
+foo (int i1)
+{
+ int
+ nested (int i2)
+ {
+ /* Here with i1 and i2, we can test that GDB can fetch both a local and a
+ non-local variable in the most simple nested function situation: the
+ parent block instance is accessible as the directly upper frame. */
+ return i1 * i2; /* STOP */
+ }
+
+ return nested (i1 + 1);
+}
+
+int
+main ()
+{
+ return !foo (1);
+}
diff --git a/gdb/testsuite/gdb.base/nested-subp1.exp b/gdb/testsuite/gdb.base/nested-subp1.exp
new file mode 100644
index 0000000..9720f5b
--- /dev/null
+++ b/gdb/testsuite/gdb.base/nested-subp1.exp
@@ -0,0 +1,55 @@
+# Copyright 2015 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 is part of the gdb testsuite.
+
+#
+# Test nested functions related functionality.
+#
+
+standard_testfile
+
+
+set testcase "nested-subp1"
+
+if { [gdb_compile "${srcdir}/${subdir}/${testcase}.c" \
+ [standard_output_file "${testcase}"] \
+ "${testcase}" \
+ [list debug "additional_flags=-std=gnu99"]] != "" } {
+ return -1
+}
+
+
+# Run until the variables we are interested in are visible.
+
+clean_restart "${testcase}"
+if ![runto_main] {
+ perror "could not run to main"
+ continue
+}
+
+set bp_location [gdb_get_line_number "STOP" "${testcase}.c"]
+gdb_test "break ${testcase}.c:${bp_location}" \
+ "Breakpoint \[0-9\]+ at 0x\[0-9a-fA-F\]+: .*" \
+ "breakpoint to the STOP marker"
+gdb_test "continue" \
+ "Breakpoint \[0-9\]+, nested .*" \
+ "continue to the STOP marker"
+
+
+# Check we get correct values for both local and non-local variable references.
+
+gdb_test "print i1" "1"
+gdb_test "print i2" "2"
diff --git a/gdb/testsuite/gdb.base/nested-subp2.c b/gdb/testsuite/gdb.base/nested-subp2.c
new file mode 100644
index 0000000..a6449e34
--- /dev/null
+++ b/gdb/testsuite/gdb.base/nested-subp2.c
@@ -0,0 +1,48 @@
+/* This test program is part of GDB, the GNU debugger.
+
+ Copyright 2015 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/>. */
+
+void
+iter_str (const char *str, void (*callback) (char c))
+{
+ for (; *str != '\0'; ++str)
+ callback (*str);
+}
+
+int
+length_str (const char *str)
+{
+ int count = 0;
+
+ void
+ increment (char c)
+ {
+ /* Here with COUNT, we can test that GDB can read a non-local variable even
+ though it's not directly in the upper stack frame. */
+ count += 1; /* STOP */
+ }
+
+ iter_str (str, &increment);
+ return count;
+}
+
+int
+main ()
+{
+ if (length_str ("foo") == 3)
+ return 0;
+ return 1;
+}
diff --git a/gdb/testsuite/gdb.base/nested-subp2.exp b/gdb/testsuite/gdb.base/nested-subp2.exp
new file mode 100644
index 0000000..a107d1c
--- /dev/null
+++ b/gdb/testsuite/gdb.base/nested-subp2.exp
@@ -0,0 +1,64 @@
+# Copyright 2015 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 is part of the gdb testsuite.
+
+#
+# Test nested functions related functionality.
+#
+
+standard_testfile
+
+
+set testcase "nested-subp2"
+
+if { [gdb_compile "${srcdir}/${subdir}/${testcase}.c" \
+ [standard_output_file "${testcase}"] \
+ "${testcase}" \
+ [list debug "additional_flags=-std=gnu99"]] != "" } {
+ return -1
+}
+
+
+# Run until the variables we are interested in are visible.
+
+clean_restart "${testcase}"
+if ![runto_main] {
+ perror "could not run to main"
+ continue
+}
+
+set bp_location [gdb_get_line_number "STOP" "${testcase}.c"]
+gdb_test "break ${testcase}.c:${bp_location}" \
+ "Breakpoint \[0-9\]+ at 0x\[0-9a-fA-F\]+: .*" \
+ "breakpoint to the STOP marker"
+gdb_test "continue" \
+ "Breakpoint \[0-9\]+, increment .*" \
+ "continue to the STOP marker"
+
+
+# Check we get correct values for both local and non-local variable references.
+
+gdb_test "print c" "102 'f'"
+gdb_test "print count" "0"
+
+
+# Same but a little later: make sure we were looking at the proper places.
+
+gdb_test "continue" \
+ "Breakpoint \[0-9\]+, increment .*" \
+ "continue to the STOP marker"
+gdb_test "print c" "111 'o'"
+gdb_test "print count" "1"
diff --git a/gdb/testsuite/gdb.base/nested-subp3.c b/gdb/testsuite/gdb.base/nested-subp3.c
new file mode 100644
index 0000000..a51f417
--- /dev/null
+++ b/gdb/testsuite/gdb.base/nested-subp3.c
@@ -0,0 +1,66 @@
+/* This test program is part of GDB, the GNU debugger.
+
+ Copyright 2015 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/>. */
+
+#include <stdlib.h>
+
+typedef void (*callback_t) (void);
+
+extern void process (callback_t cb);
+extern void parent (int first, callback_t cb);
+
+void
+ignore (int unused)
+{
+ (void) unused;
+}
+
+void
+process (callback_t cb)
+{
+ parent (0, cb);
+}
+
+void
+parent (int first, callback_t cb)
+{
+ void child (void)
+ {
+ /* When reaching this, there are two block instances for PARENT on the
+ stack: the one that is right in the upper frame is not the one actually
+ used for non-local references, so GDB has to follow the static link in
+ order to get the correct instance, and thus in order to read the proper
+ variables.
+
+ As a simple check, we can verify that under GDB, the following is true:
+ parent_first == first (which should be one: see the IF block below). */
+ const int parent_first = first;
+ ignore (parent_first); /* STOP */
+ ignore (first);
+ }
+
+ if (first)
+ process (&child);
+ else
+ cb ();
+}
+
+int
+main ()
+{
+ parent (1, NULL);
+ return 0;
+}
diff --git a/gdb/testsuite/gdb.base/nested-subp3.exp b/gdb/testsuite/gdb.base/nested-subp3.exp
new file mode 100644
index 0000000..8f9b522
--- /dev/null
+++ b/gdb/testsuite/gdb.base/nested-subp3.exp
@@ -0,0 +1,55 @@
+# Copyright 2015 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 is part of the gdb testsuite.
+
+#
+# Test nested functions related functionality.
+#
+
+standard_testfile
+
+
+set testcase "nested-subp3"
+
+if { [gdb_compile "${srcdir}/${subdir}/${testcase}.c" \
+ [standard_output_file "${testcase}"] \
+ "${testcase}" \
+ [list debug "additional_flags=-std=gnu99"]] != "" } {
+ return -1
+}
+
+
+# Run until the variables we are interested in are visible.
+
+clean_restart "${testcase}"
+if ![runto_main] {
+ perror "could not run to main"
+ continue
+}
+
+set bp_location [gdb_get_line_number "STOP" "${testcase}.c"]
+gdb_test "break ${testcase}.c:${bp_location}" \
+ "Breakpoint \[0-9\]+ at 0x\[0-9a-fA-F\]+: .*" \
+ "breakpoint to the STOP marker"
+gdb_test "continue" \
+ "Breakpoint \[0-9\]+, child .*" \
+ "continue to the STOP marker"
+
+
+# Check we get correct values for both local and non-local variable references.
+
+gdb_test "print first" "1"
+gdb_test "print parent_first" "1"