Home | History | Annotate | Line # | Download | only in gdb.base
      1  1.1.1.7  christos # Copyright (C) 2015-2024 Free Software Foundation, Inc.
      2      1.1  christos 
      3      1.1  christos # This program is free software; you can redistribute it and/or modify
      4      1.1  christos # it under the terms of the GNU General Public License as published by
      5      1.1  christos # the Free Software Foundation; either version 3 of the License, or
      6      1.1  christos # (at your option) any later version.
      7      1.1  christos #
      8      1.1  christos # This program is distributed in the hope that it will be useful,
      9      1.1  christos # but WITHOUT ANY WARRANTY; without even the implied warranty of
     10      1.1  christos # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     11      1.1  christos # GNU General Public License for more details.
     12      1.1  christos #
     13      1.1  christos # You should have received a copy of the GNU General Public License
     14      1.1  christos # along with this program.  If not, see <http://www.gnu.org/licenses/>.
     15      1.1  christos 
     16      1.1  christos # Test that GDB can step past a breakpoint even if GDB doesn't have
     17      1.1  christos # symbols for the main binary.  PR gdb/13858.
     18      1.1  christos 
     19      1.1  christos standard_testfile start.c
     20      1.1  christos 
     21      1.1  christos if { [build_executable "failed to build" ${testfile} $srcfile] } {
     22      1.1  christos     return -1
     23      1.1  christos }
     24      1.1  christos 
     25      1.1  christos # Get the current PC.  MSG is used as test message.
     26      1.1  christos 
     27      1.1  christos proc get_pc { msg } {
     28      1.1  christos     global hex gdb_prompt
     29      1.1  christos 
     30      1.1  christos     set addr ""
     31      1.1  christos     gdb_test_multiple "p /x \$pc" "$msg" {
     32      1.1  christos 	-re " = ($hex).*$gdb_prompt $" {
     33      1.1  christos 	    set addr $expect_out(1,string)
     34      1.1  christos 	    pass "$msg"
     35      1.1  christos 	}
     36      1.1  christos     }
     37      1.1  christos 
     38      1.1  christos     return $addr
     39      1.1  christos }
     40      1.1  christos 
     41      1.1  christos # Test stepping past a breakpoint with no symbols.  DISPLACED is one
     42      1.1  christos # of the "set displaced-stepping" options.  If GDB can't find where to
     43      1.1  christos # put the scratch pad, GDB should be able to fall back to stepping
     44      1.1  christos # past the breakpoint using an in-line step-over.
     45      1.1  christos 
     46      1.1  christos proc test_step_over { displaced } {
     47      1.1  christos     global hex
     48      1.1  christos     global binfile
     49      1.1  christos 
     50      1.1  christos     clean_restart $binfile
     51      1.1  christos 
     52      1.1  christos     if ![runto_main] {
     53      1.1  christos 	return -1
     54      1.1  christos     }
     55      1.1  christos 
     56      1.1  christos     delete_breakpoints
     57      1.1  christos 
     58      1.1  christos     set msg "purging symbols"
     59      1.1  christos     gdb_test_multiple "file" "$msg" {
     60      1.1  christos 	-re "Are you sure you want to change the file.*y or n. $" {
     61      1.1  christos 	    send_gdb "y\n"
     62      1.1  christos 	    exp_continue
     63      1.1  christos 	}
     64      1.1  christos 	-re "Discard symbol table.*y or n. $" {
     65      1.1  christos 	    gdb_test "y" "No symbol file now." "$msg"
     66      1.1  christos 	}
     67      1.1  christos     }
     68      1.1  christos 
     69      1.1  christos     set before_addr [get_pc "get before PC"]
     70      1.1  christos 
     71      1.1  christos     gdb_test "break *\$pc" "Breakpoint .* at $hex"
     72      1.1  christos 
     73      1.1  christos     gdb_test_no_output "set displaced-stepping $displaced"
     74      1.1  christos 
     75      1.1  christos     gdb_test "stepi" "$hex in \?\? .*"
     76      1.1  christos 
     77      1.1  christos     set after_addr [get_pc "get after PC"]
     78      1.1  christos 
     79  1.1.1.7  christos     gdb_assert {[regexp "^${hex}$" $before_addr] \
     80  1.1.1.7  christos 		    && [regexp "^${hex}$" $after_addr] \
     81  1.1.1.7  christos 		    && $before_addr != $after_addr} "advanced"
     82      1.1  christos }
     83      1.1  christos 
     84      1.1  christos foreach displaced { "off" "on" "auto" } {
     85      1.1  christos     if { $displaced != "off" && ![support_displaced_stepping] } {
     86      1.1  christos 	continue
     87      1.1  christos     }
     88      1.1  christos 
     89      1.1  christos     with_test_prefix "displaced=$displaced" {
     90      1.1  christos 	test_step_over $displaced
     91      1.1  christos     }
     92      1.1  christos }
     93