aboutsummaryrefslogtreecommitdiff
path: root/gdb/testsuite
diff options
context:
space:
mode:
authorAndrew Burgess <andrew.burgess@embecosm.com>2018-05-18 17:45:16 +0100
committerAndrew Burgess <andrew.burgess@embecosm.com>2018-05-24 18:01:31 +0100
commit45f25d6c83c31a48a01ef8293bb3978f5e58e653 (patch)
tree3eddbff0a9ff77faa031e6180f985b60774583a7 /gdb/testsuite
parentd9f6d7f8b636a2b32004273143d72a77d82b40de (diff)
downloadgdb-45f25d6c83c31a48a01ef8293bb3978f5e58e653.zip
gdb-45f25d6c83c31a48a01ef8293bb3978f5e58e653.tar.gz
gdb-45f25d6c83c31a48a01ef8293bb3978f5e58e653.tar.bz2
gdb: Restore selected frame in print_frame_local_vars
PR gdb/23203 reports 'bt full' causing the currently selected frame to change, this issue is fixed in this commit. Add a new class scoped_restore_selected_frame that saves and restores the selected frame. Make use of this in print_frame_local_vars to restore the selected frame on exit. gdb/ChangeLog: PR gdb/23203 * frame.c (scoped_restore_selected_frame::scoped_restore_selected_frame): Define. (scoped_restore_selected_frame::~scoped_restore_selected_frame): Define. * frame.h (class scoped_restore_selected_frame): New class. * stack.c (print_frame_local_vars): Remove catching and rethrowing of any exception, use scoped_restore_selected_frame to restore the frame instead. gdb/testsuite/ChangeLog: PR gdb/23203 * gdb.base/bt-selected-frame.c: New file. * gdb.base/bt-selected-frame.exp: New file. * lib/gdb.exp (get_current_frame_number): New function.
Diffstat (limited to 'gdb/testsuite')
-rw-r--r--gdb/testsuite/ChangeLog7
-rw-r--r--gdb/testsuite/gdb.base/bt-selected-frame.c35
-rw-r--r--gdb/testsuite/gdb.base/bt-selected-frame.exp72
-rw-r--r--gdb/testsuite/lib/gdb.exp16
4 files changed, 130 insertions, 0 deletions
diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog
index 426b438..b2938b1 100644
--- a/gdb/testsuite/ChangeLog
+++ b/gdb/testsuite/ChangeLog
@@ -1,3 +1,10 @@
+2018-05-24 Andrew Burgess <andrew.burgess@embecosm.com>
+
+ PR gdb/23203
+ * gdb.base/bt-selected-frame.c: New file.
+ * gdb.base/bt-selected-frame.exp: New file.
+ * lib/gdb.exp (get_current_frame_number): New function.
+
2018-05-24 Maciej W. Rozycki <macro@mips.com>
Pedro Alves <palves@redhat.com>
diff --git a/gdb/testsuite/gdb.base/bt-selected-frame.c b/gdb/testsuite/gdb.base/bt-selected-frame.c
new file mode 100644
index 0000000..708dc69
--- /dev/null
+++ b/gdb/testsuite/gdb.base/bt-selected-frame.c
@@ -0,0 +1,35 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+ Copyright 2018 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
+breakpt ()
+{
+ asm ("" ::: "memory");
+}
+
+void
+func ()
+{
+ breakpt ();
+}
+
+int
+main ()
+{
+ func ();
+ return 0;
+}
diff --git a/gdb/testsuite/gdb.base/bt-selected-frame.exp b/gdb/testsuite/gdb.base/bt-selected-frame.exp
new file mode 100644
index 0000000..a60962f
--- /dev/null
+++ b/gdb/testsuite/gdb.base/bt-selected-frame.exp
@@ -0,0 +1,72 @@
+# Copyright 2018 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/>.
+
+# Check that the selected stack frame doesn't change after a backtrace.
+
+standard_testfile
+
+if { [prepare_for_testing "failed to prepare" $testfile $srcfile debug] } {
+ return -1
+}
+
+proc check_selected_frame_after_bt { bt_cmd stack_pattern } {
+ global binfile
+
+ clean_restart $binfile
+
+ with_test_prefix $bt_cmd {
+
+ if ![runto_main] then {
+ fail "can't run to main"
+ return 0
+ }
+
+ gdb_breakpoint "breakpt"
+ gdb_continue_to_breakpoint "breakpt"
+
+ # Visit each frame in the stack and ensure that the selected
+ # frame doesn't change after executing the backtrace command
+ # in BT_CMD.
+ foreach_with_prefix frame {0 1 2} {
+ if { $frame == 0 } {
+ gdb_assert {[get_current_frame_number] == $frame} \
+ "check frame"
+ } else {
+ gdb_test "frame $frame" "#$frame .*" "select frame"
+ }
+
+ gdb_test "$bt_cmd" $stack_pattern \
+ "perform backtrace command"
+
+ gdb_assert {[get_current_frame_number] == $frame} \
+ "check frame is still selected"
+ }
+ }
+}
+
+check_selected_frame_after_bt "bt" \
+ [multi_line \
+ "#0 \[^\n\r\]+" \
+ "#1 \[^\n\r\]+" \
+ "#2 \[^\n\r\]+"]
+
+check_selected_frame_after_bt "bt full" \
+ [multi_line \
+ "#0 \[^\n\r\]+" \
+ "No locals\." \
+ "#1 \[^\n\r\]+" \
+ "No locals\." \
+ "#2 \[^\n\r\]+" \
+ "No locals\."]
diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp
index 0f05d04..ee66a38 100644
--- a/gdb/testsuite/lib/gdb.exp
+++ b/gdb/testsuite/lib/gdb.exp
@@ -5805,6 +5805,22 @@ proc get_var_address { var } {
return ""
}
+# Return the frame number for the currently selected frame
+proc get_current_frame_number {{test_name ""}} {
+ global gdb_prompt
+
+ if { $test_name == "" } {
+ set test_name "get current frame number"
+ }
+ set frame_num -1
+ gdb_test_multiple "frame" $test_name {
+ -re "#(\[0-9\]+) .*$gdb_prompt $" {
+ set frame_num $expect_out(1,string)
+ }
+ }
+ return $frame_num
+}
+
# Get the current value for remotetimeout and return it.
proc get_remotetimeout { } {
global gdb_prompt