include/elf/
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.python / py-cmd.exp
1 # Copyright (C) 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 # This file is part of the GDB testsuite. It tests the mechanism
17 # for defining new GDB commands in Python.
18
19 if $tracelevel then {
20 strace $tracelevel
21 }
22
23 load_lib gdb-python.exp
24
25 # Start with a fresh gdb.
26
27 gdb_exit
28 gdb_start
29 gdb_reinitialize_dir $srcdir/$subdir
30
31 # Skip all tests if Python scripting is not enabled.
32 if { [skip_python_tests] } { continue }
33
34 # Test a simple command.
35
36 gdb_py_test_multiple "input simple command" \
37 "python" "" \
38 "class test_cmd (gdb.Command):" "" \
39 " def __init__ (self):" "" \
40 " super (test_cmd, self).__init__ (\"test_cmd\", gdb.COMMAND_OBSCURE)" "" \
41 " def invoke (self, arg, from_tty):" "" \
42 " print \"test_cmd output, arg = %s\" % arg" "" \
43 "test_cmd ()" "" \
44 "end" ""
45
46 gdb_test "test_cmd ugh" "test_cmd output, arg = ugh" "call simple command"
47
48 # Test a prefix command, and a subcommand within it.
49
50 gdb_py_test_multiple "input prefix command" \
51 "python" "" \
52 "class prefix_cmd (gdb.Command):" "" \
53 " def __init__ (self):" "" \
54 " super (prefix_cmd, self).__init__ (\"prefix_cmd\", gdb.COMMAND_OBSCURE, gdb.COMPLETE_NONE, True)" "" \
55 " def invoke (self, arg, from_tty):" "" \
56 " print \"prefix_cmd output, arg = %s\" % arg" "" \
57 "prefix_cmd ()" "" \
58 "end" ""
59
60 gdb_test "prefix_cmd ugh" "prefix_cmd output, arg = ugh" "call prefix command"
61
62 gdb_py_test_multiple "input subcommand" \
63 "python" "" \
64 "class subcmd (gdb.Command):" "" \
65 " def __init__ (self):" "" \
66 " super (subcmd, self).__init__ (\"prefix_cmd subcmd\", gdb.COMMAND_OBSCURE)" "" \
67 " def invoke (self, arg, from_tty):" "" \
68 " print \"subcmd output, arg = %s\" % arg" "" \
69 "subcmd ()" "" \
70 "end" ""
71
72 gdb_test "prefix_cmd subcmd ugh" "subcmd output, arg = ugh" "call subcmd"
73
74 # Test prefix command using keyword arguments.
75
76 gdb_py_test_multiple "input prefix command, keyword arguments" \
77 "python" "" \
78 "class prefix_cmd2 (gdb.Command):" "" \
79 " def __init__ (self):" "" \
80 " super (prefix_cmd2, self).__init__ (\"prefix_cmd2\", gdb.COMMAND_OBSCURE, prefix = True, completer_class = gdb.COMPLETE_FILENAME)" "" \
81 " def invoke (self, arg, from_tty):" "" \
82 " print \"prefix_cmd2 output, arg = %s\" % arg" "" \
83 "prefix_cmd2 ()" "" \
84 "end" ""
85
86 gdb_test "prefix_cmd2 argh" "prefix_cmd2 output, arg = argh" "call prefix command, keyword arguments"
87
88 gdb_py_test_multiple "input subcommand under prefix_cmd2" \
89 "python" "" \
90 "class subcmd (gdb.Command):" "" \
91 " def __init__ (self):" "" \
92 " super (subcmd, self).__init__ (\"prefix_cmd2 subcmd\", gdb.COMMAND_OBSCURE)" "" \
93 " def invoke (self, arg, from_tty):" "" \
94 " print \"subcmd output, arg = %s\" % arg" "" \
95 "subcmd ()" "" \
96 "end" ""
97
98 gdb_test "prefix_cmd2 subcmd ugh" "subcmd output, arg = ugh" "call subcmd under prefix_cmd2"
99
100 # Test a subcommand in an existing GDB prefix.
101
102 gdb_py_test_multiple "input new subcommand" \
103 "python" "" \
104 "class newsubcmd (gdb.Command):" "" \
105 " def __init__ (self):" "" \
106 " super (newsubcmd, self).__init__ (\"info newsubcmd\", gdb.COMMAND_OBSCURE)" "" \
107 " def invoke (self, arg, from_tty):" "" \
108 " print \"newsubcmd output, arg = %s\" % arg" "" \
109 "newsubcmd ()" "" \
110 "end" ""
111
112 gdb_test "info newsubcmd ugh" "newsubcmd output, arg = ugh" "call newsubcmd"
113
114 # Test a command that throws gdb.GdbError.
115
116 gdb_py_test_multiple "input command to throw error" \
117 "python" "" \
118 "class test_error_cmd (gdb.Command):" "" \
119 " def __init__ (self):" "" \
120 " super (test_error_cmd, self).__init__ (\"test_error_cmd\", gdb.COMMAND_OBSCURE)" "" \
121 " def invoke (self, arg, from_tty):" "" \
122 " raise gdb.GdbError ('you lose!')" "" \
123 "test_error_cmd ()" "" \
124 "end" ""
125
126 gdb_test "test_error_cmd ugh" "you lose!" "call error command"
127
128 # Test gdb.string_to_argv.
129
130 gdb_test "python print gdb.string_to_argv (\"1 2 3\")" \
131 {\['1', '2', '3'\]} \
132 "string_to_argv (\"1 2 3\")"
133
134 gdb_test "python print gdb.string_to_argv (\"'1 2' 3\")" \
135 {\['1 2', '3'\]} \
136 "string_to_argv (\"'1 2' 3\")"
137
138 gdb_test "python print gdb.string_to_argv ('\"1 2\" 3')" \
139 {\['1 2', '3'\]} \
140 "string_to_argv ('\"1 2\" 3')"
141
142 gdb_test "python print gdb.string_to_argv ('1\\ 2 3')" \
143 {\['1 2', '3'\]} \
144 "string_to_argv ('1\\ 2 3')"
This page took 0.051663 seconds and 4 git commands to generate.