dw2-inline-small-func.exp 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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. # Check for an issue in GDB where buildsym_compunit::record_line was
  15. # removing duplicate line table entries, but skip_prologue_using_sal
  16. # depends on these duplicates to spot the end of the prologue.
  17. #
  18. # When the de-duplication was added this regression was not spotted as
  19. # it requires a particular combination of a (very) small function
  20. # being inlined into an also very small outer function.
  21. #
  22. # This test recreates the exact combination of line table entries that
  23. # were seen in the original test using the Dejagnu DWARF compiler.
  24. load_lib dwarf.exp
  25. # This test can only be run on targets which support DWARF-2 and use gas.
  26. if {![dwarf2_support]} {
  27. return 0
  28. }
  29. # The .c files use __attribute__.
  30. if [get_compiler_info] {
  31. return -1
  32. }
  33. if !$gcc_compiled {
  34. return 0
  35. }
  36. standard_testfile -lbls.c .S \
  37. .c .h
  38. set asm_file [standard_output_file $srcfile2]
  39. Dwarf::assemble $asm_file {
  40. global srcdir subdir srcfile srcfile3 srcfile4
  41. declare_labels lines_label callee_subprog_label
  42. get_func_info main {debug optimize=-O1}
  43. cu {} {
  44. # It is important that the producer here be 'clang' as, at the
  45. # time of writing this, GCC for x86-64 doesn't make use of
  46. # skip_prologue_using_sal, while clang does.
  47. compile_unit {
  48. {producer "clang xxxx" }
  49. {language @DW_LANG_C}
  50. {name ${srcfile3}}
  51. {low_pc 0 addr}
  52. {stmt_list ${lines_label} DW_FORM_sec_offset}
  53. } {
  54. callee_subprog_label: subprogram {
  55. {external 1 flag}
  56. {name callee}
  57. {inline 3 data1}
  58. }
  59. subprogram {
  60. {external 1 flag}
  61. {name main}
  62. {low_pc $main_start addr}
  63. {high_pc "$main_start + $main_len" addr}
  64. } {
  65. inlined_subroutine {
  66. {abstract_origin %$callee_subprog_label}
  67. {low_pc line_label_1 addr}
  68. {high_pc line_label_2 addr}
  69. {call_file 1 data1}
  70. {call_line 21 data1}
  71. }
  72. }
  73. }
  74. }
  75. lines {version 2 default_is_stmt 1} lines_label {
  76. include_dir "${srcdir}/${subdir}"
  77. file_name "$srcfile3" 1
  78. file_name "$srcfile4" 1
  79. set f1_l1 [gdb_get_line_number "caller: before call" $srcfile3]
  80. set f1_l2 [gdb_get_line_number "caller: the call" $srcfile3]
  81. set f1_l3 [gdb_get_line_number "caller: after call" $srcfile3]
  82. set f2_l1 [gdb_get_line_number "callee: body" $srcfile4]
  83. program {
  84. DW_LNE_set_address line_label_1
  85. line $f1_l1
  86. DW_LNS_copy
  87. line ${f1_l2}
  88. DW_LNS_copy
  89. DW_LNS_set_file 2
  90. line ${f2_l1}
  91. DW_LNS_copy
  92. DW_LNS_negate_stmt
  93. DW_LNS_copy
  94. DW_LNS_set_file 1
  95. DW_LNE_set_address line_label_2
  96. line ${f1_l3}
  97. DW_LNS_copy
  98. DW_LNE_set_address line_label_3
  99. DW_LNS_copy
  100. DW_LNE_end_sequence
  101. }
  102. }
  103. }
  104. if { [prepare_for_testing "failed to prepare" ${testfile} \
  105. [list $srcfile $asm_file] {nodebug optimize=-O1}] } {
  106. return -1
  107. }
  108. if ![runto_main] {
  109. return -1
  110. }
  111. # Delete all breakpoints so that the output of "info breakpoints"
  112. # below will only contain a single breakpoint.
  113. delete_breakpoints
  114. # Place a breakpoint within the function in the header file.
  115. set linenum [gdb_get_line_number "callee: body" $srcfile4]
  116. gdb_breakpoint "${srcfile4}:${linenum}"
  117. # Check that the breakpoint was placed where we expected. It should
  118. # appear at the requested line. When the bug in GDB was present the
  119. # breakpoint would be placed on one of the following lines instead.
  120. gdb_test "info breakpoints" \
  121. ".* in callee at \[^\r\n\]+${srcfile4}:${linenum}\\y.*"