Commit | Line | Data |
---|---|---|
130cacce AF |
1 | # Copyright 2003 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 2 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, write to the Free Software | |
15 | # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | |
16 | ||
17 | # This file was written by Adam Fedor (fedor@gnu.org) | |
18 | ||
19 | if $tracelevel then { | |
20 | strace $tracelevel | |
21 | } | |
22 | ||
23 | set testfile "basicclass" | |
24 | set srcfile ${testfile}.m | |
25 | set binfile ${objdir}/${subdir}/${testfile} | |
26 | ||
27 | # | |
28 | # Objective-C program compilation isn't standard. We need to figure out | |
29 | # which libraries to link in. Most of the time it uses pthread | |
30 | # | |
31 | if {[gdb_compile_objc "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable [list debug ]] != "" } { | |
6e25beaf | 32 | return -1 |
130cacce AF |
33 | } |
34 | ||
35 | # | |
36 | # Deduce language of main() | |
37 | # | |
38 | ||
39 | proc deduce_language_of_main {} { | |
40 | global gdb_prompt | |
41 | ||
42 | # See what language gdb thinks main() is, prior to reading full symbols. | |
43 | # I think this fails for COFF targets. | |
44 | send_gdb "show language\n" | |
45 | gdb_expect { | |
46 | -re ".* source language is \"auto; currently objective-c\".*$gdb_prompt $" { | |
47 | pass "deduced language is Objective-C, before full symbols" | |
48 | } | |
49 | -re ".*$gdb_prompt $" { | |
50 | fail "source language not correct for Objective-C (psymtabs only)" | |
51 | return | |
52 | } | |
53 | timeout { | |
54 | fail "can't show language (timeout)" | |
55 | return | |
56 | } | |
57 | } | |
58 | ||
59 | runto_main | |
60 | ||
61 | # See if our idea of the language has changed. | |
62 | ||
63 | send_gdb "show language\n" | |
64 | gdb_expect { | |
65 | -re ".* source language is \"auto; currently objective-c\".*$gdb_prompt $" { | |
66 | pass "deduced language is Objective-C, after full symbols" | |
67 | } | |
68 | -re ".*$gdb_prompt $" { | |
69 | fail "source language not correct for Objective-C (full symbols)" | |
70 | return | |
71 | } | |
72 | timeout { | |
73 | fail "can't show language (timeout)" | |
74 | return | |
75 | } | |
76 | } | |
77 | } | |
78 | ||
79 | proc do_objc_tests {} { | |
80 | global prms_id | |
81 | global bug_id | |
82 | global subdir | |
83 | global objdir | |
84 | global srcdir | |
85 | global binfile | |
86 | global gdb_prompt | |
87 | ||
88 | set prms_id 0 | |
89 | set bug_id 0 | |
90 | ||
91 | # Start with a fresh gdb. | |
92 | ||
93 | gdb_exit | |
94 | gdb_start | |
95 | gdb_reinitialize_dir $srcdir/$subdir | |
96 | gdb_load $binfile | |
97 | ||
98 | deduce_language_of_main | |
99 | } | |
100 | ||
101 | do_objc_tests | |
102 | ||
103 | # | |
104 | # Breakpoint tests | |
105 | # | |
106 | gdb_test "break doIt" \ | |
107 | "Breakpoint.*at.* file .*$srcfile, line.29.*" \ | |
108 | "breakpoint method" | |
109 | ||
110 | gdb_test "break takeArg:" \ | |
111 | "Breakpoint.*at.* file .*$srcfile, line.34.*" \ | |
112 | "breakpoint method with colon" | |
113 | ||
114 | gdb_test "break newWithArg:" \ | |
115 | "Breakpoint.*at.* file .*$srcfile, line.22.*" \ | |
116 | "breakpoint class method with colon" | |
117 | ||
118 | # | |
119 | # Continue until breakpoint (test re-setting breakpoint) | |
120 | # | |
121 | gdb_test continue \ | |
122 | "Continuing\\..*Breakpoint \[0-9\]+, -.BasicClass takeArg:. \\(self=.*, _cmd=.*, arg=.*\\) at .*$srcfile:34.*" \ | |
123 | "continue until method breakpoint" | |
124 | ||
125 | # | |
126 | # Test resetting breakpoints when re-running program | |
127 | # | |
128 | send_gdb "run\n" | |
129 | gdb_expect { | |
130 | -re "The program .* has been started already.*y or n. $" { | |
131 | send_gdb "y\n" | |
132 | exp_continue | |
133 | } | |
134 | -re "Starting program.*Breakpoint \[0-9\]+,.*main .*argc.*argv.* at .*$srcfile:.*$gdb_prompt $"\ | |
135 | { pass "resetting breakpoints when rerunning" } | |
136 | -re ".*$gdb_prompt $" { fail "resetting breakpoints when rerunning" } | |
137 | timeout { fail "resetting breakpoints when rerunning" } | |
138 | } | |
139 | ||
140 | # | |
141 | # Continue until breakpoint (test re-setting breakpoint) | |
142 | # | |
143 | gdb_test continue \ | |
144 | "Continuing\\..*Breakpoint \[0-9\]+, -.BasicClass takeArg:. \\(self=.*, _cmd=.*, arg=.*\\) at .*$srcfile:34.*" \ | |
145 | "continue until method breakpoint" | |
146 | ||
147 | # | |
148 | # Test printing objects | |
149 | # | |
150 | gdb_test "print object" \ | |
151 | "\\$\[0-9\] = .*0x0" \ | |
152 | " print an ivar of self" | |
153 | ||
154 | gdb_test "print self" \ | |
155 | "\\$\[0-9\] = \\(.*BasicClass \\*\\) 0x\[0-9a-f\]+" \ | |
156 | " print self" | |
157 | ||
158 | gdb_test "print \*self" \ | |
159 | "\\$\[0-9\] = \{isa = 0x\[0-9a-f\]+, object = 0x0\}" \ | |
160 | " print contents of self" | |
161 | ||
162 | # | |
163 | # Break in a category | |
164 | # | |
165 | gdb_test "break hiddenMethod" \ | |
166 | "Breakpoint.*at.* file .*$srcfile, line.61." \ | |
167 | "breakpoint in category method" | |
168 | ||
169 | ||
170 | # | |
171 | # Continue until breakpoint (test re-setting category breakpoint) | |
172 | # | |
173 | gdb_test continue \ | |
174 | "Continuing\\..*Breakpoint \[0-9\]+, -.BasicClass\\(Private\\) hiddenMethod. \\(self=.*, _cmd=.*\\) at .*$srcfile:61.*" \ | |
175 | "continue until category method" | |
176 | ||
177 | # | |
178 | # Test calling Objective-C methods | |
179 | # | |
180 | gdb_test "print \[self printHi\]" \ | |
83876b3b | 181 | "Hi.*\\$\[0-9\] = -?\[0-9\]+" \ |
130cacce AF |
182 | "Call an Objective-C method with no arguments" |
183 | ||
184 | gdb_test "print \[self printNumber: 42\]" \ | |
185 | "42.*\\$\[0-9\] = 43" \ | |
186 | "Call an Objective-C method with one argument" | |
187 | ||
188 | # | |
189 | # Test printing the object description | |
190 | # | |
191 | gdb_test "print-object object" \ | |
192 | "BasicClass gdb test object" \ | |
193 | "Use of the print-object command" | |
194 | ||
195 | gdb_test "po self" \ | |
196 | "BasicClass gdb test object" \ | |
197 | "Use of the po (print-object) command" | |
198 | ||
199 |