1148ad59eff0f84ca36336a66d02e4712468366b
[external/binutils.git] / gdb / testsuite / gdb.base / step-over-no-symbols.exp
1 # Copyright (C) 2015-2017 Free Software Foundation, Inc.
2
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.
7 #
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.
12 #
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/>.
15
16 # Test that GDB can step past a breakpoint even if GDB doesn't have
17 # symbols for the main binary.  PR gdb/13858.
18
19 standard_testfile start.c
20
21 if { [build_executable "failed to build" ${testfile} $srcfile] } {
22     return -1
23 }
24
25 # Get the current PC.  MSG is used as test message.
26
27 proc get_pc { msg } {
28     global hex gdb_prompt
29
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     }
37
38     return $addr
39 }
40
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.
45
46 proc test_step_over { displaced } {
47     global hex
48     global binfile
49
50     clean_restart $binfile
51
52     if ![runto_main] {
53         fail "couldn't run to main"
54         untested "stepping over breakpoint with displaced=$displaced"
55         return -1
56     }
57
58     delete_breakpoints
59
60     set msg "purging symbols"
61     gdb_test_multiple "file" "$msg" {
62         -re "Are you sure you want to change the file.*y or n. $" {
63             send_gdb "y\n"
64             exp_continue
65         }
66         -re "Discard symbol table.*y or n. $" {
67             gdb_test "y" "No symbol file now." "$msg"
68         }
69     }
70
71     set before_addr [get_pc "get before PC"]
72
73     gdb_test "break *\$pc" "Breakpoint .* at $hex"
74
75     gdb_test_no_output "set displaced-stepping $displaced"
76
77     gdb_test "stepi" "$hex in \?\? .*"
78
79     set after_addr [get_pc "get after PC"]
80
81     gdb_assert {$before_addr != $after_addr} "advanced"
82 }
83
84 foreach displaced { "off" "on" "auto" } {
85     if { $displaced != "off" && ![support_displaced_stepping] } {
86         continue
87     }
88
89     with_test_prefix "displaced=$displaced" {
90         test_step_over $displaced
91     }
92 }