1# Copyright 2003-2024 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 was written by Adam Fedor (fedor@gnu.org) 17 18standard_testfile .m 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# 24if {[gdb_compile_objc "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable [list debug ]] != "" } { 25 return -1 26} 27 28# 29# Deduce language of main() 30# 31 32proc 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 72proc do_objc_tests {} { 73 global binfile 74 75 clean_restart $binfile 76 77 deduce_language_of_main 78} 79 80do_objc_tests 81 82# 83# Breakpoint tests 84# 85 86# Disable pending breakpoint query to avoid timeouts 87# if Obj-C symbols cannot be found 88gdb_test "set breakpoint pending off" "" "set breakpoint pending" 89 90gdb_test "break doIt" \ 91 "Breakpoint.*at.* file .*$srcfile, line.29.*" \ 92 "breakpoint method" 93 94gdb_test "break takeArg:" \ 95 "Breakpoint.*at.* file .*$srcfile, line.34.*" \ 96 "breakpoint method with colon" 97 98gdb_test "break newWithArg:" \ 99 "Breakpoint.*at.* file .*$srcfile, line.22.*" \ 100 "breakpoint class method with colon" 101 102# 103# Continue until breakpoint (test re-setting breakpoint) 104# 105gdb_test continue \ 106 "Continuing\\..*Breakpoint \[0-9\]+, -.BasicClass takeArg:. \\(self=.*, _cmd=.*, arg=.*\\) at .*$srcfile:34.*" \ 107 "continue until method breakpoint" 108 109# 110# Test resetting breakpoints when re-running program 111# 112gdb_run_cmd 113gdb_test "" "Breakpoint \[0-9\]+,.*main .*argc.*argv.* at .*$srcfile:.*" "resetting breakpoints when rerunning" 114 115# 116# Continue until breakpoint (test re-setting breakpoint) 117# 118gdb_test continue \ 119 "Continuing\\..*Breakpoint \[0-9\]+, -.BasicClass takeArg:. \\(self=.*, _cmd=.*, arg=.*\\) at .*$srcfile:34.*" \ 120 "continue until method breakpoint" 121 122# 123# Test printing objects 124# 125gdb_test "print object" \ 126 "\\$\[0-9\] = .*0x0" \ 127 " print an ivar of self" 128 129gdb_test "print self" \ 130 "\\$\[0-9\] = \\(.*BasicClass \\*\\) 0x\[0-9a-f\]+" \ 131 " print self" 132 133gdb_test "print \*self" \ 134 "\\$\[0-9\] = \{{?isa = 0x\[0-9a-f\]+( <.*>)?}?, object = 0x0\}" \ 135 " print contents of self" 136 137# 138# Break in a category 139# 140gdb_test "break hiddenMethod" \ 141 "Breakpoint.*at.* file .*$srcfile, line.61." \ 142 "breakpoint in category method" 143 144 145# 146# Continue until breakpoint (test re-setting category breakpoint) 147# 148gdb_test continue \ 149 "Continuing\\..*Breakpoint \[0-9\]+, -.BasicClass\\(Private\\) hiddenMethod. \\(self=.*, _cmd=.*\\) at .*$srcfile:61.*" \ 150 "continue until category method" 151 152# 153# Test calling Objective-C methods 154# 155gdb_test "print \[self printHi\]" \ 156 "Hi.*\\$\[0-9\] = \\(.*objc_object \\*\\) 0x\[0-9a-f\]+" \ 157 "call an Objective-C method with no arguments" 158 159gdb_test "print \[self printNumber: 42\]" \ 160 "42.*\\$\[0-9\] = 43" \ 161 "call an Objective-C method with one argument" 162 163# 164# Test printing the object description 165# 166gdb_test "print-object object" \ 167 "BasicClass gdb test object" \ 168 "use of the print-object command" 169 170gdb_test "po self" \ 171 "BasicClass gdb test object" \ 172 "use of the po (print-object) command" 173 174 175