]>
Commit | Line | Data |
---|---|---|
b811d2c2 | 1 | # Copyright 2003-2020 Free Software Foundation, Inc. |
130cacce AF |
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 | |
e22f8b7c | 5 | # the Free Software Foundation; either version 3 of the License, or |
130cacce | 6 | # (at your option) any later version. |
e22f8b7c | 7 | # |
130cacce AF |
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. | |
e22f8b7c | 12 | # |
130cacce | 13 | # You should have received a copy of the GNU General Public License |
e22f8b7c | 14 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
130cacce AF |
15 | |
16 | # This file was written by Adam Fedor (fedor@gnu.org) | |
17 | ||
2c44deac | 18 | standard_testfile .m |
130cacce AF |
19 | |
20 | # | |
21 | # Objective-C program compilation isn't standard. We need to figure out | |
22 | # which libraries to link in. Most of the time it uses pthread | |
23 | # | |
24 | if {[gdb_compile_objc "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable [list debug ]] != "" } { | |
6e25beaf | 25 | return -1 |
130cacce AF |
26 | } |
27 | ||
28 | # | |
29 | # Deduce language of main() | |
30 | # | |
31 | ||
32 | proc deduce_language_of_main {} { | |
33 | global gdb_prompt | |
34 | ||
35 | # See what language gdb thinks main() is, prior to reading full symbols. | |
36 | # I think this fails for COFF targets. | |
37 | send_gdb "show language\n" | |
38 | gdb_expect { | |
39 | -re ".* source language is \"auto; currently objective-c\".*$gdb_prompt $" { | |
40 | pass "deduced language is Objective-C, before full symbols" | |
41 | } | |
42 | -re ".*$gdb_prompt $" { | |
43 | fail "source language not correct for Objective-C (psymtabs only)" | |
44 | return | |
45 | } | |
46 | timeout { | |
47 | fail "can't show language (timeout)" | |
48 | return | |
49 | } | |
50 | } | |
51 | ||
52 | runto_main | |
53 | ||
54 | # See if our idea of the language has changed. | |
55 | ||
56 | send_gdb "show language\n" | |
57 | gdb_expect { | |
58 | -re ".* source language is \"auto; currently objective-c\".*$gdb_prompt $" { | |
59 | pass "deduced language is Objective-C, after full symbols" | |
60 | } | |
61 | -re ".*$gdb_prompt $" { | |
62 | fail "source language not correct for Objective-C (full symbols)" | |
63 | return | |
64 | } | |
65 | timeout { | |
66 | fail "can't show language (timeout)" | |
67 | return | |
68 | } | |
69 | } | |
70 | } | |
71 | ||
72 | proc do_objc_tests {} { | |
130cacce | 73 | global subdir |
130cacce AF |
74 | global srcdir |
75 | global binfile | |
76 | global gdb_prompt | |
77 | ||
130cacce AF |
78 | |
79 | # Start with a fresh gdb. | |
80 | ||
81 | gdb_exit | |
82 | gdb_start | |
83 | gdb_reinitialize_dir $srcdir/$subdir | |
84 | gdb_load $binfile | |
85 | ||
86 | deduce_language_of_main | |
87 | } | |
88 | ||
89 | do_objc_tests | |
90 | ||
91 | # | |
92 | # Breakpoint tests | |
93 | # | |
0f73703c UW |
94 | |
95 | # Disable pending breakpoint query to avoid timeouts | |
96 | # if Obj-C symbols cannot be found | |
97 | gdb_test "set breakpoint pending off" "" "set breakpoint pending" | |
98 | ||
130cacce AF |
99 | gdb_test "break doIt" \ |
100 | "Breakpoint.*at.* file .*$srcfile, line.29.*" \ | |
101 | "breakpoint method" | |
102 | ||
103 | gdb_test "break takeArg:" \ | |
104 | "Breakpoint.*at.* file .*$srcfile, line.34.*" \ | |
105 | "breakpoint method with colon" | |
106 | ||
107 | gdb_test "break newWithArg:" \ | |
108 | "Breakpoint.*at.* file .*$srcfile, line.22.*" \ | |
109 | "breakpoint class method with colon" | |
110 | ||
111 | # | |
112 | # Continue until breakpoint (test re-setting breakpoint) | |
113 | # | |
114 | gdb_test continue \ | |
115 | "Continuing\\..*Breakpoint \[0-9\]+, -.BasicClass takeArg:. \\(self=.*, _cmd=.*, arg=.*\\) at .*$srcfile:34.*" \ | |
116 | "continue until method breakpoint" | |
117 | ||
118 | # | |
119 | # Test resetting breakpoints when re-running program | |
120 | # | |
83f66e8f | 121 | gdb_run_cmd |
da738167 | 122 | gdb_test "" "Breakpoint \[0-9\]+,.*main .*argc.*argv.* at .*$srcfile:.*" "resetting breakpoints when rerunning" |
130cacce AF |
123 | |
124 | # | |
125 | # Continue until breakpoint (test re-setting breakpoint) | |
126 | # | |
127 | gdb_test continue \ | |
128 | "Continuing\\..*Breakpoint \[0-9\]+, -.BasicClass takeArg:. \\(self=.*, _cmd=.*, arg=.*\\) at .*$srcfile:34.*" \ | |
129 | "continue until method breakpoint" | |
130 | ||
131 | # | |
132 | # Test printing objects | |
133 | # | |
134 | gdb_test "print object" \ | |
135 | "\\$\[0-9\] = .*0x0" \ | |
136 | " print an ivar of self" | |
137 | ||
138 | gdb_test "print self" \ | |
139 | "\\$\[0-9\] = \\(.*BasicClass \\*\\) 0x\[0-9a-f\]+" \ | |
140 | " print self" | |
141 | ||
142 | gdb_test "print \*self" \ | |
9cb709b6 | 143 | "\\$\[0-9\] = \{{?isa = 0x\[0-9a-f\]+( <.*>)?}?, object = 0x0\}" \ |
130cacce AF |
144 | " print contents of self" |
145 | ||
146 | # | |
147 | # Break in a category | |
148 | # | |
149 | gdb_test "break hiddenMethod" \ | |
150 | "Breakpoint.*at.* file .*$srcfile, line.61." \ | |
151 | "breakpoint in category method" | |
152 | ||
153 | ||
154 | # | |
155 | # Continue until breakpoint (test re-setting category breakpoint) | |
156 | # | |
157 | gdb_test continue \ | |
158 | "Continuing\\..*Breakpoint \[0-9\]+, -.BasicClass\\(Private\\) hiddenMethod. \\(self=.*, _cmd=.*\\) at .*$srcfile:61.*" \ | |
159 | "continue until category method" | |
160 | ||
161 | # | |
162 | # Test calling Objective-C methods | |
163 | # | |
164 | gdb_test "print \[self printHi\]" \ | |
62f4b920 | 165 | "Hi.*\\$\[0-9\] = \\(.*objc_object \\*\\) 0x\[0-9a-f\]+" \ |
bb95117e | 166 | "call an Objective-C method with no arguments" |
130cacce AF |
167 | |
168 | gdb_test "print \[self printNumber: 42\]" \ | |
169 | "42.*\\$\[0-9\] = 43" \ | |
bb95117e | 170 | "call an Objective-C method with one argument" |
130cacce AF |
171 | |
172 | # | |
173 | # Test printing the object description | |
174 | # | |
175 | gdb_test "print-object object" \ | |
176 | "BasicClass gdb test object" \ | |
bb95117e | 177 | "use of the print-object command" |
130cacce AF |
178 | |
179 | gdb_test "po self" \ | |
180 | "BasicClass gdb test object" \ | |
bb95117e | 181 | "use of the po (print-object) command" |
130cacce AF |
182 | |
183 |