Home | History | Annotate | Line # | Download | only in gdb.python
      1 # Copyright (C) 2016-2024 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 is used to verify that
     17 # GDB does not recurse infinitely when calling gdb.parse_and_eval() in
     18 # the course of sniffing a frame in a Python unwinder.
     19 
     20 # The unwinder has been constructed so that, should recursion occur,
     21 # it will be detected in the unwinder so that we won't need to wait
     22 # for a timeout.
     23 
     24 
     25 load_lib gdb-python.exp
     26 
     27 require allow_python_tests
     28 
     29 standard_testfile
     30 
     31 if { [prepare_for_testing "failed to prepare" ${testfile} ${srcfile}] } {
     32     return -1
     33 }
     34 
     35 set pyfile [gdb_remote_download host ${srcdir}/${subdir}/${testfile}.py]
     36 
     37 gdb_test "source ${pyfile}" "Python script imported" \
     38          "import python scripts"
     39 
     40 # The following tests require execution.
     41 
     42 if {![runto_main]} {
     43     return 0
     44 }
     45 
     46 
     47 proc cont_and_backtrace { tst } {
     48 
     49     with_test_prefix $tst {
     50 	gdb_breakpoint "ccc"
     51 
     52 	# We're testing different code paths within the unwinder's sniffer.
     53 	# Set the current path to be tested here.
     54 	gdb_test_no_output "python TestUnwinder.set_test(\"$tst\")" \
     55 			   "set code path within python unwinder to $tst"
     56 
     57 	# If the unwinder is active, the usage count will increment while
     58 	# running to the breakpoint.  Reset it prior to doing the backtrace.
     59 	gdb_test_no_output "python TestUnwinder.reset_count()" \
     60 			   "reset count"
     61 
     62 	gdb_continue_to_breakpoint "ccc"
     63 
     64 	# The python based unwinder should be called a number of times while
     65 	# generating the backtrace, but its sniffer always returns None.  So
     66 	# it doesn't really contribute to generating any of the frames below.
     67 	#
     68 	# But that's okay.  Our goal here is to make sure that GDB doesn't
     69 	# get hung up in potentially infinite recursion when invoking the
     70 	# Python-based unwinder.
     71 
     72 	gdb_test_sequence "bt"  "backtrace" {
     73 	    "\\r\\n#0 .* ccc \\(arg=789\\) at "
     74 	    "\\r\\n#1 .* bbb \\(arg=456\\) at "
     75 	    "\\r\\n#2 .* aaa \\(arg=123\\) at "
     76 	    "\\r\\n#3 .* main \\(.*\\) at"
     77 	}
     78 
     79 	# Test that the python-based unwinder / sniffer was actually called
     80 	# during generation of the backtrace.
     81 	gdb_test "python print(TestUnwinder.count > 0)" "True" \
     82 		 "python unwinder called"
     83     }
     84 }
     85 
     86 cont_and_backtrace "check_undefined_symbol"
     87 cont_and_backtrace "check_user_reg_pc"
     88 cont_and_backtrace "check_pae_pc"
     89