]>
Commit | Line | Data |
---|---|---|
1d506c26 | 1 | # Copyright 2021-2024 Free Software Foundation, Inc. |
f493b711 KB |
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 | # Test that commands in a GDB script file run via GDB's -x flag work | |
17 | # as expected. Specifically, the script creates a dprintf breakpoint | |
18 | # as well as a normal breakpoint that has "continue" in its command | |
19 | # list, and then does "run". Correct output from GDB is checked as | |
20 | # part of this test. | |
21 | ||
22 | # Bail out if the target can't use the 'run' command. | |
ec1300f6 | 23 | require target_can_use_run_cmd |
f493b711 KB |
24 | |
25 | standard_testfile | |
26 | ||
27 | if {[build_executable "failed to prepare" $testfile $srcfile debug]} { | |
28 | return -1 | |
29 | } | |
30 | ||
31 | # This is the name of the GDB script to load. | |
32 | set x_file ${srcdir}/${subdir}/$testfile.gdb | |
33 | ||
34 | # Create context in which the global, GDBFLAGS, will be restored at | |
35 | # the end of the block. All commands run within the block are | |
36 | # actually run in the outer context. (This is why 'res' is available | |
37 | # outside of the save_vars block.) | |
38 | save_vars { GDBFLAGS } { | |
39 | # Set flags with which to start GDB. | |
40 | append GDBFLAGS " -ex \"set height unlimited\"" | |
41 | append GDBFLAGS " -x \"$x_file\"" | |
42 | append GDBFLAGS " --args \"$binfile\"" | |
43 | ||
44 | # Start GDB with above flags. | |
45 | set res [gdb_spawn] | |
46 | } | |
47 | ||
48 | set test "load and run script with -x" | |
49 | if { $res != 0} { | |
50 | fail $test | |
51 | return -1 | |
52 | } | |
53 | ||
54 | # The script loaded via -x contains a run command; while running, GDB | |
55 | # is expected to print three messages from dprintf breakpoints along | |
56 | # with three interspersed messages from an ordinary breakpoint (which | |
57 | # was set up with a continue command). Set up pattern D to match | |
58 | # output from hitting the dprintf breakpoint and B for the ordinary | |
59 | # breakpoint. Then set PAT to contain the entire pattern of expected | |
60 | # output from the interspersed dprintf and ordinary breakpoints along | |
61 | # with some (additional) expected output from the dprintf breakpoints, | |
62 | # i.e. 0, 1, and 2. | |
63 | set d "dprintf in increment.., vi=" | |
64 | set b "Breakpoint ., inc_vi" | |
65 | set pat "${d}0.*?$b.*?${d}1.*?$b.*?${d}2.*?$b.*?" | |
66 | ||
67 | proc do_test {cmd test} { | |
76183fd1 KB |
68 | gdb_test_multiple $cmd $test { |
69 | -re "$::pat$::inferior_exited_re normally.*$::gdb_prompt $" { | |
70 | pass $test | |
71 | } | |
72 | -re "Don't know how to run.*$::gdb_prompt $" { | |
73 | # Even though we bailed out at the beginning of this test case | |
74 | # for targets which can't use the "run" command, there are | |
75 | # still targets, e.g. native-extended-gdbserver, which can | |
76 | # run, but will still print the "Don't know how to run" | |
77 | # message. In the case of native-extended-gdbserver, it would | |
78 | # first need to connect to the target in order to run. For | |
79 | # that particular target, the very first test which attempts | |
80 | # to use the "run" command from a command line script is | |
81 | # the one that is unsupported. The other two tests will | |
82 | # pass because, after reaching the (gdb) prompt, a gdbserver | |
83 | # is spawned and then connected to. (The command line which | |
84 | # spawns GDB for this target has a "-iex set | |
85 | # auto-connect-native-target off" which prevents it from | |
86 | # attempting to "run" using the native target.) | |
87 | unsupported $test | |
88 | } | |
89 | } | |
f493b711 KB |
90 | } |
91 | ||
92 | # Check output from running script with -x | |
93 | do_test "" $test | |
94 | ||
95 | # Restart GDB and 'source' the script; this will (still) run the program | |
96 | # due to the 'run' command in the script. | |
97 | clean_restart $binfile | |
98 | do_test "source $x_file" "load and run script using source command" | |
99 | ||
100 | # This should leave us at the gdb prompt; Run program again using | |
101 | # already established breakpoints, i.e. those loaded from the | |
102 | # script. Prior to fixing PR 28308, this was the only test that | |
103 | # would pass. | |
104 | do_test "run" "run again" |