1# Copyright 2006, 2007, 2008, 2009, 2010, 2011 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# 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
19if $tracelevel then {
20    strace $tracelevel
21}
22
23gdb_exit
24gdb_start
25
26# Create a file to source
27set fd [open "tracecommandsscript" w]
28puts $fd "\
29echo in tracecommandsscript\\n
30define func
31 echo in func \$arg0\\n
32end
33if 1
34 if 2
35  if 3
36   if 4
37    echo deep\\n
38    func 999
39   end
40  end
41 end
42end
43"
44close $fd
45
46# Make sure that the show trace-commands exists and the default is 'off'.
47gdb_test "show trace-commands" "State of GDB CLI command tracing is off\\." \
48	 "show trace-commands says off"
49
50# Source the script with verbose mode.
51gdb_test_sequence "source -v tracecommandsscript" "source -v" {
52  {[\r\n]\+echo in tracecommandsscript\\n}
53  {[\r\n]\+define func}
54  {[\r\n]\+if 1}
55  {[\r\n]\+\+if 2}
56  {[\r\n]\+\+\+if 3}
57  {[\r\n]\+\+\+\+if 4}
58  {[\r\n]\+\+\+\+\+echo deep\\n}
59  {[\r\n]\+\+\+\+\+func 999}
60  {[\r\n]\+\+\+\+\+\+echo in func 999\\n}
61}
62
63# Turn on command tracing.
64gdb_test_no_output "set trace-commands" "set trace-commands"
65
66# Make sure show trace-commands now gives 'on'.
67gdb_test "show trace-commands" \
68    {\+show trace-commands[\r\n]+State of GDB CLI command tracing is on\.} \
69	 "show trace-commands says on"
70
71# Simple test
72gdb_test "echo hi\\n" {\+echo hi\\n[\r\n]+hi} "simple trace-commands test"
73
74# Nested test
75gdb_test_sequence "if 1\nset \$i = 0\nwhile \$i < 5\nfunc \$i\nset \$i += 1\nend\nend" \
76    "nested trace-commands test" {
77  {[\r\n]\+if 1}
78  {[\r\n]\+\+set \$i = 0}
79  {[\r\n]\+\+while \$i < 5}
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  {[\r\n]\+\+\+func \$i}
93  {[\r\n]\+\+\+\+echo in func \$i\\n}
94  {[\r\n]\+\+\+set \$i \+= 1}
95}
96
97# Function with source works
98gdb_test_sequence "define topfunc\nsource tracecommandsscript\nend" \
99    "define user command" {
100  {[\r\n]\+define topfunc}
101}
102gdb_test_sequence "topfunc" "nested trace-commands test with source" {
103  {[\r\n]\+topfunc}
104  {[\r\n]\+\+source tracecommandsscript}
105  {[\r\n]\+\+echo in tracecommandsscript\\n}
106  {[\r\n]\+\+define func}
107  {[\r\n]\+\+if 1}
108  {[\r\n]\+\+\+if 2}
109  {[\r\n]\+\+\+\+if 3}
110  {[\r\n]\+\+\+\+\+if 4}
111  {[\r\n]\+\+\+\+\+\+echo deep\\n}
112  {[\r\n]\+\+\+\+\+\+func 999}
113  {[\r\n]\+\+\+\+\+\+\+echo in func 999\\n}
114}
115
116# Test nest depth resets properly on error
117gdb_test_sequence "if 1\nif 2\nload\necho should not get here\\n\nend\nend" \
118    "depth resets on error part 1" {
119  {[\r\n]\+if 1}
120  {[\r\n]\+\+if 2}
121  {[\r\n]\+\+\+load}
122  {[\r\n]No executable file specified\.}
123  {[\r\n]Use the "file" or "exec-file" command\.}
124}
125gdb_test "echo hi\\n" {[\r\n]\+echo hi\\n[\r\n]+hi} \
126	 "depth resets on error part 2"
127