old-cross-binutils/gdb/testsuite/gdb.base/foll-exec-mode.exp

205 lines
5.9 KiB
Text
Raw Normal View History

# Copyright 1997-2016 Free Software Foundation, Inc.
# 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
# the Free Software Foundation; either version 3 of the License, or
# (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
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# This is a test of gdb's follow-exec-mode.
#
# It first checks that exec events are supported by using a catchpoint,
# then tests multiple scenarios for follow-exec-mode using parameters
# that test:
# - each mode
# - different commands to execute past the exec
# - re-running both the original and new inferiors.
#
# Note that we can't single-step past an exec call. There has to
# be a breakpoint in order to stop after the exec, even if we use
# a single-step command to execute past the exec.
Target remote mode fork and exec test updates This patch updates tests for fork and exec events in target remote mode. In the majority of cases this was a simple matter of removing some code that disabled the test for target remote. In a few cases the test needed to be disabled; in those cases the gdb_protocol was checked instead of using the [is_remote target] etc. In a couple of cases we needed to use clean_restart, since target remote doesn't support the run command, and in one case we had to modify an expect expression to allow for a "multiprocess-style" ptid. Tested with the patch that implemented target remote mode fork and exec event support. gdb/testsuite/ChangeLog: * gdb.base/execl-update-breakpoints.exp (main): Enable for target remote. * gdb.base/foll-exec-mode.exp (main): Disable for target remote. * gdb.base/foll-exec.exp (main): Enable for target remote. * gdb.base/foll-fork.exp (main): Likewise. * gdb.base/foll-vfork.exp (main): Likewise. * gdb.base/multi-forks.exp (main): Likewise, and use clean_restart. (proc continue_to_exit_bp_loc): Use clean_restart. * gdb.base/pie-execl.exp (main): Disable for target remote. * gdb.base/watch-vfork.exp (main): Enable for target remote. * gdb.mi/mi-nsthrexec.exp (main): Likewise. * gdb.threads/execl.exp (main): Likewise. * gdb.threads/fork-child-threads.exp (main): Likewise. * gdb.threads/fork-plus-threads.exp (main): Disable for target remote. * gdb.threads/fork-thread-pending.exp (main): Enable for target remote. * gdb.threads/linux-dp.exp (check_philosopher_stack): Allow pid.tid style ptids, instead of just tid. * gdb.threads/thread-execl.exp (main): Enable for target remote. * gdb.threads/watchpoint-fork.exp (main): Likewise. * gdb.trace/report.exp (use_collected_data): Allow pid.tid style ptids, instead of just tid.
2015-12-14 19:18:05 +00:00
# Remote mode doesn't support the 'run' command, which is
# required for follow-exec-mode testing.
if { [target_info exists gdb_protocol]
&& [target_info gdb_protocol] == "remote" } {
continue
}
# Until "catch exec" is implemented on other targets...
#
Remove HP-UX references fom testsuite This patch removes all special cases for HP-UX, for which support has been removed earlier, that I found in the testsuite. Note that the hppa architecture != HP-UX, since other OSes can run on hppa, so I tried to leave everything that is not HP-UX specific. Two complete tests were completely HP-UX specific, so I removed them. I ran the testsuite on Linux x86-64, native and native-gdbserver, and noticed no regressions. gdb/testsuite/ChangeLog: * gdb.asm/asm-source.exp: Remove HP-UX references. * gdb.base/annota1.exp: Likewise. * gdb.base/annota3.exp: Likewise. * gdb.base/attach.exp: Likewise. * gdb.base/bigcore.exp: Likewise. * gdb.base/break.exp: Likewise. * gdb.base/call-ar-st.exp: Likewise. * gdb.base/callfuncs.exp: Likewise. * gdb.base/catch-fork-static.exp: Likewise. * gdb.base/display.exp: Likewise. * gdb.base/foll-exec-mode.exp: Likewise. * gdb.base/foll-exec.exp: Likewise. * gdb.base/foll-fork.exp: Likewise. * gdb.base/foll-vfork.exp: Likewise. * gdb.base/funcargs.exp: Likewise. * gdb.base/hbreak2.exp: Likewise. * gdb.base/inferior-died.exp: Likewise. * gdb.base/interrupt.exp: Likewise. * gdb.base/multi-forks.exp: Likewise. * gdb.base/nodebug.exp: Likewise. * gdb.base/sepdebug.exp: Likewise. * gdb.base/solib1.c: Likewise. * gdb.base/step-test.exp: Likewise. * gdb.mi/non-stop.c: Likewise. * gdb.mi/pthreads.c: Likewise. * gdb.multi/bkpt-multi-exec.ex: Likewise. * gdb.threads/pthreads.c: Likewise. * gdb.threads/staticthreads.exp: Likewise. * lib/future.exp: Likewise. * lib/gdb.exp: Likewise. * gdb.base/so-indr-cl.c: Remove. * gdb.base/so-indr-cl.exp: Likewise. * gdb.base/solib.c: Likewise. * gdb.base/solib.exp: Likewise. * gdb.base/solib2.c: Likewise.
2015-12-21 17:51:54 +00:00
if {![istarget "*-linux*"]} then {
continue
}
standard_testfile foll-exec-mode.c
set testfile2 "execd-prog"
set srcfile2 ${testfile2}.c
set binfile2 [standard_output_file ${testfile2}]
set compile_options debug
set dirname [relative_filename [pwd] [file dirname $binfile]]
lappend compile_options "additional_flags=-DBASEDIR=\"$dirname\""
# build the first test case
if { [gdb_compile "${srcdir}/${subdir}/${srcfile2}" "${binfile2}" executable $compile_options] != "" } {
untested foll-exec-mode.exp
return -1
}
if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable $compile_options] != "" } {
untested foll-exec-mode.exp
return -1
}
# Test exec catchpoints to ensure exec events are supported.
#
proc do_catch_exec_test { } {
global testfile
global gdb_prompt
clean_restart $testfile
# Start the program running, and stop at main.
#
if ![runto_main] then {
fail "Couldn't run ${testfile}"
return
}
# Verify that the system supports "catch exec".
gdb_test "catch exec" "Catchpoint \[0-9\]* \\(exec\\)" "insert first exec catchpoint"
set has_exec_catchpoints 0
gdb_test_multiple "continue" "continue to first exec catchpoint" {
-re ".*Your system does not support this type\r\nof catchpoint.*$gdb_prompt $" {
unsupported "continue to first exec catchpoint"
}
-re ".*Catchpoint.*$gdb_prompt $" {
set has_exec_catchpoints 1
pass "continue to first exec catchpoint"
}
}
if {$has_exec_catchpoints == 0} {
unsupported "exec catchpoints"
return
}
}
# Test follow-exec-mode in the specified scenario.
# MODE determines whether follow-exec-mode is "same" or "new".
# CMD determines the command used to execute past the exec call.
# INFSWITCH is ignored for MODE == "same", and for "new" it is
# used to determine whether to switch to the original inferior
# before re-running.
proc do_follow_exec_mode_tests { mode cmd infswitch } {
global binfile srcfile srcfile2 testfile testfile2
global gdb_prompt
with_test_prefix "$mode,$cmd,$infswitch" {
clean_restart $testfile
# Start the program running, and stop at main.
#
if ![runto_main] then {
fail "Couldn't run ${testfile}"
return
}
# Set the follow-exec mode.
#
gdb_test_no_output "set follow-exec-mode $mode"
# Run to the line of the exec call.
#
gdb_breakpoint [gdb_get_line_number "Set breakpoint here"]
gdb_continue_to_breakpoint "continue to line of exec call"
# Set up the output we expect to see after we execute past the exec.
#
set execd_line [gdb_get_line_number "after-exec" $srcfile2]
set expected_re ".*xecuting new program: .*${testfile2}.*Breakpoint .,.*${srcfile2}:${execd_line}.*$gdb_prompt $"
# Set a breakpoint after the exec call if we aren't single-stepping
# past it.
#
if {$cmd == "continue"} {
gdb_breakpoint "$execd_line"
}
# Execute past the exec call.
#
set test "$cmd past exec"
gdb_test_multiple $cmd $test {
-re "$expected_re" {
pass $test
}
}
# Set expected output, given the test parameters.
#
if {$mode == "same"} {
set expected_re "\\* 1.*process.*"
} else {
Reapply: List inferiors/threads/pspaces in ascending order [This reapplies a change that was accidentally reverted with c0ecb95f3d.] Before: (gdb) info threads Id Target Id Frame 3 Thread 0x7ffff77c3700 (LWP 29035) callme () at foo.c:30 2 Thread 0x7ffff7fc4700 (LWP 29034) 0x000000000040087b in child_function_2 (arg=0x0) at foo.c:60 * 1 Thread 0x7ffff7fc5740 (LWP 29030) 0x0000003b37209237 in pthread_join (threadid=140737353893632, thread_return=0x0) at pthread_join.c:92 After: (gdb) info threads Id Target Id Frame * 1 Thread 0x7ffff7fc5740 (LWP 29030) 0x0000003b37209237 in pthread_join (threadid=140737353893632, thread_return=0x0) at pthread_join.c:92 2 Thread 0x7ffff7fc4700 (LWP 29034) 0x000000000040087b in child_function_2 (arg=0x0) at foo.c:60 3 Thread 0x7ffff77c3700 (LWP 29035) callme () at foo.c:30 gdb/doc/ChangeLog: 2015-11-24 Pedro Alves <palves@redhat.com> PR 17539 * gdb.texinfo (Inferiors and Programs): Adjust "maint info program-spaces" example to ascending order listing. (Threads): Adjust "info threads" example to ascending order listing. (Forks): Adjust "info inferiors" example to ascending order listing. gdb/ChangeLog: 2015-11-24 Pedro Alves <palves@redhat.com> PR 17539 * inferior.c (add_inferior_silent): Append the new inferior to the end of the list. * progspace.c (add_program_space): Append the new pspace to the end of the list. * thread.c (new_thread): Append the new thread to the end of the list. gdb/testsuite/ChangeLog: 2015-11-24 Pedro Alves <palves@redhat.com> PR 17539 * gdb.base/foll-exec-mode.exp: Adjust to GDB listing inferiors and threads in ascending order. * gdb.base/foll-fork.exp: Likewise. * gdb.base/foll-vfork.exp: Likewise. * gdb.base/multi-forks.exp: Likewise. * gdb.mi/mi-nonstop.exp: Likewise. * gdb.mi/mi-nsintrall.exp: Likewise. * gdb.multi/base.exp: Likewise. * gdb.multi/multi-arch.exp: Likewise. * gdb.python/py-inferior.exp: Likewise. * gdb.threads/break-while-running.exp: Likewise. * gdb.threads/execl.exp: Likewise. * gdb.threads/gcore-thread.exp: Likewise. * gdb.threads/info-threads-cur-sal.exp: Likewise. * gdb.threads/kill.exp: Likewise. * gdb.threads/linux-dp.exp: Likewise. * gdb.threads/multiple-step-overs.exp: Likewise. * gdb.threads/next-bp-other-thread.exp: Likewise. * gdb.threads/step-bg-decr-pc-switch-thread.exp: Likewise. * gdb.threads/step-over-lands-on-breakpoint.exp: Likewise. * gdb.threads/step-over-trips-on-watchpoint.exp: Likewise. * gdb.threads/thread-find.exp: Likewise. * gdb.threads/tls.exp: Likewise. * lib/mi-support.exp (mi_reverse_list): Delete. (mi_check_thread_states): No longer reverse list.
2016-01-12 01:12:38 +00:00
set expected_re " 1.*null.*$testfile.*\r\n\\* 2.*process.*$testfile2 .*"
}
# Check that the inferior list is correct:
# - one inferior for MODE == "same"
# - two inferiors for MODE == "new", current is execd program
#
gdb_test "info inferiors" $expected_re "Check inferior list"
set expected_inf ""
if {$mode == "same"} {
# One inferior, the execd program.
set expected_inf $testfile2
} elseif {$infswitch == "infswitch"} {
# Two inferiors, we have switched to the original program.
set expected_inf $testfile
gdb_test "inferior 1" "Switching to inferior 1.*$testfile.*" "Switch inferiors"
} else {
# Two inferiors, run the execd program
set expected_inf $testfile2
}
# Now check that a 'run' command will run the correct inferior.
#
set test "use correct executable ($expected_inf) for run after follow exec"
gdb_run_cmd
gdb_test_multiple "" $test {
-re {Start it from the beginning\? \(y or n\) $} {
send_gdb "y\n"
exp_continue
}
-re "Starting program: .*$expected_inf.*Breakpoint .,.*\r\n$gdb_prompt $" {
pass $test
}
}
}
}
do_catch_exec_test
foreach cmd {"next" "continue"} {
foreach mode {"same" "new"} {
# Test basic follow-exec-mode.
do_follow_exec_mode_tests $mode $cmd "no_infswitch"
if {$mode == "new"} {
# Test that when we do 'run' we get the correct executable.
do_follow_exec_mode_tests $mode $cmd "infswitch"
}
}
}
return 0