info_auto_lang.exp 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. # Copyright 2018-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. # This test verifies that the commands
  18. # info [functions|variables|types]
  19. # respect the 'set language auto|ada|c' setting, whatever the language
  20. # of the current frame.
  21. # Similarly, checks that rbreak reports its results respecting
  22. # the language mode.
  23. standard_ada_testfile proc_in_ada
  24. set cfile "some_c"
  25. # gnat normalizes proc_in_ada source file when compiling.
  26. # As the 'info' commands results are sorted by absolute path names, also normalize
  27. # the some_c source file to ensure that the 'info' results are always
  28. # giving Ada results first.
  29. set csrcfile [file normalize ${srcdir}/${subdir}/${testdir}/${cfile}.c]
  30. set cobject [standard_output_file ${cfile}.o]
  31. if { [gdb_compile "${csrcfile}" "${cobject}" object [list debug]] != "" } {
  32. untested "failed to compile"
  33. return -1
  34. }
  35. if {[gdb_compile_ada "${srcfile}" "${binfile}" executable [list debug]] != "" } {
  36. untested "failed to compile"
  37. return -1
  38. }
  39. clean_restart ${testfile}
  40. set bp_location [gdb_get_line_number "STOP" ${testdir}/some_c.c]
  41. if ![runto "some_c.c:$bp_location"] then {
  42. return
  43. }
  44. set func_in_c(c_syntax) "${decimal}: void proc_in_c\\\(void\\\);"
  45. set func_in_c(ada_syntax) "${decimal}: procedure proc_in_c;"
  46. set func_in_ada(c_syntax) "${decimal}: void proc_in_ada\\\(void\\\);"
  47. set func_in_ada(ada_syntax) "${decimal}: procedure proc_in_ada;"
  48. set type_in_c(c_syntax) "${decimal}: typedef struct {\\.\\.\\.} some_type_in_c;"
  49. set type_in_c(ada_syntax) [multi_line \
  50. "${decimal}: record" \
  51. " some_component_in_c: int;" \
  52. "end record" ]
  53. set type_in_ada(c_syntax) "${decimal}: struct global_pack__some_type_in_ada;"
  54. set type_in_ada(ada_syntax) "${decimal}: global_pack.some_type_in_ada;"
  55. set var_in_c(c_syntax) "${decimal}: some_type_in_c some_struct_in_c;"
  56. set var_in_c(ada_syntax) "${decimal}: some_struct_in_c: some_type_in_c;"
  57. set var_in_ada(c_syntax) "${decimal}: struct global_pack__some_type_in_ada global_pack.some_struct_in_ada;"
  58. set var_in_ada(ada_syntax) "${decimal}: global_pack.some_struct_in_ada: global_pack.some_type_in_ada;"
  59. set rbreak_func_in_c(c_syntax) "void proc_in_c\\\(void\\\);"
  60. set rbreak_func_in_c(ada_syntax) "procedure proc_in_c;"
  61. set rbreak_func_in_ada(c_syntax) "void proc_in_ada\\\(void\\\);"
  62. set rbreak_func_in_ada(ada_syntax) "procedure proc_in_ada;"
  63. foreach_with_prefix language_choice { "auto" "ada" "c" } {
  64. # Check that switching to the desired language_choice when the selected
  65. # frame has the same language (or the desired language is auto) gives no
  66. # warning. Also set the expected matches for the various commands
  67. # tested afterwards.
  68. if {$language_choice == "auto"} {
  69. gdb_test "frame 0" "#0 .*" "select frame with lang c"
  70. set c_match c_syntax
  71. set ada_match ada_syntax
  72. } elseif {$language_choice == "ada"} {
  73. gdb_test "frame 1" "#1 .*" "select frame with lang ada"
  74. set c_match ada_syntax
  75. set ada_match ada_syntax
  76. } elseif {$language_choice == "c"} {
  77. gdb_test "frame 0" "#0 .*" "select frame with lang c"
  78. set c_match c_syntax
  79. set ada_match c_syntax
  80. } else {
  81. error "unexpected language choice"
  82. }
  83. gdb_test_no_output "set language $language_choice" "set language language_choice"
  84. foreach frame {
  85. "0"
  86. "1" } {
  87. if { $frame == 0 } {
  88. set frame_lang "c"
  89. } else {
  90. set frame_lang "ada"
  91. }
  92. with_test_prefix "frame=$frame, frame_lang=$frame_lang" {
  93. gdb_test "frame $frame" "#$frame .*" "select frame"
  94. gdb_test "info functions proc_in_" \
  95. [multi_line \
  96. "All functions matching regular expression \"proc_in_\":" \
  97. "" \
  98. "File .*proc_in_ada.adb:" \
  99. $func_in_ada($ada_match) \
  100. "" \
  101. "File .*some_c.c:" \
  102. $func_in_c($c_match)
  103. ]
  104. gdb_test "info types some_type" \
  105. [multi_line \
  106. "All types matching regular expression \"some_type\":" \
  107. "" \
  108. "File .*global_pack.ads:" \
  109. $type_in_ada($ada_match)\
  110. "" \
  111. "File .*some_c.c:" \
  112. $type_in_c($c_match)
  113. ]
  114. gdb_test "info variables some_struct" \
  115. [multi_line \
  116. "All variables matching regular expression \"some_struct\":" \
  117. "" \
  118. "File .*global_pack.ads:" \
  119. $var_in_ada($ada_match) \
  120. "" \
  121. "File .*some_c.c:" \
  122. $var_in_c($c_match)
  123. ]
  124. gdb_test "rbreak proc_in_" \
  125. [multi_line \
  126. "Breakpoint.*file .*proc_in_ada.adb,.*" \
  127. $rbreak_func_in_ada($ada_match) \
  128. "Breakpoint.*file .*some_c.c,.*" \
  129. $rbreak_func_in_c($c_match)
  130. ]
  131. delete_breakpoints
  132. }
  133. }
  134. }