1*56bb7041Schristos# Copyright (C) 2019-2020 Free Software Foundation, Inc.
23aed4a8bSchristos
33aed4a8bSchristos# This program is free software; you can redistribute it and/or modify
43aed4a8bSchristos# it under the terms of the GNU General Public License as published by
53aed4a8bSchristos# the Free Software Foundation; either version 3 of the License, or
63aed4a8bSchristos# (at your option) any later version.
73aed4a8bSchristos#
83aed4a8bSchristos# This program is distributed in the hope that it will be useful,
93aed4a8bSchristos# but WITHOUT ANY WARRANTY; without even the implied warranty of
103aed4a8bSchristos# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
113aed4a8bSchristos# GNU General Public License for more details.
123aed4a8bSchristos#
133aed4a8bSchristos# You should have received a copy of the GNU General Public License
143aed4a8bSchristos# along with this program.  If not, see <http://www.gnu.org/licenses/>.
153aed4a8bSchristos
163aed4a8bSchristos# Test breakpoints work correctly when stack protector is used.
173aed4a8bSchristos
183aed4a8bSchristos# Note on Debian/Ubuntu, stack protector is on by default, and is
193aed4a8bSchristos# currently force disabled in gdb_compile due to the XFAIL below.
203aed4a8bSchristos
213aed4a8bSchristos# Ensure the compiler is gcc/clang and is new enough to support stack
223aed4a8bSchristos# protection.
233aed4a8bSchristosif { !([test_compiler_info "gcc-*"] || [test_compiler_info "clang-*"])
243aed4a8bSchristos     || [test_compiler_info {gcc-[0-3]-*}]
253aed4a8bSchristos     || [test_compiler_info {gcc-4-0-*}]
263aed4a8bSchristos     || [test_compiler_info {clang-[0-4]=*}] } {
273aed4a8bSchristos    return 0
283aed4a8bSchristos}
293aed4a8bSchristos
303aed4a8bSchristosstandard_testfile
313aed4a8bSchristos
323aed4a8bSchristosset protector_options { "-fno-stack-protector" "-fstack-protector" \
333aed4a8bSchristos			"-fstack-protector-all" "-fstack-protector-strong" }
343aed4a8bSchristos
353aed4a8bSchristosproc simple_func_break_test { protection } {
363aed4a8bSchristos    global testfile
373aed4a8bSchristos    global srcfile
383aed4a8bSchristos    global binfile
393aed4a8bSchristos
403aed4a8bSchristos    set options debug
413aed4a8bSchristos    lappend options additional_flags=$protection
423aed4a8bSchristos
433aed4a8bSchristos    if {[prepare_for_testing "failed to prepare" $testfile $srcfile $options]} {
443aed4a8bSchristos	return -1
453aed4a8bSchristos    }
463aed4a8bSchristos
473aed4a8bSchristos    clean_restart ${binfile}
483aed4a8bSchristos
493aed4a8bSchristos    if { ![runto_main] } then {
503aed4a8bSchristos	fail "can't run to main"
513aed4a8bSchristos	return -1
523aed4a8bSchristos    }
533aed4a8bSchristos
543aed4a8bSchristos    # Break on function foo and ensure it stops on the first line of code.
553aed4a8bSchristos    gdb_breakpoint "foo"
563aed4a8bSchristos
573aed4a8bSchristos    if { $protection == "-fstack-protector-all"
583aed4a8bSchristos         && [test_compiler_info "gcc-*"] } {
593aed4a8bSchristos	setup_xfail "gcc/88432" "*-*-linux*"
603aed4a8bSchristos    }
613aed4a8bSchristos    gdb_continue_to_breakpoint "foo" ".*break here.*"
623aed4a8bSchristos
633aed4a8bSchristos    return 1
643aed4a8bSchristos}
653aed4a8bSchristos
663aed4a8bSchristosforeach_with_prefix protection $protector_options {
673aed4a8bSchristos    simple_func_break_test $protection
683aed4a8bSchristos}
69