[gdb/syscalls] Sync with strace v6.13
[binutils-gdb.git] / gdb / testsuite / gdb.base / step-over-no-symbols.exp
blob98158e1fdd095baf67a418e4dc78df17ce6d099f
1 # Copyright (C) 2015-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 that GDB can step past a breakpoint even if GDB doesn't have
17 # symbols for the main binary.  PR gdb/13858.
19 standard_testfile start.c
21 if { [build_executable "failed to build" ${testfile} $srcfile] } {
22     return -1
25 # Get the current PC.  MSG is used as test message.
27 proc get_pc { msg } {
28     global hex gdb_prompt
30     set addr ""
31     gdb_test_multiple "p /x \$pc" "$msg" {
32         -re " = ($hex).*$gdb_prompt $" {
33             set addr $expect_out(1,string)
34             pass "$msg"
35         }
36     }
38     return $addr
41 # Test stepping past a breakpoint with no symbols.  DISPLACED is one
42 # of the "set displaced-stepping" options.  If GDB can't find where to
43 # put the scratch pad, GDB should be able to fall back to stepping
44 # past the breakpoint using an in-line step-over.
46 proc test_step_over { displaced } {
47     global hex
48     global binfile
50     clean_restart $binfile
52     if ![runto_main] {
53         return -1
54     }
56     delete_breakpoints
58     set msg "purging symbols"
59     gdb_test_multiple "file" "$msg" {
60         -re "Are you sure you want to change the file.*y or n. $" {
61             send_gdb "y\n"
62             exp_continue
63         }
64         -re "Discard symbol table.*y or n. $" {
65             gdb_test "y" "No symbol file now." "$msg"
66         }
67     }
69     set before_addr [get_pc "get before PC"]
71     gdb_test "break *\$pc" "Breakpoint .* at $hex"
73     gdb_test_no_output "set displaced-stepping $displaced"
75     gdb_test "stepi" "$hex in \?\? .*"
77     set after_addr [get_pc "get after PC"]
79     gdb_assert {[regexp "^${hex}$" $before_addr] \
80                     && [regexp "^${hex}$" $after_addr] \
81                     && $before_addr != $after_addr} "advanced"
84 foreach displaced { "off" "on" "auto" } {
85     if { $displaced != "off" && ![support_displaced_stepping] } {
86         continue
87     }
89     with_test_prefix "displaced=$displaced" {
90         test_step_over $displaced
91     }