dw2-ranges-base.exp 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. # Copyright 2015-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. load_lib dwarf.exp
  15. # Test DW_TAG_compile_unit with no children and with neither DW_AT_low_pc nor
  16. # DW_AT_high_pc but with DW_AT_ranges instead.
  17. # This test can only be run on targets which support DWARF-2 and use gas.
  18. if {![dwarf2_support]} {
  19. verbose "Skipping $gdb_test_file_name."
  20. return 0
  21. }
  22. # The .c files use __attribute__.
  23. if [get_compiler_info] {
  24. return -1
  25. }
  26. if !$gcc_compiled {
  27. verbose "Skipping $gdb_test_file_name."
  28. return 0
  29. }
  30. standard_testfile .c -dw.S
  31. set asm_file [standard_output_file $srcfile2]
  32. Dwarf::assemble $asm_file {
  33. global srcdir subdir srcfile srcfile2
  34. declare_labels ranges_label
  35. declare_labels L
  36. # Find start address and length for our functions.
  37. set main_func \
  38. [function_range main [list ${srcdir}/${subdir}/$srcfile]]
  39. set frame2_func \
  40. [function_range frame2 [list ${srcdir}/${subdir}/$srcfile]]
  41. set frame3_func \
  42. [function_range frame3 [list ${srcdir}/${subdir}/$srcfile]]
  43. # Very simple info for this test program. We don't care about
  44. # this information being correct (w.r.t. funtion / argument types)
  45. # just so long as the compilation using makes use of the
  46. # .debug_ranges data then the test achieves its objective.
  47. cu { label cu_label } {
  48. compile_unit {
  49. {language @DW_LANG_C}
  50. {name dw-ranges-base.c}
  51. {stmt_list $L DW_FORM_sec_offset}
  52. {ranges ${ranges_label} DW_FORM_sec_offset}
  53. } {
  54. subprogram {
  55. {external 1 flag}
  56. {name main}
  57. }
  58. subprogram {
  59. {external 1 flag}
  60. {name frame2}
  61. }
  62. subprogram {
  63. {external 1 flag}
  64. {name frame3}
  65. }
  66. }
  67. }
  68. lines {version 2} L {
  69. include_dir "${srcdir}/${subdir}"
  70. file_name "$srcfile" 1
  71. # Generate simple line table program. The line table
  72. # information contained here is not correct, and we really
  73. # don't care, just so long as each function has some line
  74. # table data associated with it. We do make use of the fake
  75. # line numbers that we pick here in the tests below.
  76. program {
  77. DW_LNE_set_address [lindex $main_func 0]
  78. DW_LNS_advance_line 10
  79. DW_LNS_copy
  80. DW_LNS_advance_pc [lindex $main_func 1]
  81. DW_LNS_advance_line 19
  82. DW_LNS_copy
  83. DW_LNE_end_sequence
  84. DW_LNE_set_address [lindex $frame2_func 0]
  85. DW_LNS_advance_line 20
  86. DW_LNS_copy
  87. DW_LNS_advance_pc [lindex $frame2_func 1]
  88. DW_LNS_advance_line 29
  89. DW_LNS_copy
  90. DW_LNE_end_sequence
  91. DW_LNE_set_address [lindex $frame3_func 0]
  92. DW_LNS_advance_line 30
  93. DW_LNS_copy
  94. DW_LNS_advance_pc [lindex $frame3_func 1]
  95. DW_LNS_advance_line 39
  96. DW_LNS_copy
  97. DW_LNE_end_sequence
  98. }
  99. }
  100. # Generate ranges data. This is the point of this whole test
  101. # file, we must have multiple bases specified, so we use a new
  102. # base for each function.
  103. ranges {is_64 [is_64_target]} {
  104. ranges_label: sequence {
  105. base [lindex $main_func 0]
  106. range 0 [lindex $main_func 1]
  107. base [lindex $frame2_func 0]
  108. range 0 [lindex $frame2_func 1]
  109. base [lindex $frame3_func 0]
  110. range 0 [lindex $frame3_func 1]
  111. }
  112. }
  113. aranges {} cu_label {
  114. arange {} [lindex $main_func 0] [lindex $main_func 1]
  115. arange {} [lindex $frame2_func 0] [lindex $frame2_func 1]
  116. arange {} [lindex $frame3_func 0] [lindex $frame3_func 1]
  117. }
  118. }
  119. if { [prepare_for_testing "failed to prepare" ${testfile} \
  120. [list $srcfile $asm_file] {nodebug}] } {
  121. return -1
  122. }
  123. if ![runto_main] {
  124. return -1
  125. }
  126. # Make use of the line numbers we faked in the .debug_line table above.
  127. gdb_test "info line main" \
  128. "Line 11 of .* starts at address .* and ends at .*"
  129. gdb_test "info line frame2" \
  130. "Line 21 of .* starts at address .* and ends at .*"
  131. gdb_test "info line frame3" \
  132. "Line 31 of .* starts at address .* and ends at .*"
  133. # Ensure that the line table correctly tracks the end of sequence markers.
  134. set end_seq_count 0
  135. set prev -1
  136. set seq_count 0
  137. gdb_test_multiple "maint info line-table gdb.dwarf2/dw2-ranges-base.c" \
  138. "count END markers in line table" {
  139. -re "^$decimal\[ \t\]+$decimal\[ \t\]+$hex\(\[ \t\]+Y\)? *\r\n" {
  140. if { $prev != -1 } {
  141. gdb_assert "$prev == 1" \
  142. "prev of normal entry at $seq_count is end marker"
  143. }
  144. set prev 0
  145. incr seq_count
  146. exp_continue
  147. }
  148. -re "^$decimal\[ \t\]+END\[ \t\]+$hex\(\[ \t\]+Y\)? *\r\n" {
  149. if { $prev != -1 } {
  150. gdb_assert "$prev == 0" \
  151. "prev of end marker at $seq_count is normal entry"
  152. }
  153. set prev 1
  154. incr seq_count
  155. incr end_seq_count
  156. exp_continue
  157. }
  158. -re "^\r\n" {
  159. # Empty lines between tables.
  160. exp_continue
  161. }
  162. -re "^$gdb_prompt $" {
  163. gdb_assert [expr $end_seq_count == 3] $gdb_test_name
  164. }
  165. -re ".*linetable: \\(\\(struct linetable \\*\\) 0x0\\):\r\nNo line table.\r\n" {
  166. exp_continue
  167. }
  168. -re ".*linetable: \\(\\(struct linetable \\*\\) $hex\\):\r\nINDEX\[ \t\]+LINE\[ \t\]+ADDRESS\[ \t\]+IS-STMT\[ \t\]PROLOGUE-END *\r\n" {
  169. exp_continue
  170. }
  171. }