dw2-inline-many-frames.exp 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365
  1. # Copyright 2019-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. # This test shows the importance of not corrupting the order of line
  15. # table information. When multiple lines are given for the same
  16. # address the compiler usually lists these in the order in which we
  17. # would expect to encounter them. When stepping through nested inline
  18. # frames the last line given for an address is assumed by GDB to be
  19. # the most inner frame, and this is what GDB displays.
  20. #
  21. # If we corrupt the order of the line table entries then GDB will
  22. # display the wrong line as being the inner most frame.
  23. load_lib dwarf.exp
  24. # This test can only be run on targets which support DWARF-2 and use gas.
  25. if {![dwarf2_support]} {
  26. return 0
  27. }
  28. # The .c files use __attribute__.
  29. if [get_compiler_info] {
  30. return -1
  31. }
  32. if !$gcc_compiled {
  33. return 0
  34. }
  35. standard_testfile .c .S
  36. set asm_file [standard_output_file $srcfile2]
  37. Dwarf::assemble $asm_file {
  38. global srcdir subdir srcfile srcfile2
  39. declare_labels ranges_label lines_label
  40. declare_labels aaa_label bbb_label ccc_label
  41. declare_labels ggg_label hhh_label iii_label
  42. get_func_info main
  43. get_func_info ddd
  44. get_func_info eee
  45. get_func_info fff
  46. get_func_info jjj
  47. get_func_info kkk
  48. set call_in_main [gdb_get_line_number "main call aaa"]
  49. set call_in_aaa [gdb_get_line_number "aaa return"]
  50. set call_in_bbb [gdb_get_line_number "bbb return"]
  51. set call_in_ccc [gdb_get_line_number "ccc return"]
  52. set call_in_fff [gdb_get_line_number "fff return"]
  53. set call_in_ggg [gdb_get_line_number "ggg return"]
  54. set call_in_hhh [gdb_get_line_number "hhh return"]
  55. set call_in_iii [gdb_get_line_number "iii return"]
  56. cu {} {
  57. compile_unit {
  58. {language @DW_LANG_C}
  59. {name dw2-inline-stepping.c}
  60. {low_pc 0 addr}
  61. {stmt_list ${lines_label} DW_FORM_sec_offset}
  62. {ranges ${ranges_label} DW_FORM_sec_offset}
  63. } {
  64. subprogram {
  65. {external 1 flag}
  66. {name ddd}
  67. {low_pc $ddd_start addr}
  68. {high_pc "$ddd_start + $ddd_len" addr}
  69. }
  70. subprogram {
  71. {external 1 flag}
  72. {name eee}
  73. {low_pc $eee_start addr}
  74. {high_pc "$eee_start + $eee_len" addr}
  75. }
  76. subprogram {
  77. {external 1 flag}
  78. {name jjj}
  79. {low_pc $jjj_start addr}
  80. {high_pc "$jjj_start + $jjj_len" addr}
  81. }
  82. subprogram {
  83. {external 1 flag}
  84. {name kkk}
  85. {low_pc $kkk_start addr}
  86. {high_pc "$kkk_start + $kkk_len" addr}
  87. }
  88. aaa_label: subprogram {
  89. {name aaa}
  90. {inline 3 data1}
  91. }
  92. bbb_label: subprogram {
  93. {name bbb}
  94. {inline 3 data1}
  95. }
  96. ccc_label: subprogram {
  97. {name ccc}
  98. {inline 3 data1}
  99. }
  100. ggg_label: subprogram {
  101. {name ggg}
  102. {inline 3 data1}
  103. }
  104. hhh_label: subprogram {
  105. {name hhh}
  106. {inline 3 data1}
  107. }
  108. iii_label: subprogram {
  109. {name iii}
  110. {inline 3 data1}
  111. }
  112. subprogram {
  113. {external 1 flag}
  114. {name main}
  115. {low_pc $main_start addr}
  116. {high_pc "$main_start + $main_len" addr}
  117. } {
  118. inlined_subroutine {
  119. {abstract_origin %$aaa_label}
  120. {low_pc main_label2 addr}
  121. {high_pc main_label3 addr}
  122. {call_file 1 data1}
  123. {call_line $call_in_main data1}
  124. } {
  125. inlined_subroutine {
  126. {abstract_origin %$bbb_label}
  127. {low_pc main_label2 addr}
  128. {high_pc main_label3 addr}
  129. {call_file 1 data1}
  130. {call_line $call_in_aaa data1}
  131. } {
  132. inlined_subroutine {
  133. {abstract_origin %$ccc_label}
  134. {low_pc main_label2 addr}
  135. {high_pc main_label3 addr}
  136. {call_file 1 data1}
  137. {call_line $call_in_bbb data1}
  138. }
  139. }
  140. }
  141. }
  142. subprogram {
  143. {external 1 flag}
  144. {name fff}
  145. {low_pc $fff_start addr}
  146. {high_pc "$fff_start + $fff_len" addr}
  147. } {
  148. inlined_subroutine {
  149. {abstract_origin %$ggg_label}
  150. {low_pc fff_label addr}
  151. {high_pc main_label2 addr}
  152. {call_file 1 data1}
  153. {call_line $call_in_fff data1}
  154. } {
  155. inlined_subroutine {
  156. {abstract_origin %$hhh_label}
  157. {low_pc fff_label addr}
  158. {high_pc fff_label2 addr}
  159. {call_file 1 data1}
  160. {call_line $call_in_ggg data1}
  161. } {
  162. inlined_subroutine {
  163. {abstract_origin %$iii_label}
  164. {low_pc fff_label addr}
  165. {high_pc fff_label2 addr}
  166. {call_file 1 data1}
  167. {call_line $call_in_hhh data1}
  168. }
  169. }
  170. }
  171. }
  172. }
  173. }
  174. lines {version 2} lines_label {
  175. include_dir "${srcdir}/${subdir}"
  176. file_name "$srcfile" 1
  177. program {
  178. DW_LNE_set_address $main_start
  179. line [gdb_get_line_number "main prologue"]
  180. DW_LNS_copy
  181. DW_LNE_set_address main_label
  182. line [gdb_get_line_number "main set global_var"]
  183. DW_LNS_copy
  184. DW_LNE_set_address main_label2
  185. line [gdb_get_line_number "main call aaa"]
  186. DW_LNS_copy
  187. DW_LNE_set_address main_label2
  188. line [gdb_get_line_number "aaa return"]
  189. DW_LNS_copy
  190. DW_LNE_set_address main_label2
  191. line [gdb_get_line_number "bbb return"]
  192. DW_LNS_copy
  193. DW_LNE_set_address main_label2
  194. line [gdb_get_line_number "ccc return"]
  195. DW_LNS_copy
  196. DW_LNE_set_address main_label3
  197. line [gdb_get_line_number "main end"]
  198. DW_LNS_copy
  199. DW_LNE_set_address $main_end
  200. DW_LNE_end_sequence
  201. DW_LNE_set_address $ddd_start
  202. line [gdb_get_line_number "ddd prologue"]
  203. DW_LNS_copy
  204. DW_LNE_set_address ddd_label
  205. line [gdb_get_line_number "ddd return"]
  206. DW_LNS_copy
  207. DW_LNE_set_address ddd_label2
  208. line [gdb_get_line_number "ddd end"]
  209. DW_LNS_copy
  210. DW_LNE_set_address $ddd_end
  211. DW_LNE_end_sequence
  212. DW_LNE_set_address $eee_start
  213. line [gdb_get_line_number "eee prologue"]
  214. DW_LNS_copy
  215. DW_LNE_set_address eee_label
  216. line [gdb_get_line_number "eee return"]
  217. DW_LNS_copy
  218. DW_LNE_set_address eee_label2
  219. line [gdb_get_line_number "eee end"]
  220. DW_LNS_copy
  221. DW_LNE_set_address $eee_end
  222. DW_LNE_end_sequence
  223. DW_LNE_set_address $fff_start
  224. line [gdb_get_line_number "fff prologue"]
  225. DW_LNS_copy
  226. DW_LNE_set_address fff_label
  227. line [gdb_get_line_number "fff return"]
  228. DW_LNS_copy
  229. DW_LNE_set_address fff_label
  230. line [gdb_get_line_number "ggg return"]
  231. DW_LNS_copy
  232. DW_LNE_set_address fff_label
  233. line [gdb_get_line_number "hhh return"]
  234. DW_LNS_copy
  235. DW_LNE_set_address fff_label
  236. line [gdb_get_line_number "iii return"]
  237. DW_LNS_copy
  238. DW_LNE_set_address fff_label2
  239. line [gdb_get_line_number "fff end"]
  240. DW_LNS_copy
  241. DW_LNE_set_address $fff_end
  242. DW_LNE_end_sequence
  243. DW_LNE_set_address $jjj_start
  244. line [gdb_get_line_number "jjj prologue"]
  245. DW_LNS_copy
  246. DW_LNE_set_address jjj_label
  247. line [gdb_get_line_number "jjj return"]
  248. DW_LNS_copy
  249. DW_LNE_set_address jjj_label2
  250. line [gdb_get_line_number "jjj end"]
  251. DW_LNS_copy
  252. DW_LNE_set_address $jjj_end
  253. DW_LNE_end_sequence
  254. DW_LNE_set_address $kkk_start
  255. line [gdb_get_line_number "kkk prologue"]
  256. DW_LNS_copy
  257. DW_LNE_set_address kkk_label
  258. line [gdb_get_line_number "kkk return"]
  259. DW_LNS_copy
  260. DW_LNE_set_address $kkk_end
  261. DW_LNE_end_sequence
  262. }
  263. }
  264. ranges {is_64 [is_64_target]} {
  265. ranges_label: sequence {
  266. range ${main_start} ${main_end}
  267. range ${ddd_start} ${ddd_end}
  268. range ${eee_start} ${eee_end}
  269. range ${fff_start} ${fff_end}
  270. range ${jjj_start} ${jjj_end}
  271. range ${kkk_start} ${kkk_end}
  272. }
  273. }
  274. }
  275. if { [prepare_for_testing "failed to prepare" ${testfile} \
  276. [list $srcfile $asm_file] {nodebug}] } {
  277. return -1
  278. }
  279. if ![runto_main] {
  280. return -1
  281. }
  282. # First we step through all of the functions until we get the 'kkk'.
  283. set patterns [list "main call aaa" \
  284. "aaa return" \
  285. "bbb return" \
  286. "ccc return" \
  287. "ddd return" \
  288. "eee return" \
  289. "fff return" \
  290. "ggg return" \
  291. "hhh return" \
  292. "iii return" \
  293. "jjj return" \
  294. "kkk return" ]
  295. foreach p $patterns {
  296. gdb_test "step" "/\\* $p \\*/" \
  297. "step to '$p'"
  298. }
  299. # Now check the backtrace.
  300. set line_in_main [gdb_get_line_number "main call aaa"]
  301. set line_in_aaa [gdb_get_line_number "aaa return"]
  302. set line_in_bbb [gdb_get_line_number "bbb return"]
  303. set line_in_ccc [gdb_get_line_number "ccc return"]
  304. set line_in_ddd [gdb_get_line_number "ddd return"]
  305. set line_in_eee [gdb_get_line_number "eee return"]
  306. set line_in_fff [gdb_get_line_number "fff return"]
  307. set line_in_ggg [gdb_get_line_number "ggg return"]
  308. set line_in_hhh [gdb_get_line_number "hhh return"]
  309. set line_in_iii [gdb_get_line_number "iii return"]
  310. set line_in_jjj [gdb_get_line_number "jjj return"]
  311. set line_in_kkk [gdb_get_line_number "kkk return"]
  312. gdb_test "bt" [multi_line \
  313. "#0 kkk \\(\\) at \[^\r\n\]+${srcfile}:${line_in_kkk}" \
  314. "#1 $hex in jjj \\(\\) at \[^\r\n\]+${srcfile}:${line_in_jjj}" \
  315. "#2 $hex in iii \\(\\) at \[^\r\n\]+${srcfile}:${line_in_iii}" \
  316. "#3 hhh \\(\\) at \[^\r\n\]+${srcfile}:${line_in_hhh}" \
  317. "#4 ggg \\(\\) at \[^\r\n\]+${srcfile}:${line_in_ggg}" \
  318. "#5 fff \\(\\) at \[^\r\n\]+${srcfile}:${line_in_fff}" \
  319. "#6 $hex in eee \\(\\) at \[^\r\n\]+${srcfile}:${line_in_eee}" \
  320. "#7 $hex in ddd \\(\\) at \[^\r\n\]+${srcfile}:${line_in_ddd}" \
  321. "#8 $hex in ccc \\(\\) at \[^\r\n\]+${srcfile}:${line_in_ccc}" \
  322. "#9 bbb \\(\\) at \[^\r\n\]+${srcfile}:${line_in_bbb}" \
  323. "#10 aaa \\(\\) at \[^\r\n\]+${srcfile}:${line_in_aaa}" \
  324. "#11 main \\(\\) at \[^\r\n\]+${srcfile}:${line_in_main}" ]
  325. # Now check we can use 'up' to inspect each frame correctly.
  326. set patterns [list \
  327. "jjj return" \
  328. "iii return" \
  329. "hhh return" \
  330. "ggg return" \
  331. "fff return" \
  332. "eee return" \
  333. "ddd return" \
  334. "ccc return" \
  335. "bbb return" \
  336. "aaa return" \
  337. "main call aaa" ]
  338. foreach p $patterns {
  339. gdb_test "up" "/\\* $p \\*/" \
  340. "up to '$p'"
  341. }