1 |
227 |
jeremybenn |
# Copyright (C) 2009, 2010 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 .
|
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 |
|
|
# Usage: gdb_py_test_multiple NAME INPUT RESULT {INPUT RESULT}...
|
24 |
|
|
# Run a test named NAME, consisting of multiple lines of input.
|
25 |
|
|
# After each input line INPUT, search for result line RESULT.
|
26 |
|
|
# Succeed if all results are seen; fail otherwise.
|
27 |
|
|
proc gdb_py_test_multiple {name args} {
|
28 |
|
|
global gdb_prompt
|
29 |
|
|
foreach {input result} $args {
|
30 |
|
|
if {[gdb_test_multiple $input "$name - $input" {
|
31 |
|
|
-re "\[\r\n\]*($result)\[\r\n\]+($gdb_prompt | *>)$" {
|
32 |
|
|
pass "$name - $input"
|
33 |
|
|
}
|
34 |
|
|
}]} {
|
35 |
|
|
return 1
|
36 |
|
|
}
|
37 |
|
|
}
|
38 |
|
|
return 0
|
39 |
|
|
}
|
40 |
|
|
|
41 |
|
|
# Start with a fresh gdb.
|
42 |
|
|
|
43 |
|
|
gdb_exit
|
44 |
|
|
gdb_start
|
45 |
|
|
gdb_reinitialize_dir $srcdir/$subdir
|
46 |
|
|
|
47 |
|
|
gdb_test_multiple "python print 'hello, world!'" "verify python support" {
|
48 |
|
|
-re "not supported.*$gdb_prompt $" {
|
49 |
|
|
unsupported "python support is disabled"
|
50 |
|
|
return -1
|
51 |
|
|
}
|
52 |
|
|
-re "$gdb_prompt $" {}
|
53 |
|
|
}
|
54 |
|
|
|
55 |
|
|
# Test a simple command.
|
56 |
|
|
|
57 |
|
|
gdb_py_test_multiple "input simple command" \
|
58 |
|
|
"python" "" \
|
59 |
|
|
"class test_cmd (gdb.Command):" "" \
|
60 |
|
|
" def __init__ (self):" "" \
|
61 |
|
|
" super (test_cmd, self).__init__ (\"test_cmd\", gdb.COMMAND_OBSCURE)" "" \
|
62 |
|
|
" def invoke (self, arg, from_tty):" "" \
|
63 |
|
|
" print \"test_cmd output, arg = %s\" % arg" "" \
|
64 |
|
|
"test_cmd ()" "" \
|
65 |
|
|
"end" ""
|
66 |
|
|
|
67 |
|
|
gdb_test "test_cmd ugh" "test_cmd output, arg = ugh" "call simple command"
|
68 |
|
|
|
69 |
|
|
# Test a prefix command, and a subcommand within it.
|
70 |
|
|
|
71 |
|
|
gdb_py_test_multiple "input prefix command" \
|
72 |
|
|
"python" "" \
|
73 |
|
|
"class prefix_cmd (gdb.Command):" "" \
|
74 |
|
|
" def __init__ (self):" "" \
|
75 |
|
|
" super (prefix_cmd, self).__init__ (\"prefix_cmd\", gdb.COMMAND_OBSCURE, gdb.COMPLETE_NONE, True)" "" \
|
76 |
|
|
" def invoke (self, arg, from_tty):" "" \
|
77 |
|
|
" print \"prefix_cmd output, arg = %s\" % arg" "" \
|
78 |
|
|
"prefix_cmd ()" "" \
|
79 |
|
|
"end" ""
|
80 |
|
|
|
81 |
|
|
gdb_test "prefix_cmd ugh" "prefix_cmd output, arg = ugh" "call prefix command"
|
82 |
|
|
|
83 |
|
|
gdb_py_test_multiple "input subcommand" \
|
84 |
|
|
"python" "" \
|
85 |
|
|
"class subcmd (gdb.Command):" "" \
|
86 |
|
|
" def __init__ (self):" "" \
|
87 |
|
|
" super (subcmd, self).__init__ (\"prefix_cmd subcmd\", gdb.COMMAND_OBSCURE)" "" \
|
88 |
|
|
" def invoke (self, arg, from_tty):" "" \
|
89 |
|
|
" print \"subcmd output, arg = %s\" % arg" "" \
|
90 |
|
|
"subcmd ()" "" \
|
91 |
|
|
"end" ""
|
92 |
|
|
|
93 |
|
|
gdb_test "prefix_cmd subcmd ugh" "subcmd output, arg = ugh" "call subcmd"
|
94 |
|
|
|
95 |
|
|
# Test prefix command using keyword arguments.
|
96 |
|
|
|
97 |
|
|
gdb_py_test_multiple "input prefix command, keyword arguments" \
|
98 |
|
|
"python" "" \
|
99 |
|
|
"class prefix_cmd2 (gdb.Command):" "" \
|
100 |
|
|
" def __init__ (self):" "" \
|
101 |
|
|
" super (prefix_cmd2, self).__init__ (\"prefix_cmd2\", gdb.COMMAND_OBSCURE, prefix = True, completer_class = gdb.COMPLETE_FILENAME)" "" \
|
102 |
|
|
" def invoke (self, arg, from_tty):" "" \
|
103 |
|
|
" print \"prefix_cmd2 output, arg = %s\" % arg" "" \
|
104 |
|
|
"prefix_cmd2 ()" "" \
|
105 |
|
|
"end" ""
|
106 |
|
|
|
107 |
|
|
gdb_test "prefix_cmd2 argh" "prefix_cmd2 output, arg = argh" "call prefix command, keyword arguments"
|
108 |
|
|
|
109 |
|
|
gdb_py_test_multiple "input subcommand under prefix_cmd2" \
|
110 |
|
|
"python" "" \
|
111 |
|
|
"class subcmd (gdb.Command):" "" \
|
112 |
|
|
" def __init__ (self):" "" \
|
113 |
|
|
" super (subcmd, self).__init__ (\"prefix_cmd2 subcmd\", gdb.COMMAND_OBSCURE)" "" \
|
114 |
|
|
" def invoke (self, arg, from_tty):" "" \
|
115 |
|
|
" print \"subcmd output, arg = %s\" % arg" "" \
|
116 |
|
|
"subcmd ()" "" \
|
117 |
|
|
"end" ""
|
118 |
|
|
|
119 |
|
|
gdb_test "prefix_cmd2 subcmd ugh" "subcmd output, arg = ugh" "call subcmd under prefix_cmd2"
|
120 |
|
|
|
121 |
|
|
# Test a subcommand in an existing GDB prefix.
|
122 |
|
|
|
123 |
|
|
gdb_py_test_multiple "input new subcommand" \
|
124 |
|
|
"python" "" \
|
125 |
|
|
"class newsubcmd (gdb.Command):" "" \
|
126 |
|
|
" def __init__ (self):" "" \
|
127 |
|
|
" super (newsubcmd, self).__init__ (\"info newsubcmd\", gdb.COMMAND_OBSCURE)" "" \
|
128 |
|
|
" def invoke (self, arg, from_tty):" "" \
|
129 |
|
|
" print \"newsubcmd output, arg = %s\" % arg" "" \
|
130 |
|
|
"newsubcmd ()" "" \
|
131 |
|
|
"end" ""
|
132 |
|
|
|
133 |
|
|
gdb_test "info newsubcmd ugh" "newsubcmd output, arg = ugh" "call newsubcmd"
|