comp-unit-lang.exp 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. # Copyright 2014-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. # Test that GDB determines the frame's language based on the comp
  15. # unit's language, even if the file has an unknown file extension,
  16. # such as ".txt".
  17. load_lib dwarf.exp
  18. # This test can only be run on targets which support DWARF-2 and use
  19. # gas.
  20. if {![dwarf2_support]} {
  21. return 0
  22. }
  23. standard_testfile .c .S
  24. # Assemble the DWARF using CU_LANG as compilation unit's language.
  25. # Run to a function in that compilation unit and check that GDB
  26. # figures out that the language is GDB_LANG.
  27. proc do_test {cu_lang gdb_lang} {
  28. global testfile srcfile srcfile2
  29. # Make some DWARF for the test.
  30. set asm_file [standard_output_file $srcfile2]
  31. Dwarf::assemble $asm_file {
  32. upvar cu_lang cu_lang
  33. # Creating a CU with 4-byte addresses lets this test link on
  34. # both 32- and 64-bit machines.
  35. cu { addr_size 4 } {
  36. compile_unit {
  37. {name file1.txt}
  38. {language @$cu_lang}
  39. {MACRO_AT_range {func}}
  40. } {
  41. subprogram {
  42. {external 1 flag}
  43. {MACRO_AT_func {func}}
  44. } {
  45. }
  46. }
  47. }
  48. }
  49. if { [prepare_for_testing "failed to prepare" ${testfile} \
  50. [list $srcfile $asm_file] {nodebug}] } {
  51. return -1
  52. }
  53. if ![runto func] {
  54. return -1
  55. }
  56. gdb_test "show language" "\"auto; currently $gdb_lang\".*"
  57. }
  58. proc do_test_with_prefix {cu_lang gdb_lang} {
  59. with_test_prefix $gdb_lang {
  60. do_test $cu_lang $gdb_lang
  61. }
  62. }
  63. # Some paths in the debugger fall back to C. Check C++ as well to
  64. # make sure the test doesn't happen to work because of such a
  65. # fallback.
  66. do_test_with_prefix DW_LANG_C "c"
  67. do_test_with_prefix DW_LANG_C_plus_plus "c\\+\\+"