1# Copyright 2009-2020 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
16if { [skip_cplus_tests] } { continue }
17
18set srcfile expand-sals.cc
19if { [prepare_for_testing "failed to prepare" expand-sals $srcfile {debug c++}] } {
20    return -1
21}
22if ![runto_main] {
23    return -1
24}
25
26gdb_breakpoint [gdb_get_line_number "func-line"]
27gdb_continue_to_breakpoint "func" ".*func-line.*"
28
29gdb_test "up" "caller-line.*"
30
31# PC should not be now at the boundary of source lines to make the original bug
32# exploitable.  The GLOBAL_X variable exists in the source for this purpose.
33
34# Original problem was an internal error here.
35set test "break"
36gdb_test_multiple $test $test {
37    -re "Breakpoint \[0-9\]+ at .*, line \[0-9\]+\\. \\(\[2-9\] locations\\)\r\n$gdb_prompt $" {
38	fail $test
39    }
40    -re "Breakpoint \[0-9\]+ at .*, line \[0-9\]+\\.\r\n$gdb_prompt $" {
41	pass $test
42    }
43}
44
45gdb_continue_to_breakpoint "caller" ".*caller-line.*"
46
47# Test GDB caught this return call and not the next one through B::B()
48gdb_test "bt" \
49	 "#0 \[^\r\n\]* (A::)?A \[^\r\n\]*\r\n#1 \[^\r\n\]* main \[^\r\n\]*" \
50	 "bt from A"
51
52gdb_continue_to_breakpoint "next caller func" ".*func-line.*"
53