1 1.1.1.2 christos # Copyright (C) 2022-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 # This file is part of the GDB testsuite. It tests a pretty printer that 17 1.1 christos # calls an inferior function by hand, triggering a Use-after-Free bug 18 1.1 christos # (PR gdb/28856). 19 1.1 christos 20 1.1 christos load_lib gdb-python.exp 21 1.1 christos 22 1.1.1.2 christos require allow_python_tests 23 1.1 christos 24 1.1.1.2 christos standard_testfile 25 1.1 christos 26 1.1 christos if { [prepare_for_testing "failed to prepare" $testfile $srcfile debug] } { 27 1.1 christos untested "failed to compile" 28 1.1 christos return -1 29 1.1 christos } 30 1.1 christos 31 1.1 christos # This proc restarts GDB, makes the inferior reach the desired spot - marked 32 1.1 christos # by a comment in the .c file - and turns on the pretty printer for testing. 33 1.1 christos # Starting with a new GDB is important because the test may crash GDB. The 34 1.1 christos # return values are here to avoid us trying to test the pretty printer if 35 1.1 christos # there was a problem getting to main. 36 1.1 christos proc start_test { breakpoint_comment } { 37 1.1 christos global srcdir subdir testfile binfile 38 1.1 christos 39 1.1 christos # Start with a fresh gdb. 40 1.1 christos # This is important because the test can crash GDB. 41 1.1 christos 42 1.1 christos clean_restart ${binfile} 43 1.1 christos 44 1.1 christos if {![runto_main]} { 45 1.1 christos untested "couldn't run to breakpoint" 46 1.1 christos return -1 47 1.1 christos } 48 1.1 christos 49 1.1 christos # Let GDB get to the return line. 50 1.1 christos gdb_breakpoint [gdb_get_line_number ${breakpoint_comment} ${testfile}.c ] 51 1.1 christos gdb_continue_to_breakpoint ${breakpoint_comment} ".*" 52 1.1 christos 53 1.1 christos set remote_python_file [gdb_remote_download host ${srcdir}/${subdir}/${testfile}.py] 54 1.1 christos gdb_test_no_output "source ${remote_python_file}" "load python file" 55 1.1 christos 56 1.1 christos return 0 57 1.1 christos } 58 1.1 christos 59 1.1 christos # Start by testing the "run" command, it can't leverage start_test 60 1.1 christos with_test_prefix "run to frame" { 61 1.1 christos if {![runto_main]} { 62 1.1 christos untested "couldn't run to main" 63 1.1 christos } 64 1.1 christos 65 1.1 christos set remote_python_file [gdb_remote_download host ${srcdir}/${subdir}/${testfile}.py] 66 1.1 christos gdb_test_no_output "source ${remote_python_file}" "load python file" 67 1.1 christos 68 1.1 christos gdb_breakpoint [gdb_get_line_number "TAG: final frame" ${testfile}.c] 69 1.1 christos gdb_continue_to_breakpoint "TAG: final frame" ".*" 70 1.1 christos } 71 1.1 christos 72 1.1 christos # Testing the backtrace command. 73 1.1 christos with_test_prefix "frame print" { 74 1.1 christos if { [start_test "TAG: final frame"] == 0 } { 75 1.1 christos gdb_test "backtrace -frame-arguments all" [multi_line \ 76 1.1 christos "#0 .*g \\(mt=mytype is .*\\, depth=0\\).*"\ 77 1.1 christos "#1 .*g \\(mt=mytype is .*\\, depth=1\\).*"\ 78 1.1 christos "#2 .*g \\(mt=mytype is .*\\, depth=2\\).*"\ 79 1.1 christos "#3 .*g \\(mt=mytype is .*\\, depth=3\\).*"\ 80 1.1 christos "#4 .*g \\(mt=mytype is .*\\, depth=4\\).*"\ 81 1.1 christos "#5 .*g \\(mt=mytype is .*\\, depth=5\\).*"\ 82 1.1 christos "#6 .*g \\(mt=mytype is .*\\, depth=6\\).*"\ 83 1.1 christos "#7 .*g \\(mt=mytype is .*\\, depth=7\\).*"\ 84 1.1 christos "#8 .*g \\(mt=mytype is .*\\, depth=8\\).*"\ 85 1.1 christos "#9 .*g \\(mt=mytype is .*\\, depth=9\\).*"\ 86 1.1 christos "#10 .*g \\(mt=mytype is .*\\, depth=10\\).*"\ 87 1.1 christos "#11 .*main \\(\\).*"] \ 88 1.1 christos "backtrace test" 89 1.1 christos } 90 1.1 christos } 91 1.1 christos 92 1.1 christos # Test the "info frame" command 93 1.1 christos with_test_prefix "info frame" { 94 1.1 christos if { [start_test "TAG: first frame"] == 0 } { 95 1.1 christos gdb_test "info frame" "mytype is $hex \"hello world\".*" 96 1.1 christos } 97 1.1 christos } 98 1.1 christos 99 1.1 christos # Testing the down command. 100 1.1 christos with_test_prefix "frame movement down" { 101 1.1 christos if { [start_test "TAG: first frame"] == 0 } { 102 1.1 christos gdb_test "up" [multi_line "#1 .*in main \\(\\) at .*" ".*outside the frame.*"] 103 1.1 christos gdb_test "down" [multi_line "#0\\s+g \\(mt=mytype is .*\\, depth=10\\).*" ".*first frame.*"] 104 1.1 christos } 105 1.1 christos } 106 1.1 christos 107 1.1 christos # Testing the up command. 108 1.1 christos with_test_prefix "frame movement up" { 109 1.1 christos if { [start_test "TAG: final frame"] == 0 } { 110 1.1 christos gdb_test "up" [multi_line "#1 .*in g \\(mt=mytype is .*\\, depth=1\\).*" ".*first frame.*"] 111 1.1 christos } 112 1.1 christos } 113 1.1 christos 114 1.1 christos # Testing the finish command. 115 1.1 christos with_test_prefix "frame exit through finish" { 116 1.1 christos if { [start_test "TAG: final frame"] == 0 } { 117 1.1 christos gdb_test "finish" [multi_line ".*.*g \\(mt=mytype is .*\\, depth=0\\).*" ".*g \\(mt=mytype is .*\\, depth=1\\).*" ".*"] 118 1.1 christos } 119 1.1 christos } 120 1.1 christos 121 1.1 christos # Testing the step command. 122 1.1 christos with_test_prefix "frame enter through step" { 123 1.1 christos if { [start_test "TAG: outside the frame"] == 0 } { 124 1.1 christos gdb_test "step" [multi_line "g \\(mt=mytype is .*\\, depth=10\\).*" "41.*if \\(depth \\<= 0\\)"] 125 1.1 christos } 126 1.1 christos } 127 1.1 christos 128 1.1 christos # Testing the continue command. 129 1.1 christos with_test_prefix "frame enter through continue" { 130 1.1 christos if { [start_test "TAG: outside the frame"] == 0 } { 131 1.1 christos gdb_breakpoint [gdb_get_line_number "TAG: first frame" ${testfile}.c ] 132 1.1 christos gdb_continue_to_breakpoint "TAG: first frame" ".*TAG: first frame.*" 133 1.1 christos } 134 1.1 christos } 135