1*1424dfb3Schristos# Copyright (C) 2019-2020 Free Software Foundation, Inc.
207163879Schristos
307163879Schristos# This program is free software; you can redistribute it and/or modify
407163879Schristos# it under the terms of the GNU General Public License as published by
507163879Schristos# the Free Software Foundation; either version 3 of the License, or
607163879Schristos# (at your option) any later version.
707163879Schristos#
807163879Schristos# This program is distributed in the hope that it will be useful,
907163879Schristos# but WITHOUT ANY WARRANTY; without even the implied warranty of
1007163879Schristos# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1107163879Schristos# GNU General Public License for more details.
1207163879Schristos#
1307163879Schristos# You should have received a copy of the GNU General Public License
1407163879Schristos# along with this program.  If not, see <http://www.gnu.org/licenses/>.
1507163879Schristos
1607163879Schristos# Test breakpoints work correctly when stack protector is used.
1707163879Schristos
1807163879Schristos# Note on Debian/Ubuntu, stack protector is on by default, and is
1907163879Schristos# currently force disabled in gdb_compile due to the XFAIL below.
2007163879Schristos
2107163879Schristos# Ensure the compiler is gcc/clang and is new enough to support stack
2207163879Schristos# protection.
2307163879Schristosif { !([test_compiler_info "gcc-*"] || [test_compiler_info "clang-*"])
2407163879Schristos     || [test_compiler_info {gcc-[0-3]-*}]
2507163879Schristos     || [test_compiler_info {gcc-4-0-*}]
2607163879Schristos     || [test_compiler_info {clang-[0-4]=*}] } {
2707163879Schristos    return 0
2807163879Schristos}
2907163879Schristos
3007163879Schristosstandard_testfile
3107163879Schristos
3207163879Schristosset protector_options { "-fno-stack-protector" "-fstack-protector" \
3307163879Schristos			"-fstack-protector-all" "-fstack-protector-strong" }
3407163879Schristos
3507163879Schristosproc simple_func_break_test { protection } {
3607163879Schristos    global testfile
3707163879Schristos    global srcfile
3807163879Schristos    global binfile
3907163879Schristos
4007163879Schristos    set options debug
4107163879Schristos    lappend options additional_flags=$protection
4207163879Schristos
4307163879Schristos    if {[prepare_for_testing "failed to prepare" $testfile $srcfile $options]} {
4407163879Schristos	return -1
4507163879Schristos    }
4607163879Schristos
4707163879Schristos    clean_restart ${binfile}
4807163879Schristos
4907163879Schristos    if { ![runto_main] } then {
5007163879Schristos	fail "can't run to main"
5107163879Schristos	return -1
5207163879Schristos    }
5307163879Schristos
5407163879Schristos    # Break on function foo and ensure it stops on the first line of code.
5507163879Schristos    gdb_breakpoint "foo"
5607163879Schristos
5707163879Schristos    if { $protection == "-fstack-protector-all"
5807163879Schristos         && [test_compiler_info "gcc-*"] } {
5907163879Schristos	setup_xfail "gcc/88432" "*-*-linux*"
6007163879Schristos    }
6107163879Schristos    gdb_continue_to_breakpoint "foo" ".*break here.*"
6207163879Schristos
6307163879Schristos    return 1
6407163879Schristos}
6507163879Schristos
6607163879Schristosforeach_with_prefix protection $protector_options {
6707163879Schristos    simple_func_break_test $protection
6807163879Schristos}
69