1 # Copyright 2009-2012 Free Software Foundation, Inc.
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.
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.
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/>.
16 # This file is part of the GDB testsuite. It tests precord debugging
17 # with shared libraries and a logfile.
19 # This test suitable only for process record-replay
20 if ![supports_process_record] {
24 set testfile "solib-reverse"
25 set srcfile ${testfile}.c
27 set libsrc ${libfile}.c
28 set library ${objdir}/${subdir}/${libfile}.sl
29 set binfile ${objdir}/${subdir}/${testfile}
31 if [get_compiler_info ${binfile}] {
35 if { [gdb_compile_shlib ${srcdir}/${subdir}/${libsrc} ${library} "debug"] != "" } {
36 untested "Could not compile shared library."
40 set exec_opts [list debug shlib=${library}]
42 # Attempt to prevent -Wl,-z,relro which may happen by default with some
43 # toolchain configurations. Due to PR corefiles/11804 GDB will then produce
46 if { [gdb_compile ${srcdir}/${subdir}/${srcfile} ${binfile} executable \
47 [concat $exec_opts additional_flags=-Wl,-z,norelro]] != ""
48 && [gdb_compile ${srcdir}/${subdir}/${srcfile} ${binfile} executable $exec_opts] != "" } {
49 untested "Could not compile $binfile."
53 # Start with a fresh gdb.
58 # Clear it to never find any separate system debug infos.
59 gdb_test_no_output "set debug-file-directory"
61 gdb_reinitialize_dir $srcdir/$subdir
67 if [supports_process_record] {
68 # Activate process record/replay
69 gdb_test_no_output "record" "Turn on process record"
72 set end_of_main [gdb_get_line_number "end of main" ]
73 gdb_test "break $end_of_main" \
74 "Breakpoint $decimal at .*/$srcfile, line $end_of_main\." \
77 gdb_test "continue" "Breakpoint .* end of main .*" "run to end of main"
79 gdb_test "record save solib.precsave" \
80 "Saved core file solib.precsave with execution log\." \
81 "save process recfile"
83 gdb_test "kill" "" "Kill process, prepare to debug log file" \
84 "Kill the program being debugged\\? \\(y or n\\) " "y"
86 gdb_test "record restore solib.precsave" \
87 "Program terminated with signal .*" \
91 # Test reverse-step over undebuggable solib functions.
94 # Run forward past some solib function calls.
96 set end_part_one [gdb_get_line_number " end part one" "$srcfile"]
97 set end_part_two [gdb_get_line_number " end part two" "$srcfile"]
98 gdb_test "until $end_part_one" " end part one.*" "run until end part one"
100 gdb_test "reverse-step" " sleep three .*" "reverse-step third sleep"
101 gdb_test "reverse-step" " sleep two .*" "reverse-step second sleep"
102 gdb_test "reverse-step" " sleep one .*" \
103 "reverse-step first sleep, dynsym resolve"
105 gdb_test "reverse-step" " printf three .*" "reverse-step third printf"
106 gdb_test "reverse-step" " printf two .*" "reverse-step second printf"
107 gdb_test "reverse-step" " printf one .*" \
108 "reverse-step first printf, dynsym resolve"
109 gdb_test "reverse-step" " generic statement.*" "reverse-step generic"
113 # Test reverse-next over undebuggable solib functions.
116 # Run forward again...
118 gdb_test "until $end_part_one" " end part one.*" "forward to end part one"
120 gdb_test "reverse-next" " sleep three .*" "reverse-next third sleep"
121 gdb_test "reverse-next" " sleep two .*" "reverse-next second sleep"
122 gdb_test "reverse-next" " sleep one .*" \
123 "reverse-next first sleep, dynsym resolve"
125 gdb_test "reverse-next" " printf three .*" "reverse-next third printf"
126 gdb_test "reverse-next" " printf two .*" "reverse-next second printf"
127 gdb_test "reverse-next" " printf one .*" \
128 "reverse-next first printf, dynsym resolve"
129 gdb_test "reverse-next" " generic statement.*" "reverse-next generic"
133 # Test reverse-step into debuggable solib function
136 gdb_test "reverse-step" "${libsrc}.*" "reverse-step into solib function one"
137 gdb_test "reverse-step" "return 2.x.*" "reverse-step within solib function one"
138 gdb_test "reverse-step" " middle part two.*" "reverse-step back to main one"
140 gdb_test "reverse-step" "${libsrc}.*" "reverse-step into solib function two"
141 gdb_test "reverse-step" "return 2.x.*" "reverse-step within solib function two"
142 gdb_test "reverse-step" " begin part two.*" "reverse-step back to main two"
145 # Test reverse-next over debuggable solib function
148 gdb_test "until $end_part_two" " end part two.*" "run until end part two"
150 gdb_test "reverse-next" " middle part two.*" "reverse-next over solib function one"
151 gdb_test "reverse-next" " begin part two.*" "reverse-next over solib function two"