basicclass.exp 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. # Copyright 2003-2022 Free Software Foundation, Inc.
  2. # This program is free software; you can redistribute it and/or modify
  3. # it under the terms of the GNU General Public License as published by
  4. # the Free Software Foundation; either version 3 of the License, or
  5. # (at your option) any later version.
  6. #
  7. # This program is distributed in the hope that it will be useful,
  8. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. # GNU General Public License for more details.
  11. #
  12. # You should have received a copy of the GNU General Public License
  13. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  14. # This file was written by Adam Fedor (fedor@gnu.org)
  15. standard_testfile .m
  16. #
  17. # Objective-C program compilation isn't standard. We need to figure out
  18. # which libraries to link in. Most of the time it uses pthread
  19. #
  20. if {[gdb_compile_objc "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable [list debug ]] != "" } {
  21. return -1
  22. }
  23. #
  24. # Deduce language of main()
  25. #
  26. proc deduce_language_of_main {} {
  27. global gdb_prompt
  28. # See what language gdb thinks main() is, prior to reading full symbols.
  29. # I think this fails for COFF targets.
  30. send_gdb "show language\n"
  31. gdb_expect {
  32. -re ".* source language is \"auto; currently objective-c\".*$gdb_prompt $" {
  33. pass "deduced language is Objective-C, before full symbols"
  34. }
  35. -re ".*$gdb_prompt $" {
  36. fail "source language not correct for Objective-C (psymtabs only)"
  37. return
  38. }
  39. timeout {
  40. fail "can't show language (timeout)"
  41. return
  42. }
  43. }
  44. runto_main
  45. # See if our idea of the language has changed.
  46. send_gdb "show language\n"
  47. gdb_expect {
  48. -re ".* source language is \"auto; currently objective-c\".*$gdb_prompt $" {
  49. pass "deduced language is Objective-C, after full symbols"
  50. }
  51. -re ".*$gdb_prompt $" {
  52. fail "source language not correct for Objective-C (full symbols)"
  53. return
  54. }
  55. timeout {
  56. fail "can't show language (timeout)"
  57. return
  58. }
  59. }
  60. }
  61. proc do_objc_tests {} {
  62. global subdir
  63. global srcdir
  64. global binfile
  65. global gdb_prompt
  66. # Start with a fresh gdb.
  67. gdb_exit
  68. gdb_start
  69. gdb_reinitialize_dir $srcdir/$subdir
  70. gdb_load $binfile
  71. deduce_language_of_main
  72. }
  73. do_objc_tests
  74. #
  75. # Breakpoint tests
  76. #
  77. # Disable pending breakpoint query to avoid timeouts
  78. # if Obj-C symbols cannot be found
  79. gdb_test "set breakpoint pending off" "" "set breakpoint pending"
  80. gdb_test "break doIt" \
  81. "Breakpoint.*at.* file .*$srcfile, line.29.*" \
  82. "breakpoint method"
  83. gdb_test "break takeArg:" \
  84. "Breakpoint.*at.* file .*$srcfile, line.34.*" \
  85. "breakpoint method with colon"
  86. gdb_test "break newWithArg:" \
  87. "Breakpoint.*at.* file .*$srcfile, line.22.*" \
  88. "breakpoint class method with colon"
  89. #
  90. # Continue until breakpoint (test re-setting breakpoint)
  91. #
  92. gdb_test continue \
  93. "Continuing\\..*Breakpoint \[0-9\]+, -.BasicClass takeArg:. \\(self=.*, _cmd=.*, arg=.*\\) at .*$srcfile:34.*" \
  94. "continue until method breakpoint"
  95. #
  96. # Test resetting breakpoints when re-running program
  97. #
  98. gdb_run_cmd
  99. gdb_test "" "Breakpoint \[0-9\]+,.*main .*argc.*argv.* at .*$srcfile:.*" "resetting breakpoints when rerunning"
  100. #
  101. # Continue until breakpoint (test re-setting breakpoint)
  102. #
  103. gdb_test continue \
  104. "Continuing\\..*Breakpoint \[0-9\]+, -.BasicClass takeArg:. \\(self=.*, _cmd=.*, arg=.*\\) at .*$srcfile:34.*" \
  105. "continue until method breakpoint"
  106. #
  107. # Test printing objects
  108. #
  109. gdb_test "print object" \
  110. "\\$\[0-9\] = .*0x0" \
  111. " print an ivar of self"
  112. gdb_test "print self" \
  113. "\\$\[0-9\] = \\(.*BasicClass \\*\\) 0x\[0-9a-f\]+" \
  114. " print self"
  115. gdb_test "print \*self" \
  116. "\\$\[0-9\] = \{{?isa = 0x\[0-9a-f\]+( <.*>)?}?, object = 0x0\}" \
  117. " print contents of self"
  118. #
  119. # Break in a category
  120. #
  121. gdb_test "break hiddenMethod" \
  122. "Breakpoint.*at.* file .*$srcfile, line.61." \
  123. "breakpoint in category method"
  124. #
  125. # Continue until breakpoint (test re-setting category breakpoint)
  126. #
  127. gdb_test continue \
  128. "Continuing\\..*Breakpoint \[0-9\]+, -.BasicClass\\(Private\\) hiddenMethod. \\(self=.*, _cmd=.*\\) at .*$srcfile:61.*" \
  129. "continue until category method"
  130. #
  131. # Test calling Objective-C methods
  132. #
  133. gdb_test "print \[self printHi\]" \
  134. "Hi.*\\$\[0-9\] = \\(.*objc_object \\*\\) 0x\[0-9a-f\]+" \
  135. "call an Objective-C method with no arguments"
  136. gdb_test "print \[self printNumber: 42\]" \
  137. "42.*\\$\[0-9\] = 43" \
  138. "call an Objective-C method with one argument"
  139. #
  140. # Test printing the object description
  141. #
  142. gdb_test "print-object object" \
  143. "BasicClass gdb test object" \
  144. "use of the print-object command"
  145. gdb_test "po self" \
  146. "BasicClass gdb test object" \
  147. "use of the po (print-object) command"