loc-sec-offset.exp 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. # Copyright 2021-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 DW_AT_location attribute referencing the .debug_loc section using
  15. # the DW_FORM_sec_offset form.
  16. load_lib dwarf.exp
  17. if {![dwarf2_support]} {
  18. return 0
  19. }
  20. # Test with 32-bit and 64-bit DWARF.
  21. foreach_with_prefix is_64 {false true} {
  22. if { $is_64 } {
  23. standard_testfile .c -dw64.S
  24. set testfile ${testfile}-dw64
  25. } else {
  26. standard_testfile .c -dw32.S
  27. set testfile ${testfile}-dw32
  28. }
  29. lassign [function_range func1 $srcdir/$subdir/$srcfile] \
  30. func1_addr func1_len
  31. lassign [function_range func2 $srcdir/$subdir/$srcfile] \
  32. func2_addr func2_len
  33. set asm_file [standard_output_file $srcfile2]
  34. Dwarf::assemble $asm_file {
  35. global func1_addr func1_len
  36. global func2_addr func2_len
  37. global is_64
  38. set cu_version 4
  39. cu {
  40. version $cu_version
  41. is_64 $is_64
  42. } {
  43. declare_labels int_type1
  44. declare_labels foo_location_list
  45. DW_TAG_compile_unit {
  46. } {
  47. int_type1: DW_TAG_base_type {
  48. {DW_AT_byte_size 4 DW_FORM_data1}
  49. {DW_AT_encoding @DW_ATE_signed}
  50. {DW_AT_name "int"}
  51. }
  52. DW_TAG_variable {
  53. {DW_AT_name "foo"}
  54. {DW_AT_location $foo_location_list DW_FORM_sec_offset}
  55. {DW_AT_type :$int_type1}
  56. }
  57. DW_TAG_subprogram {
  58. {DW_AT_name "func1"}
  59. {DW_AT_low_pc $func1_addr}
  60. {DW_AT_high_pc $func1_len DW_FORM_udata}
  61. }
  62. DW_TAG_subprogram {
  63. {DW_AT_name "func2"}
  64. {DW_AT_low_pc $func2_addr}
  65. {DW_AT_high_pc $func2_len DW_FORM_udata}
  66. }
  67. }
  68. }
  69. # Generate a .debug_loc contribution.
  70. loc {
  71. cu_is_64 $is_64
  72. cu_version $cu_version
  73. } {
  74. foo_location_list:
  75. entry $func1_addr "$func1_addr + $func1_len" {
  76. DW_OP_constu 0x123456
  77. DW_OP_stack_value
  78. }
  79. entry $func2_addr "$func2_addr + $func2_len" {
  80. DW_OP_constu 0x234567
  81. DW_OP_stack_value
  82. }
  83. }
  84. }
  85. if { [prepare_for_testing "failed to prepare" ${testfile} \
  86. [list $srcfile $asm_file] {nodebug}] } {
  87. return -1
  88. }
  89. if { ![runto_main] } {
  90. return
  91. }
  92. gdb_breakpoint "func1"
  93. gdb_breakpoint "func2"
  94. gdb_continue_to_breakpoint "func1"
  95. with_test_prefix "at func1" {
  96. gdb_test "print /x foo" " = 0x123456"
  97. }
  98. gdb_continue_to_breakpoint "func2"
  99. with_test_prefix "at func2" {
  100. gdb_test "print /x foo" " = 0x234567"
  101. }
  102. }