dw2-inline-header-1.exp 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  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. # Setup a line table where:
  15. #
  16. # | | | | | Inline | Inline |
  17. # | Addr | File | Line | Stmt | Rng A | Rng B |
  18. # |------|------|------|------|--------|--------|
  19. # | 1 | 1 | 16 | Y | | |
  20. # | 2 | 1 | 17 | Y | | |
  21. # | 3 | 2 | 21 | Y | X | |
  22. # | 4 | 2 | 22 | Y | X | |
  23. # | 4 | 1 | 18 | N | X | |
  24. # | 5 | 2 | 23 | N | X | X |
  25. # | 6 | 1 | 24 | Y | | |
  26. # | 7 | 1 | END | Y | | |
  27. # |------|------|------|------|--------|--------|
  28. #
  29. # Places a brekpoint at file 2, line 22. Previously GDB would discard
  30. # the line table entry for this line due to switching files for the
  31. # file 1, line 18 non-statement line. After patching however, GDB now
  32. # discards the file 1, line 18 entry instead, and the breakpoint at
  33. # line 22 should succeed.
  34. #
  35. # The two inlined subroutine ranges 'A' and 'B' represent two possible
  36. # ways that a compiler might represent this siuatio in the DWARF.
  37. #
  38. # Range 'B' is something that has been seen in the wild using GCC 8.2.
  39. # In this case the compilers range information is clearly wrong, but
  40. # this shouldn't impact the main point of the test.
  41. #
  42. # Range 'A' is a hypothetical case of how the compiler might choose to
  43. # represent this range, this has never been seen in the wild, but is
  44. # an improved debug experiece over range 'B'. However, if we ever run
  45. # in to the situation where GDB can support the range 'A' test, or
  46. # support some real DWARF seen in the wild, then the range 'A' case
  47. # should be dropped in favour of supporting real world cases. This is
  48. # included here as it "just worked" once the range 'B' case was
  49. # working.
  50. load_lib dwarf.exp
  51. # This test can only be run on targets which support DWARF-2 and use gas.
  52. if {![dwarf2_support]} {
  53. return 0
  54. }
  55. # The .c files use __attribute__.
  56. if [get_compiler_info] {
  57. return -1
  58. }
  59. if !$gcc_compiled {
  60. return 0
  61. }
  62. # Prepare and run the test.
  63. proc do_test { start_label func_name tag } {
  64. global srcfile srcfile2 srcfile3 srcfile4 testfile
  65. standard_testfile dw2-inline-header-lbls.c dw2-inline-header-${tag}.S \
  66. dw2-inline-header.c dw2-inline-header.h
  67. set build_options {nodebug optimize=-O1}
  68. set asm_file [standard_output_file $srcfile2]
  69. Dwarf::assemble $asm_file {
  70. global srcdir subdir srcfile srcfile3 srcfile4 testfile
  71. upvar build_options build_options
  72. upvar start_label start_label
  73. declare_labels lines_label callee_subprog_label
  74. get_func_info main $build_options
  75. cu {} {
  76. compile_unit {
  77. {producer "gcc" }
  78. {language @DW_LANG_C}
  79. {name ${srcfile3}}
  80. {low_pc 0 addr}
  81. {stmt_list ${lines_label} DW_FORM_sec_offset}
  82. } {
  83. callee_subprog_label: subprogram {
  84. {external 1 flag}
  85. {name callee}
  86. {inline 3 data1}
  87. }
  88. subprogram {
  89. {external 1 flag}
  90. {name main}
  91. {low_pc $main_start addr}
  92. {high_pc "$main_start + $main_len" addr}
  93. } {
  94. inlined_subroutine {
  95. {abstract_origin %$callee_subprog_label}
  96. {low_pc $start_label addr}
  97. {high_pc line_label_6 addr}
  98. {call_file 1 data1}
  99. {call_line 18 data1}
  100. }
  101. }
  102. }
  103. }
  104. lines {version 2 default_is_stmt 1} lines_label {
  105. include_dir "${srcdir}/${subdir}"
  106. file_name "$srcfile3" 1
  107. file_name "$srcfile4" 1
  108. program {
  109. DW_LNE_set_address line_label_1
  110. DW_LNS_advance_line 15
  111. DW_LNS_copy
  112. DW_LNE_set_address line_label_2
  113. DW_LNS_advance_line 1
  114. DW_LNS_copy
  115. DW_LNS_set_file 2
  116. DW_LNE_set_address line_label_3
  117. DW_LNS_advance_line 4
  118. DW_LNS_copy
  119. DW_LNE_set_address line_label_4
  120. DW_LNS_advance_line 1
  121. DW_LNS_copy
  122. DW_LNS_advance_line -4
  123. DW_LNS_set_file 1
  124. DW_LNS_negate_stmt
  125. DW_LNS_copy
  126. DW_LNS_set_file 2
  127. DW_LNE_set_address line_label_5
  128. DW_LNS_advance_line 5
  129. DW_LNS_copy
  130. DW_LNS_negate_stmt
  131. DW_LNS_set_file 1
  132. DW_LNE_set_address line_label_6
  133. DW_LNS_advance_line 1
  134. DW_LNS_copy
  135. DW_LNE_set_address line_label_7
  136. DW_LNE_end_sequence
  137. }
  138. }
  139. }
  140. if { [prepare_for_testing "failed to prepare" ${testfile}-${tag} \
  141. [list $srcfile $asm_file] $build_options] } {
  142. return -1
  143. }
  144. if ![runto_main] {
  145. return -1
  146. }
  147. # Delete all breakpoints so that the output of "info breakpoints"
  148. # below will only contain a single breakpoint.
  149. delete_breakpoints
  150. # Place a breakpoint within the function in the header file.
  151. gdb_breakpoint "${srcfile4}:22"
  152. # Check that the breakpoint was placed where we expected. It should
  153. # appear at the requested line. When the bug in GDB was present the
  154. # breakpoint would be placed on one of the following lines instead.
  155. gdb_test "info breakpoints" \
  156. ".* in $func_name at \[^\r\n\]+${srcfile4}:22\\y.*" \
  157. "info breakpoints, $tag"
  158. }
  159. do_test line_label_3 "callee" "range-a"
  160. do_test line_label_5 "main" "range-b"