Automatic Copyright Year update after running gdb/copyright.py
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.base / trace-commands.exp
CommitLineData
88b9d363 1# Copyright 2006-2022 Free Software Foundation, Inc.
8625200f
AS
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
e22f8b7c 5# the Free Software Foundation; either version 3 of the License, or
8625200f
AS
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
e22f8b7c 14# along with this program. If not, see <http://www.gnu.org/licenses/>.
8625200f
AS
15
16# Test that the source command's verbose mode works, the 'set trace-commands'
17# command works, and that the nest depth is correct in various circumstances.
18
8625200f
AS
19gdb_exit
20gdb_start
21
22# Create a file to source
08b3fe69
TT
23set tracecommandsscript [standard_output_file tracecommandsscript]
24set fd [open "$tracecommandsscript" w]
8625200f
AS
25puts $fd "\
26echo in tracecommandsscript\\n
27define func
28 echo in func \$arg0\\n
29end
30if 1
31 if 2
32 if 3
33 if 4
34 echo deep\\n
35 func 999
36 end
37 end
38 end
39end
40"
41close $fd
42
43# Make sure that the show trace-commands exists and the default is 'off'.
44gdb_test "show trace-commands" "State of GDB CLI command tracing is off\\." \
45 "show trace-commands says off"
46
47# Source the script with verbose mode.
08b3fe69 48gdb_test_sequence "source -v $tracecommandsscript" "source -v" {
8625200f
AS
49 {[\r\n]\+echo in tracecommandsscript\\n}
50 {[\r\n]\+define func}
51 {[\r\n]\+if 1}
52 {[\r\n]\+\+if 2}
53 {[\r\n]\+\+\+if 3}
54 {[\r\n]\+\+\+\+if 4}
55 {[\r\n]\+\+\+\+\+echo deep\\n}
56 {[\r\n]\+\+\+\+\+func 999}
57 {[\r\n]\+\+\+\+\+\+echo in func 999\\n}
58}
59
60# Turn on command tracing.
27d3a1a2 61gdb_test_no_output "set trace-commands" "set trace-commands"
8625200f
AS
62
63# Make sure show trace-commands now gives 'on'.
64gdb_test "show trace-commands" \
65 {\+show trace-commands[\r\n]+State of GDB CLI command tracing is on\.} \
66 "show trace-commands says on"
67
68# Simple test
69gdb_test "echo hi\\n" {\+echo hi\\n[\r\n]+hi} "simple trace-commands test"
70
71# Nested test
5fa290c1
DE
72gdb_test_sequence "if 1\nset \$i = 0\nwhile \$i < 5\nfunc \$i\nset \$i += 1\nend\nend" \
73 "nested trace-commands test" {
8625200f
AS
74 {[\r\n]\+if 1}
75 {[\r\n]\+\+set \$i = 0}
76 {[\r\n]\+\+while \$i < 5}
77 {[\r\n]\+\+\+func \$i}
78 {[\r\n]\+\+\+\+echo in func \$i\\n}
79 {[\r\n]\+\+\+set \$i \+= 1}
80 {[\r\n]\+\+\+func \$i}
81 {[\r\n]\+\+\+\+echo in func \$i\\n}
82 {[\r\n]\+\+\+set \$i \+= 1}
83 {[\r\n]\+\+\+func \$i}
84 {[\r\n]\+\+\+\+echo in func \$i\\n}
85 {[\r\n]\+\+\+set \$i \+= 1}
86 {[\r\n]\+\+\+func \$i}
87 {[\r\n]\+\+\+\+echo in func \$i\\n}
88 {[\r\n]\+\+\+set \$i \+= 1}
89 {[\r\n]\+\+\+func \$i}
90 {[\r\n]\+\+\+\+echo in func \$i\\n}
91 {[\r\n]\+\+\+set \$i \+= 1}
92}
93
94# Function with source works
08b3fe69 95gdb_test_sequence "define topfunc\nsource $tracecommandsscript\nend" \
5fa290c1 96 "define user command" {
8625200f
AS
97 {[\r\n]\+define topfunc}
98}
5fa290c1 99gdb_test_sequence "topfunc" "nested trace-commands test with source" {
8625200f 100 {[\r\n]\+topfunc}
08b3fe69 101 {[\r\n]\+\+source .*/tracecommandsscript}
8625200f
AS
102 {[\r\n]\+\+echo in tracecommandsscript\\n}
103 {[\r\n]\+\+define func}
104 {[\r\n]\+\+if 1}
105 {[\r\n]\+\+\+if 2}
106 {[\r\n]\+\+\+\+if 3}
107 {[\r\n]\+\+\+\+\+if 4}
108 {[\r\n]\+\+\+\+\+\+echo deep\\n}
109 {[\r\n]\+\+\+\+\+\+func 999}
110 {[\r\n]\+\+\+\+\+\+\+echo in func 999\\n}
111}
112
113# Test nest depth resets properly on error
5fa290c1
DE
114gdb_test_sequence "if 1\nif 2\nload\necho should not get here\\n\nend\nend" \
115 "depth resets on error part 1" {
8625200f
AS
116 {[\r\n]\+if 1}
117 {[\r\n]\+\+if 2}
118 {[\r\n]\+\+\+load}
119 {[\r\n]No executable file specified\.}
120 {[\r\n]Use the "file" or "exec-file" command\.}
121}
122gdb_test "echo hi\\n" {[\r\n]\+echo hi\\n[\r\n]+hi} \
123 "depth resets on error part 2"
This page took 1.735122 seconds and 4 git commands to generate.