833b4ed75ef76dcb0563067f78dd01dc32841b5e
[external/binutils.git] / gdb / testsuite / gdb.arch / i386-bp_permanent.exp
1 # Copyright (C) 2008-2014 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
17 # This file is part of the gdb testsuite.
18
19 # Test stepping over permanent breakpoints on i386.
20
21 if { ![istarget "i?86-*-*"] && ![istarget "x86_64-*-*"] } then {
22     verbose "Skipping skip over permanent breakpoint on i386 tests."
23     return
24 }
25
26 set testfile "i386-bp_permanent"
27 set srcfile i386-bp_permanent.c
28 set binfile ${objdir}/${subdir}/${testfile}
29
30 # some targets have leading underscores on assembly symbols.
31 set additional_flags [gdb_target_symbol_prefix_flags]
32
33 # Don't use "debug", so that we don't have line information for the assembly
34 # fragments.
35 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable [list $additional_flags]] != "" } {
36     untested ${testfile}.exp
37     return -1
38 }
39
40
41 gdb_exit
42 gdb_start
43 gdb_reinitialize_dir $srcdir/$subdir
44 gdb_load ${binfile}
45
46 #
47 # Run to `main' where we begin our tests.
48 #
49
50 if ![runto_main] then {
51   return -1
52 }
53
54 set function "standard"
55
56 set retcode [gdb_test_multiple "disassemble $function" "Disassemble function '$function'" {
57     -re "($hex) <\\+0>.*($hex) <\\+$decimal>.*int3.*($hex) <\\+$decimal>.*leave.*$gdb_prompt $" {
58       set address_bp $expect_out(2,string)
59       set address_after_bp $expect_out(3,string)
60     }
61 }]
62
63 if {$retcode != 0} {
64   fail "Disassemble failed, skipping entire test."
65   return -1
66 }
67
68 gdb_breakpoint "*$address_bp"
69
70 gdb_test "continue" "Breakpoint .*, $address_bp in $function.*" \
71          "stop at permanent breakpoint"
72
73 # We want to fetch the stack pointer at the start of '$function'
74 # function to make sure the skip_permanent_breakpoint implementation
75 # really skips only the permanent breakpoint.  If, for whatever
76 # reason, the 'leave' instruction executes, the stack pointer will not
77 # have this value.
78 set start_sp 0
79 gdb_test_multiple "print \$sp" "fetch stack pointer value" {
80     -re "\\\$1.*($hex).*$gdb_prompt $" {
81       set start_sp $expect_out(1,string)
82     }
83 }
84
85 gdb_test "stepi" "$address_after_bp in $function.*" \
86          "single-step past permanent breakpoint"
87
88 gdb_test "print \$sp" ".*$start_sp.*" \
89          "stack pointer value matches"