complete.exp 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. # Copyright 2005-2022 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. load_lib "ada.exp"
  16. if { [skip_ada_tests] } { return -1 }
  17. standard_ada_testfile foo
  18. if {[gdb_compile_ada "${srcfile}" "${binfile}" executable [list debug ]] != "" } {
  19. return -1
  20. }
  21. clean_restart ${testfile}
  22. set bp_location [gdb_get_line_number "START" ${testdir}/foo.adb]
  23. runto "foo.adb:$bp_location"
  24. set eol "\[\r\n\]*"
  25. # A convenience function that verifies that the "complete EXPR" command
  26. # returns the EXPECTED_OUTPUT.
  27. proc test_gdb_complete { expr expected_output {msg ""} } {
  28. set cmd "complete p $expr"
  29. if {$msg == ""} {
  30. set msg $cmd
  31. }
  32. gdb_test "complete p $expr" \
  33. "$expected_output" $msg
  34. }
  35. # A convenience function that verifies that the "complete EXPR" command
  36. # does not generate any output.
  37. proc test_gdb_no_completion { expr } {
  38. gdb_test_no_output "complete p $expr"
  39. }
  40. # Try a global variable, only one match should be found:
  41. test_gdb_complete "my_glob" \
  42. "p my_global_variable"
  43. # A global variable, inside a nested package:
  44. test_gdb_complete "insi" \
  45. "p inside_variable"
  46. # A global variable inside a nested package, but only giving part of
  47. # the fully qualified name (top level package name missing):
  48. test_gdb_no_completion "inner.insi"
  49. # An incomplete nested package name, were lies a single symbol:
  50. test_gdb_complete "pck.inne" \
  51. "p pck.inner.inside_variable" \
  52. "complete nested package name"
  53. # A fully qualified symbol name, mangled...
  54. test_gdb_complete "pck__inner__ins" \
  55. "p pck__inner__inside_variable"
  56. # A fully qualified symbol name...
  57. test_gdb_complete "pck.inner.ins" \
  58. "p pck.inner.inside_variable"
  59. # Make sure that "inside" is not returned as a possible completion
  60. # for "side"...
  61. test_gdb_no_completion "side"
  62. # Verify that "Exported_Capitalized" is not returned as a match for
  63. # "exported", since its symbol name contains capital letters.
  64. test_gdb_no_completion "exported"
  65. # check the "<...>" notation.
  66. test_gdb_complete "<Exported" \
  67. "p <Exported_Capitalized>"
  68. # While at it, make sure we can print the symbol too, using the '<'
  69. # notation.
  70. gdb_test "p <Exported_Capitalized>" " = 2"
  71. # Confirm that we can't print the symbol without the '<' notation.
  72. gdb_test "p Exported_Capitalized" \
  73. "No definition of \"exported_capitalized\" in current context."
  74. gdb_test "p exported_capitalized" \
  75. "No definition of \"exported_capitalized\" in current context."
  76. # A global symbol, created by the binder, that starts with __gnat...
  77. test_gdb_complete "__gnat_ada_main_progra" \
  78. "p __gnat_ada_main_program_name"
  79. # A global symbol, created by the binder, that starts with __gnat,
  80. # and using the '<' notation.
  81. test_gdb_complete "<__gnat_ada_main_prog" \
  82. "p <__gnat_ada_main_program_name>"
  83. # A local variable
  84. test_gdb_complete "some" \
  85. "p some_local_variable"
  86. # A local variable variable, but in a different procedure. No match
  87. # should be returned.
  88. test_gdb_no_completion "not_in_sco"
  89. # A fully qualified variable name that doesn't exist...
  90. test_gdb_no_completion "pck.ins"
  91. # A fully qualified variable name that does exist...
  92. test_gdb_complete "pck.my" \
  93. "p pck.my_global_variable"
  94. # A fully qualified package name
  95. test_gdb_complete "pck.inne" \
  96. "p pck.inner.inside_variable" \
  97. "complete fully qualified package name"
  98. # A fully qualified package name, with a dot at the end
  99. test_gdb_complete "pck.inner." \
  100. "p pck.inner.inside_variable"
  101. # Two matches, from the global scope:
  102. test_gdb_complete "local_ident" \
  103. [multi_line "p local_identical_one" \
  104. "p local_identical_two" ]
  105. # Two matches, from the global scope, but using fully qualified names:
  106. test_gdb_complete "pck.local_ident" \
  107. [multi_line "p pck.local_identical_one" \
  108. "p pck.local_identical_two" ]
  109. # Two matches, from the global scope, but using mangled fully qualified
  110. # names:
  111. test_gdb_complete "pck__local_ident" \
  112. [multi_line "p pck__local_identical_one" \
  113. "p pck__local_identical_two" ]
  114. # Two matches, one from the global scope, the other from the local scope:
  115. test_gdb_complete "external_ident" \
  116. [multi_line "p external_identical_one" \
  117. "p external_identical_two" ]
  118. # Complete on the name of package.
  119. test_gdb_complete "pck" \
  120. [multi_line "(p pck\\.ad\[sb\])?" \
  121. "(p pck\\.ad\[sb\])?" \
  122. "p pck.ambiguous_func" \
  123. "p pck.external_identical_one" \
  124. "p pck.inner.inside_variable" \
  125. "p pck.local_identical_one" \
  126. "p pck.local_identical_two" \
  127. "p pck.my_global_variable" \
  128. "p pck.proc" ]
  129. # Complete on the name of a package followed by a dot:
  130. test_gdb_complete "pck." \
  131. [multi_line "(p pck\\.ad\[sb\])?" \
  132. "(p pck\\.ad\[sb\])?" \
  133. "p pck.ambiguous_func" \
  134. "p pck.external_identical_one" \
  135. "p pck.inner.inside_variable" \
  136. "p pck.local_identical_one" \
  137. "p pck.local_identical_two" \
  138. "p pck.my_global_variable" \
  139. "p pck.proc" ]
  140. # Complete a mangled symbol name, but using the '<...>' notation.
  141. test_gdb_complete "<pck__my" \
  142. "p <pck__my_global_variable>"
  143. # Very simple completion, but using the interactive form, this time.
  144. # The verification we are trying to make involves the event loop,
  145. # and using the "complete" command is not sufficient to reproduce
  146. # the original problem.
  147. if { [readline_is_used] } {
  148. set test "interactive complete 'print some'"
  149. send_gdb "print some\t"
  150. gdb_test_multiple "" "$test" {
  151. -re "^print some_local_variable $" {
  152. send_gdb "\n"
  153. gdb_test_multiple "" "$test" {
  154. -re " = 1$eol$gdb_prompt $" {
  155. pass "$test"
  156. }
  157. }
  158. }
  159. }
  160. }
  161. # Usually, parsing a function name that is ambiguous yields a menu through
  162. # which users can select a specific function. This should not happen during
  163. # completion, though.
  164. test_gdb_complete "ambig" \
  165. [multi_line "p ambiguous_func" \
  166. "p ambiguous_proc" ]
  167. test_gdb_complete "ambiguous_f" \
  168. "p ambiguous_func"
  169. test_gdb_complete "ambiguous_func" \
  170. "p ambiguous_func"
  171. # Perform a test intented to verify the behavior where the number
  172. # of possible completions is very large. The goal is not to verify
  173. # precisely the list returned by the complete command (this depends
  174. # on too many parameters -- targets, compiler version, runtime, etc).
  175. # However, we want to sanity-check each one of them, knowing that
  176. # each result should start with "break ada" and that the proposed
  177. # completion should look like a valid symbol name (in particular,
  178. # no uppercase letters...). See gdb/22670. File names are OK as
  179. # well, which is why "/" and "-" appear in the regexp.
  180. gdb_test_no_output "set max-completions unlimited"
  181. set test "complete break ada"
  182. gdb_test_multiple "$test" $test {
  183. -re "^$test$eol\(break ada\[\]\[a-z0-9._@/-\]*$eol\)+$gdb_prompt $" {
  184. pass $test
  185. }
  186. -re "\[A-Z\].*$gdb_prompt $" {
  187. fail "$test (gdb/22670)"
  188. }
  189. }