| 1 | # Copyright (C) 2011-2016 Free Software Foundation, Inc. |
| 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 | # This file is part of the GDB testsuite. It tests the mechanism |
| 17 | # exposing values to Python. |
| 18 | |
| 19 | if {[skip_shlib_tests]} { |
| 20 | untested py-finish-breakpoint.exp |
| 21 | return 0 |
| 22 | } |
| 23 | |
| 24 | load_lib gdb-python.exp |
| 25 | |
| 26 | set libfile "py-events-shlib" |
| 27 | set libsrc $srcdir/$subdir/$libfile.c |
| 28 | set lib_sl [standard_output_file $libfile-nodebug.so] |
| 29 | set lib_opts "" |
| 30 | |
| 31 | standard_testfile |
| 32 | set exec_opts [list debug shlib=$lib_sl] |
| 33 | |
| 34 | if [get_compiler_info] { |
| 35 | return -1 |
| 36 | } |
| 37 | |
| 38 | if { [gdb_compile_shlib $libsrc $lib_sl $lib_opts] != "" |
| 39 | || [gdb_compile $srcdir/$subdir/$srcfile $binfile executable $exec_opts] != ""} { |
| 40 | untested "failed to compile" |
| 41 | return -1 |
| 42 | } |
| 43 | |
| 44 | # Start with a fresh gdb. |
| 45 | clean_restart ${testfile} |
| 46 | |
| 47 | if { [skip_python_tests] } { continue } |
| 48 | |
| 49 | if { $gdb_py_is_py24 == 1 } { |
| 50 | # Python 2.4, 2.5 do not support the "ValueError as e" syntax used in |
| 51 | # the py-finish-breakpoint.py script. |
| 52 | untested py-finish-breakpoint.exp |
| 53 | return 0 |
| 54 | } |
| 55 | |
| 56 | # Skip all tests if Python scripting is not enabled. |
| 57 | if { [skip_python_tests] } { continue } |
| 58 | |
| 59 | # |
| 60 | # Test FinishBreakpoint in normal conditions |
| 61 | # |
| 62 | |
| 63 | clean_restart ${testfile} |
| 64 | gdb_load_shlib ${lib_sl} |
| 65 | |
| 66 | if ![runto_main] then { |
| 67 | fail "cannot run to main." |
| 68 | return 0 |
| 69 | } |
| 70 | |
| 71 | set python_file [gdb_remote_download host \ |
| 72 | ${srcdir}/${subdir}/${testfile}.py] |
| 73 | |
| 74 | gdb_test_no_output "set confirm off" "disable confirmation" |
| 75 | gdb_test "source $python_file" "Python script imported.*" \ |
| 76 | "import python scripts" |
| 77 | gdb_breakpoint "increase_1" |
| 78 | gdb_test "continue" "Breakpoint .*at.*" "continue to the function to finish" |
| 79 | |
| 80 | # set FinishBreakpoint |
| 81 | |
| 82 | gdb_test "python finishbp_default = gdb.FinishBreakpoint ()" \ |
| 83 | "Temporary breakpoint.*" "set FinishBreakpoint with default frame value" |
| 84 | gdb_test "python finishbp = MyFinishBreakpoint (gdb.parse_and_eval ('a'), gdb.newest_frame ())" \ |
| 85 | "Temporary breakpoint.*" "set FinishBreakpoint" |
| 86 | gdb_test "python print (finishbp.return_value)" "None.*" \ |
| 87 | "check return_value at init" |
| 88 | |
| 89 | # check normal bp hit |
| 90 | |
| 91 | gdb_test "continue" "MyFinishBreakpoint stop with.*return_value is: -5.*#0.*increase.*" \ |
| 92 | "check MyFinishBreakpoint hit" |
| 93 | gdb_test "python print (finishbp.return_value)" "-5.*" "check return_value" |
| 94 | |
| 95 | gdb_test "python print (finishbp_default.hit_count)" "1.*" "check finishBP on default frame has been hit" |
| 96 | gdb_test "python print (finishbp.is_valid())" "False.*"\ |
| 97 | "ensure that finish bp is invalid afer normal hit" |
| 98 | |
| 99 | # check FinishBreakpoint in main no allowed |
| 100 | |
| 101 | gdb_test "finish" "main.*" "return to main()" |
| 102 | gdb_test "python MyFinishBreakpoint (None, gdb.selected_frame ())" \ |
| 103 | "ValueError: \"FinishBreakpoint\" not meaningful in the outermost frame..*" \ |
| 104 | "check FinishBP not allowed in main" |
| 105 | |
| 106 | # |
| 107 | # Test FinishBreakpoint with no debug symbol |
| 108 | # |
| 109 | |
| 110 | clean_restart ${testfile} |
| 111 | gdb_load_shlib ${lib_sl} |
| 112 | |
| 113 | gdb_test "source $python_file" "Python script imported.*" \ |
| 114 | "import python scripts" |
| 115 | set cond_line [gdb_get_line_number "Condition Break."] |
| 116 | |
| 117 | if ![runto_main] then { |
| 118 | fail "cannot run to main." |
| 119 | return 0 |
| 120 | } |
| 121 | |
| 122 | gdb_test "print do_nothing" "no debug info.*" "ensure that shared lib has no debug info" |
| 123 | gdb_breakpoint "do_nothing" {temporary} |
| 124 | gdb_test "continue" "Temporary breakpoint .*in \\.?do_nothing.*" \ |
| 125 | "continue to do_nothing" |
| 126 | |
| 127 | gdb_test "python finishBP = SimpleFinishBreakpoint(gdb.newest_frame())" \ |
| 128 | "SimpleFinishBreakpoint init" \ |
| 129 | "set finish breakpoint" |
| 130 | gdb_test "continue" "SimpleFinishBreakpoint stop.*" "check FinishBreakpoint hit" |
| 131 | gdb_test "python print (finishBP.return_value)" "None" "check return value without debug symbol" |
| 132 | |
| 133 | # |
| 134 | # Test FinishBreakpoint in function returned by longjmp |
| 135 | # |
| 136 | |
| 137 | clean_restart ${testfile} |
| 138 | gdb_load_shlib ${lib_sl} |
| 139 | |
| 140 | gdb_test "source $python_file" "Python script imported.*" \ |
| 141 | "import python scripts" |
| 142 | |
| 143 | if ![runto call_longjmp_1] then { |
| 144 | perror "couldn't run to breakpoint call_longjmp" |
| 145 | continue |
| 146 | } |
| 147 | |
| 148 | gdb_test "python finishbp = SimpleFinishBreakpoint(gdb.newest_frame())" \ |
| 149 | "SimpleFinishBreakpoint init" \ |
| 150 | "set finish breakpoint" |
| 151 | gdb_test "break [gdb_get_line_number "after longjmp."]" "Breakpoint.* at .*" \ |
| 152 | "set BP after the jump" |
| 153 | gdb_test "continue" "SimpleFinishBreakpoint out of scope.*" \ |
| 154 | "check FinishBP out of scope notification" |
| 155 | gdb_test "python print (finishbp.is_valid())" "False.*"\ |
| 156 | "ensure that finish bp is invalid afer out of scope notification" |
| 157 | |
| 158 | # |
| 159 | # Test FinishBreakpoint in BP condition evaluation |
| 160 | # (finish in dummy frame) |
| 161 | # |
| 162 | |
| 163 | clean_restart ${testfile} |
| 164 | gdb_load_shlib ${lib_sl} |
| 165 | |
| 166 | gdb_test "source $python_file" "Python script imported.*" \ |
| 167 | "import python scripts" |
| 168 | |
| 169 | |
| 170 | if ![runto_main] then { |
| 171 | fail "cannot run to main." |
| 172 | return 0 |
| 173 | } |
| 174 | |
| 175 | gdb_test "break ${cond_line} if test_1(i,8)" "Breakpoint .* at .*" \ |
| 176 | "set a conditional BP" |
| 177 | gdb_test "python TestBreakpoint()" "TestBreakpoint init" \ |
| 178 | "set FinishBP in a breakpoint condition" |
| 179 | gdb_test "continue" \ |
| 180 | "\"FinishBreakpoint\" cannot be set on a dummy frame.*" \ |
| 181 | "don't allow FinishBreakpoint on dummy frames" |
| 182 | gdb_test "print i" "8" "check stopped location" |
| 183 | |
| 184 | # |
| 185 | # Test FinishBreakpoint in BP condition evaluation |
| 186 | # (finish in normal frame) |
| 187 | # |
| 188 | |
| 189 | clean_restart ${testfile} |
| 190 | gdb_load_shlib ${lib_sl} |
| 191 | |
| 192 | gdb_test "source $python_file" "Python script imported.*" \ |
| 193 | "import python scripts" |
| 194 | |
| 195 | if ![runto_main] then { |
| 196 | fail "cannot run to main." |
| 197 | return 0 |
| 198 | } |
| 199 | |
| 200 | gdb_test "break ${cond_line} if test(i,8)" \ |
| 201 | "Breakpoint .* at .*" "set conditional BP" |
| 202 | gdb_test "python TestBreakpoint()" "TestBreakpoint init" "set BP in condition" |
| 203 | |
| 204 | gdb_test "continue" \ |
| 205 | "test don't stop: 1.*test don't stop: 2.*test stop.*Error in testing breakpoint condition.*The program being debugged stopped while in a function called from GDB.*" \ |
| 206 | "stop in condition function" |
| 207 | |
| 208 | gdb_test "continue" "Continuing.*" "finish condition evaluation" |
| 209 | gdb_test "continue" "Breakpoint.*" "stop at conditional breakpoint" |
| 210 | gdb_test "print i" "8" "check stopped location" |
| 211 | |
| 212 | # |
| 213 | # Test FinishBreakpoint in explicit inferior function call |
| 214 | # |
| 215 | |
| 216 | clean_restart ${testfile} |
| 217 | gdb_load_shlib ${lib_sl} |
| 218 | |
| 219 | gdb_test "source $python_file" "Python script imported.*" \ |
| 220 | "import python scripts" |
| 221 | |
| 222 | if ![runto_main] then { |
| 223 | fail "cannot run to main." |
| 224 | return 0 |
| 225 | } |
| 226 | |
| 227 | # return address in dummy frame |
| 228 | |
| 229 | gdb_test "python TestExplicitBreakpoint('increase_1')" "Breakpoint.*at.*" \ |
| 230 | "prepare TestExplicitBreakpoint" |
| 231 | gdb_test "print increase_1(&i)" \ |
| 232 | "\"FinishBreakpoint\" cannot be set on a dummy frame.*" \ |
| 233 | "don't allow FinishBreakpoint on dummy frames" |
| 234 | |
| 235 | # return address in normal frame |
| 236 | |
| 237 | delete_breakpoints |
| 238 | gdb_test "python TestExplicitBreakpoint(\"increase_1\")" "Breakpoint.*at.*" \ |
| 239 | "prepare TestExplicitBreakpoint" |
| 240 | gdb_test "print increase(&i)" \ |
| 241 | "SimpleFinishBreakpoint init.*SimpleFinishBreakpoint stop.*The program being debugged stopped while in a function called from GDB.*" \ |
| 242 | "FinishBP stop at during explicit function call" |
| 243 | |
| 244 | |
| 245 | # |
| 246 | # Test FinishBreakpoint when inferior exits |
| 247 | # |
| 248 | |
| 249 | if ![runto "test_exec_exit"] then { |
| 250 | fail "cannot run to test_exec_exit." |
| 251 | return 0 |
| 252 | } |
| 253 | |
| 254 | gdb_test_no_output "set var self_exec = 0" "switch to exit() test" |
| 255 | gdb_test "python SimpleFinishBreakpoint(gdb.newest_frame())" "SimpleFinishBreakpoint init" "set FinishBP after the exit()" |
| 256 | gdb_test "continue" "SimpleFinishBreakpoint out of scope.*" "catch out of scope after exit" |
| 257 | |
| 258 | # |
| 259 | # Test FinishBreakpoint when inferior execs |
| 260 | # |
| 261 | |
| 262 | if ![runto "test_exec_exit"] then { |
| 263 | fail "cannot run to test_exec_exit." |
| 264 | return 0 |
| 265 | } |
| 266 | |
| 267 | gdb_test "python SimpleFinishBreakpoint(gdb.newest_frame())" "SimpleFinishBreakpoint init" "set FinishBP after the exec" |
| 268 | gdb_test "catch exec" "Catchpoint.*\(exec\).*" "catch exec" |
| 269 | gdb_test "continue" "SimpleFinishBreakpoint out of scope.*" "catch out of scope after exec" |