[gdb/syscalls] Sync with strace v6.13
[binutils-gdb.git] / gdb / testsuite / gdb.base / trace-commands.exp
blob1cabb20aa269d4d97e5ffb044c4cf2bb63da4b5e
1 # Copyright 2006-2024 Free Software Foundation, Inc.
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.
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.
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/>.
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.
19 gdb_exit
20 gdb_start
22 # Create a file to source
23 set tracecommandsscript [standard_output_file tracecommandsscript]
24 set fd [open "$tracecommandsscript" w]
25 puts $fd "\
26 echo in tracecommandsscript\\n
27 define func
28  echo in func \$arg0\\n
29 end
30 if 1
31  if 2
32   if 3
33    if 4
34     echo deep\\n
35     func 999
36    end
37   end
38  end
39 end
41 close $fd
43 # Make sure that the show trace-commands exists and the default is 'off'.
44 gdb_test "show trace-commands" "State of GDB CLI command tracing is off\\." \
45          "show trace-commands says off"
47 # Source the script with verbose mode.
48 gdb_test_sequence "source -v $tracecommandsscript" "source -v" {
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}
60 # Turn on command tracing.
61 gdb_test_no_output "set trace-commands" "set trace-commands"
63 # Make sure show trace-commands now gives 'on'.
64 gdb_test "show trace-commands" \
65     {\+show trace-commands[\r\n]+State of GDB CLI command tracing is on\.} \
66          "show trace-commands says on"
68 # Simple test
69 gdb_test "echo hi\\n" {\+echo hi\\n[\r\n]+hi} "simple trace-commands test"
71 # Nested test
72 set strings {
73     {+if 1}
74     {++set $i = 0}
75     {++while $i < 5}
76     {+++func $i}
77     {++++echo in func $i\n}
78     {+++set $i += 1}
79     {+++func $i}
80     {++++echo in func $i\n}
81     {+++set $i += 1}
82     {+++func $i}
83     {++++echo in func $i\n}
84     {+++set $i += 1}
85     {+++func $i}
86     {++++echo in func $i\n}
87     {+++set $i += 1}
88     {+++func $i}
89     {++++echo in func $i\n}
90     {+++set $i += 1}
92 set re {}
93 foreach string $strings {
94     lappend re [string_to_regexp $string]
96 set re [join $re "\r\n(.*\r\n)?"]
97 set cmd "if 1\nset \$i = 0\nwhile \$i < 5\nfunc \$i\nset \$i += 1\nend\nend"
98 gdb_test $cmd $re "nested trace-commands test"
100 # Function with source works
101 gdb_test_sequence "define topfunc\nsource $tracecommandsscript\nend" \
102     "define user command" {
103   {[\r\n]\+define topfunc}
105 gdb_test_sequence "topfunc" "nested trace-commands test with source" {
106   {[\r\n]\+topfunc}
107   {[\r\n]\+\+source .*/tracecommandsscript}
108   {[\r\n]\+\+echo in tracecommandsscript\\n}
109   {[\r\n]\+\+define func}
110   {[\r\n]\+\+if 1}
111   {[\r\n]\+\+\+if 2}
112   {[\r\n]\+\+\+\+if 3}
113   {[\r\n]\+\+\+\+\+if 4}
114   {[\r\n]\+\+\+\+\+\+echo deep\\n}
115   {[\r\n]\+\+\+\+\+\+func 999}
116   {[\r\n]\+\+\+\+\+\+\+echo in func 999\\n}
119 # Test nest depth resets properly on error
120 set cmd "if 1\nif 2\nload\necho should not get here\\n\nend\nend"
121 set strings {
122   {+if 1}
123   {++if 2}
124   {+++load}
125   {No executable file specified.}
126   {Use the "file" or "exec-file" command.}
128 set re {}
129 foreach string $strings {
130     lappend re [string_to_regexp $string]
132 set re [join $re "\r\n(.*\r\n)?"]
133 gdb_test $cmd $re "depth resets on error part 1"
135 gdb_test "echo hi\\n" {[\r\n]\+echo hi\\n[\r\n]+hi} \
136          "depth resets on error part 2"