2004-07-06 17:08:54 +02:00
|
|
|
# This testcase is part of GDB, the GNU debugger.
|
|
|
|
|
2018-01-01 05:43:02 +01:00
|
|
|
# Copyright 2004-2018 Free Software Foundation, Inc.
|
2004-07-06 17:08:54 +02:00
|
|
|
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
2007-08-23 20:14:19 +02:00
|
|
|
# the Free Software Foundation; either version 3 of the License, or
|
2004-07-06 17:08:54 +02:00
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
2007-08-23 20:14:19 +02:00
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2004-07-06 17:08:54 +02:00
|
|
|
|
|
|
|
# Check that GDB can and only executes single instructions when
|
|
|
|
# stepping through a sequence of breakpoints interleaved by a signal
|
|
|
|
# handler.
|
|
|
|
|
|
|
|
# This test is known to tickle the following problems: kernel letting
|
|
|
|
# the inferior execute both the system call, and the instruction
|
|
|
|
# following, when single-stepping a system call; kernel failing to
|
|
|
|
# propogate the single-step state when single-stepping the sigreturn
|
|
|
|
# system call, instead resuming the inferior at full speed; GDB
|
|
|
|
# doesn't know how to software single-step across a sigreturn
|
|
|
|
# instruction. Since the kernel problems can be "fixed" using
|
|
|
|
# software single-step this is KFAILed rather than XFAILed.
|
|
|
|
|
2005-03-08 11:12:21 +01:00
|
|
|
if [target_info exists gdb,nosignals] {
|
2007-03-23 13:41:18 +01:00
|
|
|
verbose "Skipping sigbpt.exp because of nosignals."
|
2005-03-08 11:12:21 +01:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2004-07-06 17:08:54 +02:00
|
|
|
|
test suite update - gdb.base/s*
Convert files gdb.base/s*.exp to use standard_output_file et al.
* gdb.base/save-bp.exp, gdb.base/savedregs.exp,
gdb.base/scope.exp, gdb.base/sep.exp, gdb.base/sepsymtab.exp,
gdb.base/set-lang-auto.exp, gdb.base/setshow.exp,
gdb.base/setvar.exp, gdb.base/shlib-call.exp,
gdb.base/shreloc.exp, gdb.base/sigall.exp,
gdb.base/sigaltstack.exp, gdb.base/sigbpt.exp,
gdb.base/sigchld.exp, gdb.base/siginfo-addr.exp,
gdb.base/siginfo-infcall.exp, gdb.base/siginfo-obj.exp,
gdb.base/siginfo.exp, gdb.base/signals.exp, gdb.base/signest.exp,
gdb.base/signull.exp, gdb.base/sigrepeat.exp,
gdb.base/sigstep.exp, gdb.base/sizeof.exp,
gdb.base/skip-solib.exp, gdb.base/so-impl-ld.exp,
gdb.base/solib-display.exp, gdb.base/solib-nodir.exp,
gdb.base/solib-overlap.exp, gdb.base/solib-symbol.exp,
gdb.base/solib-weak.exp, gdb.base/source.exp,
gdb.base/stack-checking.exp, gdb.base/stale-infcall.exp,
gdb.base/stap-probe.exp, gdb.base/start.exp,
gdb.base/step-break.exp, gdb.base/step-bt.exp,
gdb.base/step-line.exp, gdb.base/step-resume-infcall.exp,
gdb.base/step-test.exp, gdb.base/structs.exp,
gdb.base/structs2.exp, gdb.base/structs3.exp,
gdb.base/symbol-without-target_section.exp: Use standard_testfile,
standard_output_file, prepare_for_testing, clean_restart.
2013-06-27 20:58:28 +02:00
|
|
|
standard_testfile
|
|
|
|
|
2016-12-23 17:52:18 +01:00
|
|
|
if {[prepare_for_testing "failed to prepare" $testfile $srcfile debug]} {
|
2006-08-10 07:27:22 +02:00
|
|
|
return -1
|
2004-07-06 17:08:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#
|
|
|
|
# Run to `main' where we begin our tests.
|
|
|
|
#
|
|
|
|
|
|
|
|
if ![runto_main] then {
|
|
|
|
gdb_suppress_tests
|
|
|
|
}
|
|
|
|
|
|
|
|
# If we can examine what's at memory address 0, it is possible that we
|
|
|
|
# could also execute it. This could probably make us run away,
|
|
|
|
# executing random code, which could have all sorts of ill effects,
|
|
|
|
# especially on targets without an MMU. Don't run the tests in that
|
|
|
|
# case.
|
|
|
|
|
2014-08-07 10:09:38 +02:00
|
|
|
if { [is_address_zero_readable] } {
|
2016-12-01 21:40:05 +01:00
|
|
|
untested "memory at address 0 is possibly executable"
|
2014-08-07 10:09:38 +02:00
|
|
|
return
|
2004-07-06 17:08:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
gdb_test "break keeper"
|
|
|
|
|
|
|
|
# Run to bowler, and then single step until there's a SIGSEGV. Record
|
|
|
|
# the address of each single-step instruction (up to and including the
|
|
|
|
# instruction that causes the SIGSEGV) in bowler_addrs, and the address
|
|
|
|
# of the actual SIGSEGV in segv_addr.
|
2009-02-05 14:59:18 +01:00
|
|
|
# Note: this test detects which signal is received. Usually it is SIGSEGV
|
|
|
|
# (and we use SIGSEGV in comments) but on Darwin it is SIGBUS.
|
2004-07-06 17:08:54 +02:00
|
|
|
|
|
|
|
set bowler_addrs bowler
|
2007-05-17 14:09:31 +02:00
|
|
|
set segv_addr none
|
2004-07-06 17:08:54 +02:00
|
|
|
gdb_test {display/i $pc}
|
PowerPC64 ELFv2 ABI: skip global entry point code
This patch handles another aspect of the ELFv2 ABI, which unfortunately
requires common code changes.
In ELFv2, functions may provide both a global and a local entry point.
The global entry point (where the function symbol points to) is intended
to be used for function-pointer or cross-module (PLT) calls, and requires
r12 to be set up to the entry point address itself. The local entry
point (which is found at a fixed offset after the global entry point,
as defined by bits in the symbol table entries' st_other field), instead
expects r2 to be set up to the current TOC.
Now, when setting a breakpoint on a function by name, you really want
that breakpoint to trigger either way, no matter whether the function
is called via its local or global entry point. Since the global entry
point will always fall through into the local entry point, the way to
achieve that is to simply set the breakpoint at the local entry point.
One way to do that would be to have prologue parsing skip the code
sequence that makes up the global entry point. Unfortunately, this
does not work reliably, since -for optimized code- GDB these days
will not actuall invoke the prologue parsing code but instead just
set the breakpoint at the symbol address and rely on DWARF being
correct at any point throughout the function ...
Unfortunately, I don't really see any way to express the notion of
local entry points with the current set of gdbarch callbacks.
Thus this patch adds a new callback, skip_entrypoint, that is
somewhat analogous to skip_prologue, but is called every time
GDB needs to determine a function start address, even in those
cases where GDB decides to not call skip_prologue.
As a side effect, the skip_entrypoint implementation on ppc64
does not need to perform any instruction parsing; it can simply
rely on the local entry point flags in the symbol table entry.
With this implemented, two test cases would still fail to set
the breakpoint correctly, but that's because they use the construct:
gdb_test "break *hello"
Now, using "*hello" explicitly instructs GDB to set the breakpoint
at the numerical value of "hello" treated as function pointer, so
it will by definition only hit the global entry point.
I think this behaviour is unavoidable, but acceptable -- most people
do not use this construct, and if they do, they get what they
asked for ...
In one of those two test cases, use of this construct is really
not appropriate. I think this was added way back when as a means
to work around prologue skipping problems on some platforms. These
days that shouldn't really be necessary any more ...
For the other (step-bt), we really want to make sure backtracing
works on the very first instruction of the routine. To enable that
test also on powerpc64le-linux, we can modify the code to call the
test function via function pointer (which makes it use the global
entry point in the ELFv2 ABI).
gdb/ChangeLog:
* gdbarch.sh (skip_entrypoint): New callback.
* gdbarch.c, gdbarch.h: Regenerate.
* symtab.c (skip_prologue_sal): Call gdbarch_skip_entrypoint.
* infrun.c (fill_in_stop_func): Likewise.
* ppc-linux-tdep.c: Include "elf/ppc64.h".
(ppc_elfv2_elf_make_msymbol_special): New function.
(ppc_elfv2_skip_entrypoint): Likewise.
(ppc_linux_init_abi): Install them for ELFv2.
gdb/testsuite/ChangeLog:
* gdb.base/sigbpt.exp: Do not use "*" when setting breakpoint
on a function.
* gdb.base/step-bt.c: Call hello via function pointer to make
sure its first instruction is executed on powerpc64le-linux.
2014-02-04 18:44:14 +01:00
|
|
|
gdb_test "advance bowler" "bowler.*" "advance to the bowler"
|
2009-02-05 14:59:18 +01:00
|
|
|
set test "stepping to fault"
|
|
|
|
set signame "SIGSEGV"
|
2004-07-06 17:08:54 +02:00
|
|
|
gdb_test_multiple "stepi" "$test" {
|
2009-10-21 20:02:27 +02:00
|
|
|
-re "Program received signal (SIGBUS|SIGSEGV).*pc(\r\n| *) *=> (0x\[0-9a-f\]*).*$gdb_prompt $" {
|
2009-02-05 14:59:18 +01:00
|
|
|
set signame $expect_out(1,string)
|
|
|
|
set segv_addr $expect_out(3,string)
|
2004-07-06 17:08:54 +02:00
|
|
|
pass "$test"
|
|
|
|
}
|
2009-10-21 20:02:27 +02:00
|
|
|
-re " .*pc(\r\n| *)=> (0x\[0-9a-f\]*).*bowler.*$gdb_prompt $" {
|
2007-06-21 17:26:05 +02:00
|
|
|
set bowler_addrs [concat $expect_out(2,string) $bowler_addrs]
|
2004-07-06 17:08:54 +02:00
|
|
|
send_gdb "stepi\n"
|
|
|
|
exp_continue
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
# Now record the address of the instruction following the faulting
|
|
|
|
# instruction in bowler_addrs.
|
|
|
|
|
|
|
|
set test "get insn after fault"
|
|
|
|
gdb_test_multiple {x/2i $pc} "$test" {
|
2009-10-21 20:02:27 +02:00
|
|
|
-re "=> (0x\[0-9a-f\]*).*bowler.*(0x\[0-9a-f\]*).*bowler.*$gdb_prompt $" {
|
2004-07-06 17:08:54 +02:00
|
|
|
set bowler_addrs [concat $expect_out(2,string) $bowler_addrs]
|
|
|
|
pass "$test"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
# Procedures for returning the address of the instruction before, at
|
|
|
|
# and after, the faulting instruction.
|
|
|
|
|
|
|
|
proc before_segv { } {
|
|
|
|
global bowler_addrs
|
|
|
|
return [lindex $bowler_addrs 2]
|
|
|
|
}
|
|
|
|
|
|
|
|
proc at_segv { } {
|
|
|
|
global bowler_addrs
|
|
|
|
return [lindex $bowler_addrs 1]
|
|
|
|
}
|
|
|
|
|
|
|
|
proc after_segv { } {
|
|
|
|
global bowler_addrs
|
|
|
|
return [lindex $bowler_addrs 0]
|
|
|
|
}
|
|
|
|
|
|
|
|
# Check that the address table and SIGSEGV correspond.
|
|
|
|
|
2016-12-01 21:40:05 +01:00
|
|
|
set test "verify that ${signame} occurs at the last STEPI insn"
|
2004-07-06 17:08:54 +02:00
|
|
|
if {[string compare $segv_addr [at_segv]] == 0} {
|
|
|
|
pass "$test"
|
|
|
|
} else {
|
|
|
|
fail "$test ($segv_addr [at_segv])"
|
|
|
|
}
|
|
|
|
|
|
|
|
# Check that the inferior is correctly single stepped all the way back
|
|
|
|
# to a faulting instruction.
|
|
|
|
|
|
|
|
proc stepi_out { name args } {
|
|
|
|
global gdb_prompt
|
2009-02-05 14:59:18 +01:00
|
|
|
global signame
|
2004-07-06 17:08:54 +02:00
|
|
|
|
|
|
|
# Set SIGSEGV to pass+nostop and then run the inferior all the way
|
|
|
|
# through to the signal handler. With the handler is reached,
|
|
|
|
# disable SIGSEGV, ensuring that further signals stop the
|
|
|
|
# inferior. Stops a SIGSEGV infinite loop when a broke system
|
|
|
|
# keeps re-executing the faulting instruction.
|
|
|
|
rerun_to_main
|
2010-06-10 21:48:20 +02:00
|
|
|
gdb_test "handle ${signame} nostop print pass" ".*" "${name}; pass ${signame}"
|
2004-07-08 16:19:21 +02:00
|
|
|
gdb_test "continue" "keeper.*" "${name}; continue to keeper"
|
2010-06-10 21:48:20 +02:00
|
|
|
gdb_test "handle ${signame} stop print nopass" ".*" "${name}; nopass ${signame}"
|
2004-07-06 17:08:54 +02:00
|
|
|
|
|
|
|
# Insert all the breakpoints. To avoid the need to step over
|
|
|
|
# these instructions, this is delayed until after the keeper has
|
|
|
|
# been reached.
|
|
|
|
for {set i 0} {$i < [llength $args]} {incr i} {
|
|
|
|
gdb_test "break [lindex $args $i]" "Breakpoint.*" \
|
2004-07-08 16:19:21 +02:00
|
|
|
"${name}; set breakpoint $i of [llength $args]"
|
2004-07-06 17:08:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
# Single step our way out of the keeper, through the signal
|
|
|
|
# trampoline, and back to the instruction that faulted.
|
2004-07-08 16:19:21 +02:00
|
|
|
set test "${name}; stepi out of handler"
|
2004-07-06 17:08:54 +02:00
|
|
|
gdb_test_multiple "stepi" "$test" {
|
2006-05-01 18:39:36 +02:00
|
|
|
-re "Could not insert single-step breakpoint.*$gdb_prompt $" {
|
2014-10-28 15:32:51 +01:00
|
|
|
setup_kfail gdb/8841 "sparc*-*-openbsd*"
|
2006-05-01 18:39:36 +02:00
|
|
|
fail "$test (could not insert single-step breakpoint)"
|
|
|
|
}
|
2015-07-15 17:30:14 +02:00
|
|
|
-re "Cannot insert breakpoint.*Cannot access memory.*$gdb_prompt $" {
|
|
|
|
setup_kfail gdb/8841 "nios2*-*-linux*"
|
|
|
|
fail "$test (could not insert single-step breakpoint)"
|
|
|
|
}
|
2004-07-06 17:08:54 +02:00
|
|
|
-re "keeper.*$gdb_prompt $" {
|
|
|
|
send_gdb "stepi\n"
|
|
|
|
exp_continue
|
|
|
|
}
|
|
|
|
-re "signal handler.*$gdb_prompt $" {
|
|
|
|
send_gdb "stepi\n"
|
|
|
|
exp_continue
|
|
|
|
}
|
|
|
|
-re "Program received signal SIGSEGV.*$gdb_prompt $" {
|
2014-10-28 15:32:51 +01:00
|
|
|
kfail gdb/8807 "$test (executed fault insn)"
|
2004-07-06 17:08:54 +02:00
|
|
|
}
|
2007-06-21 17:26:05 +02:00
|
|
|
-re "Breakpoint.*pc(\r\n| *)[at_segv] .*bowler.*$gdb_prompt $" {
|
2004-07-06 17:08:54 +02:00
|
|
|
pass "$test (at breakpoint)"
|
|
|
|
}
|
2007-06-21 17:26:05 +02:00
|
|
|
-re "Breakpoint.*pc(\r\n| *)[after_segv] .*bowler.*$gdb_prompt $" {
|
2014-10-28 15:32:51 +01:00
|
|
|
kfail gdb/8807 "$test (executed breakpoint)"
|
2004-07-06 17:08:54 +02:00
|
|
|
}
|
2007-06-21 17:26:05 +02:00
|
|
|
-re "pc(\r\n| *)[at_segv] .*bowler.*$gdb_prompt $" {
|
2004-07-06 17:08:54 +02:00
|
|
|
pass "$test"
|
|
|
|
}
|
2007-06-21 17:26:05 +02:00
|
|
|
-re "pc(\r\n| *)[after_segv] .*bowler.*$gdb_prompt $" {
|
2014-10-28 15:32:51 +01:00
|
|
|
kfail gdb/8807 "$test (skipped fault insn)"
|
2004-07-06 17:08:54 +02:00
|
|
|
}
|
2009-10-21 20:02:27 +02:00
|
|
|
-re "pc(\r\n| *)=> 0x\[a-z0-9\]* .*bowler.*$gdb_prompt $" {
|
2014-10-28 15:32:51 +01:00
|
|
|
kfail gdb/8807 "$test (corrupt pc)"
|
2004-07-07 19:30:10 +02:00
|
|
|
}
|
2004-07-06 17:08:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
# Clear any breakpoints
|
|
|
|
for {set i 0} {$i < [llength $args]} {incr i} {
|
|
|
|
gdb_test "clear [lindex $args $i]" "Deleted .*" \
|
2004-07-08 16:19:21 +02:00
|
|
|
"${name}; clear breakpoint $i of [llength $args]"
|
2004-07-06 17:08:54 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
# Let a signal handler exit, returning to a breakpoint instruction
|
|
|
|
# inserted at the original fault instruction. Check that the
|
|
|
|
# breakpoint is hit, and that single stepping off that breakpoint
|
|
|
|
# executes the underlying fault instruction causing a SIGSEGV.
|
|
|
|
|
|
|
|
proc cont_out { name args } {
|
|
|
|
global gdb_prompt
|
2009-02-05 14:59:18 +01:00
|
|
|
global signame
|
2004-07-06 17:08:54 +02:00
|
|
|
|
|
|
|
# Set SIGSEGV to pass+nostop and then run the inferior all the way
|
|
|
|
# through to the signal handler. With the handler is reached,
|
|
|
|
# disable SIGSEGV, ensuring that further signals stop the
|
|
|
|
# inferior. Stops a SIGSEGV infinite loop when a broke system
|
|
|
|
# keeps re-executing the faulting instruction.
|
|
|
|
rerun_to_main
|
2010-06-10 21:48:20 +02:00
|
|
|
gdb_test "handle ${signame} nostop print pass" ".*" "${name}; pass ${signame}"
|
2004-07-08 16:19:21 +02:00
|
|
|
gdb_test "continue" "keeper.*" "${name}; continue to keeper"
|
2010-06-10 21:48:20 +02:00
|
|
|
gdb_test "handle ${signame} stop print nopass" ".*" "${name}; nopass ${signame}"
|
2004-07-06 17:08:54 +02:00
|
|
|
|
|
|
|
# Insert all the breakpoints. To avoid the need to step over
|
|
|
|
# these instructions, this is delayed until after the keeper has
|
|
|
|
# been reached. Always set a breakpoint at the signal trampoline
|
|
|
|
# instruction.
|
|
|
|
set args [concat $args "*[at_segv]"]
|
|
|
|
for {set i 0} {$i < [llength $args]} {incr i} {
|
|
|
|
gdb_test "break [lindex $args $i]" "Breakpoint.*" \
|
2004-07-08 16:19:21 +02:00
|
|
|
"${name}; set breakpoint $i of [llength $args]"
|
2004-07-06 17:08:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
# Let the handler return, it should "appear to hit" the breakpoint
|
|
|
|
# inserted at the faulting instruction. Note that the breakpoint
|
|
|
|
# instruction wasn't executed, rather the inferior was SIGTRAPed
|
|
|
|
# with the PC at the breakpoint.
|
2009-10-21 20:02:27 +02:00
|
|
|
gdb_test "continue" "Breakpoint.*pc(\r\n| *)=> [at_segv] .*" \
|
2004-07-08 16:19:21 +02:00
|
|
|
"${name}; continue to breakpoint at fault"
|
2004-07-06 17:08:54 +02:00
|
|
|
|
|
|
|
# Now single step the faulted instrction at that breakpoint.
|
|
|
|
gdb_test "stepi" \
|
2009-10-21 20:02:27 +02:00
|
|
|
"Program received signal ${signame}.*pc(\r\n| *)=> [at_segv] .*" \
|
2004-07-08 16:19:21 +02:00
|
|
|
"${name}; stepi fault"
|
2004-07-06 17:08:54 +02:00
|
|
|
|
|
|
|
# Clear any breakpoints
|
|
|
|
for {set i 0} {$i < [llength $args]} {incr i} {
|
|
|
|
gdb_test "clear [lindex $args $i]" "Deleted .*" \
|
2004-07-08 16:19:21 +02:00
|
|
|
"${name}; clear breakpoint $i of [llength $args]"
|
2004-07-06 17:08:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Try to confuse DECR_PC_AFTER_BREAK architectures by scattering
|
|
|
|
# breakpoints around the faulting address. In all cases the inferior
|
|
|
|
# should single-step out of the signal trampoline halting (but not
|
|
|
|
# executing) the fault instruction.
|
|
|
|
|
|
|
|
stepi_out "stepi"
|
|
|
|
stepi_out "stepi bp before segv" "*[before_segv]"
|
|
|
|
stepi_out "stepi bp at segv" "*[at_segv]"
|
|
|
|
stepi_out "stepi bp before and at segv" "*[at_segv]" "*[before_segv]"
|
|
|
|
|
|
|
|
|
|
|
|
# Try to confuse DECR_PC_AFTER_BREAK architectures by scattering
|
|
|
|
# breakpoints around the faulting address. In all cases the inferior
|
|
|
|
# should exit the signal trampoline halting at the breakpoint that
|
|
|
|
# replaced the fault instruction.
|
|
|
|
cont_out "cont"
|
|
|
|
cont_out "cont bp after segv" "*[before_segv]"
|
|
|
|
cont_out "cont bp before and after segv" "*[before_segv]" "*[after_segv]"
|