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