Automatic Copyright Year update after running gdb/copyright.py
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.threads / step-over-exec.exp
CommitLineData
88b9d363 1# Copyright 2020-2022 Free Software Foundation, Inc.
3b7a962d
SM
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
16# Test stepping over an exec syscall instruction in a multi-threaded program.
17
18standard_testfile .c -execd.c
19
20set syscalls_src $srcdir/lib/my-syscalls.S
21
22# EXECR_THREAD is "leader" or "other", and decides which thread does the exec.
23#
24# If DIFFERENT_TEXT_SEGMENTS is true, the exec'er and exec'd program are
25# compiled with different, explicit text segment addresses. This makes it so
26# the address of the displaced stepping buffer in the old executable is likely
27# not accessible in the new executable. This might catch cases where GDB tries
28# (wrongfully) to restore the bytes saved from the old executable in the new
29# executable.
30#
31# DISPLACED_STEPPING is "auto" or "off" and controls the value of "set
32# displaced-stepping".
33
34proc do_test { execr_thread different_text_segments displaced_stepping } {
35 global srcdir subdir srcfile srcfile2 binfile
36 global syscalls_src
37 global decimal hex
38
39 set execr_srcs [list $srcdir/$subdir/$srcfile $syscalls_src]
40 set execd_srcs [list $srcdir/$subdir/$srcfile2]
41
42 # Generate unique filenames for each case.
43 set execr_binfile $binfile-execr-thread-$execr_thread-diff-text-segs-$different_text_segments
44 set execd_binfile $execr_binfile-execd
45
46 set execr_opts [list debug]
47 set execd_opts [list debug]
48
49 if { $different_text_segments } {
50 lappend execr_opts "ldflags=-Wl,-Ttext-segment=0x600000"
51 lappend execd_opts "ldflags=-Wl,-Ttext-segment=0x800000"
52 }
53
54 if { $execr_thread == "leader" } {
55 lappend execr_opts "additional_flags=-DLEADER_DOES_EXEC"
56 } elseif { $execr_thread == "other" } {
57 lappend execr_opts "additional_flags=-DOTHER_DOES_EXEC"
58 } else {
59 error "Invalid execr_thread value: $execr_thread."
60 }
61
62 # Compile execr binary (the one that does the exec).
63 if {[gdb_compile_pthreads $execr_srcs $execr_binfile executable $execr_opts] != "" } {
64 return -1
65 }
66
67 # Compile the second binary (the one that gets exec'd).
68 if {[gdb_compile $execd_srcs $execd_binfile executable $execd_opts] != "" } {
69 return -1
70 }
71
72 clean_restart ${execr_binfile}
73
74 gdb_test_no_output "set displaced-stepping $displaced_stepping"
75
76 if ![runto_main] {
77 return
78 }
79
80 # Leave breakpoint main inserted, we expect to hit it after exec.
81
82 # This breakpoint will be stepped by whatever thread does the exec.
83 gdb_test "break my_execve_syscall if 0" "Breakpoint $decimal at $hex.*"
84
85 # Continue across exec to main.
86 if { [target_is_gdbserver] } {
87 setup_kfail gdb/27020 "*-*-*"
88 }
89 set failed [gdb_test "continue" \
90 "process $decimal is executing new program: .* hit Breakpoint $decimal, main .*" \
91 "continue across exec"]
92 if { $failed } {
93 return
94 }
95
96 # Just to confirm we are indeed in the execd program.
97 gdb_test "print a_variable_in_execd" " = 1212"
98
99 # Continue execution to make sure we can step over the breakpoint on main.
100 # It would be nice to use gdb_continue_to_end to ensure the program can
101 # exit properly, but it hangs due to PR gdb/26995.
102 gdb_breakpoint foo
103 gdb_test "continue" "Breakpoint $decimal, foo .*" \
104 "continue to foo"
105}
106
107foreach_with_prefix displaced_stepping {auto off} {
108 foreach_with_prefix different_text_segments {true false} {
109 foreach_with_prefix execr_thread {leader other} {
110 do_test $execr_thread $different_text_segments $displaced_stepping
111 }
112 }
113}
This page took 0.114871 seconds and 4 git commands to generate.