template-specification-full-name.exp 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. # Copyright 2020-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 to reproduce the crash described in PR 26693. The following DWARF was
  15. # crashing GDB while loading partial symbols: a DW_TAG_subprogram with a
  16. # DW_AT_specification (pointing to another subprogram), without a DW_AT_name
  17. # and with a template parameter (DW_TAG_template_type_parameter). More
  18. # precisely, the crash was happening when trying to compute the full name of the
  19. # subprogram.
  20. load_lib dwarf.exp
  21. if {![dwarf2_support]} {
  22. return 0
  23. }
  24. standard_testfile main.c .S
  25. lassign [function_range main ${srcdir}/${subdir}/${srcfile}] \
  26. main_start main_length
  27. set asm_file [standard_output_file $srcfile2]
  28. Dwarf::assemble $asm_file {
  29. global main_start main_length
  30. cu { label cu_start } {
  31. DW_TAG_compile_unit {
  32. {DW_AT_language @DW_LANG_C_plus_plus}
  33. } {
  34. declare_labels templated_subprogram int
  35. int: DW_TAG_base_type {
  36. {DW_AT_name "int"}
  37. {DW_AT_byte_size 4 DW_FORM_data1}
  38. {DW_AT_encoding @DW_ATE_signed}
  39. }
  40. # The templated subprogram.
  41. templated_subprogram: DW_TAG_subprogram {
  42. {DW_AT_name "apply"}
  43. }
  44. # The template specialization.
  45. #
  46. # The low and high PC are phony: we just need an address range that
  47. # is valid in the program, so we use the main function's range.
  48. DW_TAG_subprogram {
  49. {DW_AT_specification :$templated_subprogram}
  50. {MACRO_AT_range main}
  51. } {
  52. DW_TAG_template_type_param {
  53. {DW_AT_name "T"}
  54. {DW_AT_type :$int DW_FORM_ref4}
  55. }
  56. }
  57. }
  58. }
  59. aranges {} cu_start {
  60. arange {} "$main_start" "$main_length"
  61. }
  62. }
  63. if { [prepare_for_testing "failed to prepare" ${testfile} \
  64. [list $srcfile $asm_file] {nodebug}] } {
  65. return -1
  66. }
  67. if ![runto_main] {
  68. return -1
  69. }
  70. # Just a sanity check to make sure GDB slurped the symbols correctly.
  71. gdb_test "print apply<int>" " = {void \\(void\\)} $hex <apply<int>\\(\\)>"