[gdb/syscalls] Sync with strace v6.13
[binutils-gdb.git] / gdb / testsuite / gdb.base / frame-view.exp
blob705a02411eeb90efbfe470ff1a7d0598feb16e33
1 # Copyright 2022-2024 Free Software Foundation, Inc.
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 3 of the License, or
6 # (at your option) any later version.
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 # GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 # Test the "frame view" family of commands.
18 standard_testfile
20 if { [build_executable "failed to prepare" \
21           ${testfile} ${srcfile} {debug pthreads}] } {
22     return
25 # If WITH_PRETTY_PRINTER is true, load pretty printers for the function
26 # parameter types, in which we do an inferior call.  This is meant to test
27 # that the frame_info_ptr correctly reinflates frames created using
28 # "select-frame view".
30 proc test_select_frame_view { with_pretty_printer } {
31     clean_restart $::binfile
33     if { $with_pretty_printer } {
34         require allow_python_tests
35     }
37     if { ![runto_main] } {
38         return
39     }
41     if { $with_pretty_printer } {
42         set remote_python_file \
43             [gdb_remote_download host "${::srcdir}/${::subdir}/${::testfile}.py"]
44         gdb_test_no_output "source ${remote_python_file}" "load python file"
45     }
47     # Stop thread 2 at a baz.
48     gdb_test "break baz"
49     gdb_test "continue" "Thread 2.*hit Breakpoint $::decimal, baz .*"
51     # Grab the stack pointer and pc of thread 2's frame.
52     set frame_sp ""
53     set frame_pc ""
55     gdb_test_multiple "info frame" "" {
56         -re -wrap ".*frame at ($::hex):.*" {
57             set frame_sp $expect_out(1,string)
58             pass $gdb_test_name
59         }
60     }
62     gdb_test_multiple "print/x \$pc" "" {
63         -re -wrap " = ($::hex)" {
64             set frame_pc $expect_out(1,string)
65             pass $gdb_test_name
66         }
67     }
69     if { $frame_sp == "" || $frame_pc == "" } {
70         # Something must have failed and logged a failure above.
71         return
72     }
74     # Select thread 2's frame in thread 1.
75     gdb_test "thread 1" "Switching to thread 1 .*"
76     gdb_test_no_output "select-frame view $frame_sp $frame_pc" \
77         "select thread 2 frame from thread 1"
79     if { $with_pretty_printer } {
80         # When the pretty printer does its infcall, it is done on the currently
81         # selected thread, thread 1 here.  However, other threads are resumed
82         # at the same time.  This causes thread 2 to exit during that infcall,
83         # leading to this weirdness:
84         #
85         #     frame^M
86         #     #0  baz (z=[Thread 0x7ffff7cc26c0 (LWP 417519) exited]^M
87         #     hohoho) at /home/simark/src/binutils-gdb/gdb/testsuite/gdb.base/frame-view.c:35^M
88         #     35        return z.n + 2;^M
89         #
90         # Avoid that by setting scheduler-locking on.
91         gdb_test_no_output "set scheduler-locking on"
93         set z1_pattern "hahaha"
94         set z2_pattern "hohoho"
95     } else {
96         set z1_pattern "\\.\\.\\."
97         set z2_pattern "\\.\\.\\."
98     }
100     # Verify that the "frame" command does not change the selected frame.
101     # There used to be a bug where the "frame" command would lose the
102     # selection of user-created frames.
103     gdb_test "frame" "#0  baz \\(z1=$z1_pattern, z2=$z2_pattern\\).*" "frame"
104     gdb_test "frame" "#0  baz \\(z1=$z1_pattern, z2=$z2_pattern\\).*" "frame again"
107 foreach_with_prefix with_pretty_printer {false true} {
108     test_select_frame_view $with_pretty_printer