PageRenderTime 48ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/gdb/testsuite/gdb.base/foll-vfork.exp

https://github.com/rofl0r/gdb
Expect | 408 lines | 256 code | 46 blank | 106 comment | 20 complexity | 74c819651aebd26f227718cf3ec0b8fe MD5 | raw file
  1. # Copyright 1997, 1999, 2007, 2008, 2009, 2010, 2011
  2. # Free Software Foundation, Inc.
  3. # This program is free software; you can redistribute it and/or modify
  4. # it under the terms of the GNU General Public License as published by
  5. # the Free Software Foundation; either version 3 of the License, or
  6. # (at your option) any later version.
  7. #
  8. # This program is distributed in the hope that it will be useful,
  9. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. # GNU General Public License for more details.
  12. #
  13. # You should have received a copy of the GNU General Public License
  14. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. if { [is_remote target] || ![isnative] } then {
  16. continue
  17. }
  18. # NOTE drow/2002-12-06: I don't know what the referenced kernel problem
  19. # is, but it appears to be fixed in recent HP/UX versions.
  20. ##if [istarget "hppa2.0w-hp-hpux*"] {
  21. ## warning "Don't run gdb.base/foll-vfork.exp until JAGaa43495 kernel problem is fixed."
  22. ## return 0
  23. ##}
  24. global srcfile
  25. set testfile "foll-vfork"
  26. set testfile2 "vforked-prog"
  27. set srcfile ${testfile}.c
  28. set srcfile2 ${testfile2}.c
  29. set binfile ${objdir}/${subdir}/${testfile}
  30. set binfile2 ${objdir}/${subdir}/${testfile2}
  31. if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
  32. untested foll-vfork.exp
  33. return -1
  34. }
  35. if { [gdb_compile "${srcdir}/${subdir}/${srcfile2}" "${binfile2}" executable {debug}] != "" } {
  36. untested foll-vfork.exp
  37. return -1
  38. }
  39. # Until "set follow-fork-mode" and "catch vfork" are implemented on
  40. # other targets...
  41. #
  42. if {![istarget "hppa*-hp-hpux*"] && ![istarget "*-linux*"]} then {
  43. continue
  44. }
  45. # Test to see if we are on an HP-UX 10.20 and if so,
  46. # do not run these tests as catching vfork is disabled for
  47. # 10.20.
  48. if [istarget "hppa*-hp-hpux10.20"] then {
  49. return 0
  50. }
  51. # A few of these tests require a little more time than the standard
  52. # timeout allows.
  53. set oldtimeout $timeout
  54. set timeout [expr "$timeout + 10"]
  55. proc check_vfork_catchpoints {} {
  56. global gdb_prompt
  57. global has_vfork_catchpoints
  58. # Verify that the system supports "catch vfork".
  59. gdb_test "catch vfork" "Catchpoint \[0-9\]* \\(vfork\\)" "insert first vfork catchpoint"
  60. set has_vfork_catchpoints 0
  61. gdb_test_multiple "continue" "continue to first vfork catchpoint" {
  62. -re ".*Your system does not support this type\r\nof catchpoint.*$gdb_prompt $" {
  63. unsupported "continue to first vfork catchpoint"
  64. }
  65. -re ".*Catchpoint.*$gdb_prompt $" {
  66. set has_vfork_catchpoints 1
  67. pass "continue to first vfork catchpoint"
  68. }
  69. }
  70. if {$has_vfork_catchpoints == 0} {
  71. unsupported "vfork catchpoints"
  72. return -code return
  73. }
  74. }
  75. proc vfork_parent_follow_through_step {} {
  76. global gdb_prompt
  77. send_gdb "set follow-fork parent\n"
  78. gdb_expect {
  79. -re "$gdb_prompt $" {pass "set follow-fork parent, vfork through step"}
  80. timeout {fail "set follow-fork parent, vfork through step"}
  81. }
  82. send_gdb "next\n"
  83. gdb_expect {
  84. -re "Detaching after fork from.*13.*$gdb_prompt "\
  85. {pass "vfork parent follow, through step"}
  86. -re "$gdb_prompt $" {fail "vfork parent follow, through step"}
  87. timeout {fail "(timeout) vfork parent follow, through step" }
  88. }
  89. # The child has been detached; allow time for any output it might
  90. # generate to arrive, so that output doesn't get confused with
  91. # any gdb_expected debugger output from a subsequent testpoint.
  92. #
  93. exec sleep 1
  94. }
  95. proc vfork_parent_follow_to_bp {} {
  96. global gdb_prompt
  97. global srcfile
  98. send_gdb "set follow-fork parent\n"
  99. gdb_expect {
  100. -re "$gdb_prompt $" {pass "set follow-fork parent, vfork to bp"}
  101. timeout {fail "set follow-fork parent, vfork to bp"}
  102. }
  103. send_gdb "break ${srcfile}:18\n"
  104. gdb_expect {
  105. -re "$gdb_prompt $" {pass "break, vfork to bp"}
  106. timeout {fail "break, vfork to bp"}
  107. }
  108. send_gdb "continue\n"
  109. gdb_expect {
  110. -re ".*Detaching after fork from child process.*Breakpoint.*18.*$gdb_prompt "\
  111. {pass "vfork parent follow, to bp"}
  112. -re "$gdb_prompt $" {fail "vfork parent follow, to bp"}
  113. timeout {fail "(timeout) vfork parent follow, to bp" }
  114. }
  115. # The child has been detached; allow time for any output it might
  116. # generate to arrive, so that output doesn't get confused with
  117. # any expected debugger output from a subsequent testpoint.
  118. #
  119. exec sleep 1
  120. }
  121. proc vfork_and_exec_child_follow_to_main_bp {} {
  122. global gdb_prompt
  123. global binfile
  124. send_gdb "set follow-fork child\n"
  125. gdb_expect {
  126. -re "$gdb_prompt $" {pass "set follow-fork child, vfork and exec to main bp"}
  127. timeout {fail "set follow-fork child, vfork and exec to main bp"}
  128. }
  129. send_gdb "continue\n"
  130. gdb_expect {
  131. -re "Attaching after.* vfork to.*xecuting new program.*Breakpoint.*vforked-prog.c:9.*$gdb_prompt "\
  132. {pass "vfork and exec child follow, to main bp"}
  133. -re "$gdb_prompt $" {fail "vfork and exec child follow, to main bp"}
  134. timeout {fail "(timeout) vfork and exec child follow, to main bp" }
  135. }
  136. # The parent has been detached; allow time for any output it might
  137. # generate to arrive, so that output doesn't get confused with
  138. # any gdb_expected debugger output from a subsequent testpoint.
  139. #
  140. exec sleep 1
  141. # Explicitly kill this child, or a subsequent rerun actually runs
  142. # the exec'd child, not the original program...
  143. send_gdb "kill\n"
  144. gdb_expect {
  145. -re ".*Kill the program being debugged.*y or n. $" {
  146. send_gdb "y\n"
  147. send_gdb "file $binfile\n"
  148. gdb_expect {
  149. -re ".*Load new symbol table from.*y or n. $" {
  150. send_gdb "y\n"
  151. gdb_expect {
  152. -re "Reading symbols from.*$gdb_prompt $" {}
  153. timeout { fail "loading symbols (timeout)"; return }
  154. }
  155. }
  156. -re ".*gdb_prompt $" {}
  157. timeout { fail "loading symbols (timeout)"; return }
  158. }
  159. }
  160. -re ".*$gdb_prompt $" {}
  161. timeout { fail "killing inferior (timeout)" ; return }
  162. }
  163. }
  164. proc vfork_and_exec_child_follow_through_step {} {
  165. global gdb_prompt
  166. global binfile
  167. # This test cannot be performed prior to HP-UX 10.30, because ptrace-based
  168. # debugging of a vforking program basically doesn't allow the child to do
  169. # things like hit a breakpoint between a vfork and exec. This means that
  170. # saying "set follow-fork child; next" at a vfork() call won't work, because
  171. # the implementation of "next" sets a "step resume" breakpoint at the
  172. # return from the vfork(), which the child will hit on its way to exec'ing.
  173. #
  174. if { ![istarget "hppa*-*-hpux11.*"] } {
  175. verbose "vfork child-following next test ignored for non-hppa or pre-HP/UX-10.30 targets."
  176. return 0
  177. }
  178. send_gdb "set follow-fork child\n"
  179. gdb_expect {
  180. -re "$gdb_prompt $" {pass "set follow-fork child, vfork and exec through step"}
  181. timeout {fail "set follow-fork child, vfork and exec through step"}
  182. }
  183. send_gdb "next\n"
  184. gdb_expect {
  185. -re "Attaching after fork to.*Executing new program.*Breakpoint.*vforked-prog.c:9.*$gdb_prompt "\
  186. {pass "vfork and exec child follow, through step"}
  187. -re "$gdb_prompt $" {fail "vfork and exec child follow, through step"}
  188. timeout {fail "(timeout) vfork and exec child follow, through step" }
  189. }
  190. # The parent has been detached; allow time for any output it might
  191. # generate to arrive, so that output doesn't get confused with
  192. # any expected debugger output from a subsequent testpoint.
  193. #
  194. exec sleep 1
  195. # Explicitly kill this child, or a subsequent rerun actually runs
  196. # the exec'd child, not the original program...
  197. send_gdb "kill\n"
  198. gdb_expect {
  199. -re ".*Kill the program being debugged.*y or n. $" {
  200. send_gdb "y\n"
  201. send_gdb "file $binfile\n"
  202. gdb_expect {
  203. -re ".*Load new symbol table from.*y or n. $" {
  204. send_gdb "y\n"
  205. gdb_expect {
  206. -re "Reading symbols from.*$gdb_prompt $" {}
  207. timeout { fail "loading symbols (timeout)"; return }
  208. }
  209. }
  210. -re ".*gdb_prompt $" {}
  211. timeout { fail "loading symbols (timeout)"; return }
  212. }
  213. }
  214. -re ".*$gdb_prompt $" {}
  215. timeout { fail "killing inferior (timeout)" ; return }
  216. }
  217. }
  218. proc tcatch_vfork_then_parent_follow {} {
  219. global gdb_prompt
  220. global srcfile
  221. send_gdb "set follow-fork parent\n"
  222. gdb_expect {
  223. -re "$gdb_prompt $" {pass "set follow-fork parent, tcatch vfork"}
  224. timeout {fail "set follow-fork parent, tcatch vfork"}
  225. }
  226. send_gdb "tcatch vfork\n"
  227. gdb_expect {
  228. -re "Catchpoint .*(vfork).*$gdb_prompt $"\
  229. {pass "vfork parent follow, set tcatch vfork"}
  230. -re "$gdb_prompt $" {fail "vfork parent follow, set tcatch vfork"}
  231. timeout {fail "(timeout) vfork parent follow, set tcatch vfork"}
  232. }
  233. send_gdb "continue\n"
  234. # HP-UX 10.20 seems to stop you in "vfork", while more recent HP-UXs
  235. # stop you in "_vfork".
  236. gdb_expect {
  237. -re "0x\[0-9a-fA-F\]*.*(vfork|__kernel_v?syscall).*$gdb_prompt "\
  238. {pass "vfork parent follow, tcatch vfork"}
  239. -re "vfork \\(\\) at.*$gdb_prompt "\
  240. {pass "vfork parent follow, tcatch vfork"}
  241. -re "$gdb_prompt $" {fail "vfork parent follow, tcatch vfork"}
  242. timeout {fail "(timeout) vfork parent follow, tcatch vfork"}
  243. }
  244. send_gdb "finish\n"
  245. gdb_expect {
  246. -re "Run till exit from.*vfork.*0x\[0-9a-fA-F\]* in main .* at .*${srcfile}:12.*$gdb_prompt "\
  247. {pass "vfork parent follow, finish after tcatch vfork"}
  248. -re "Run till exit from.*__kernel_v?syscall.*0x\[0-9a-fA-F\]* in vfork .*$gdb_prompt " {
  249. send_gdb "finish\n"
  250. exp_continue
  251. }
  252. -re "$gdb_prompt $" {fail "vfork parent follow, finish after tcatch vfork"}
  253. timeout {fail "(timeout) vfork parent follow, finish after tcatch vfork" }
  254. }
  255. # The child has been detached; allow time for any output it might
  256. # generate to arrive, so that output doesn't get confused with
  257. # any expected debugger output from a subsequent testpoint.
  258. #
  259. exec sleep 1
  260. }
  261. proc tcatch_vfork_then_child_follow {} {
  262. global gdb_prompt
  263. global srcfile
  264. global srcfile2
  265. send_gdb "set follow-fork child\n"
  266. gdb_expect {
  267. -re "$gdb_prompt $" {pass "set follow-fork child, tcatch vfork"}
  268. timeout {fail "set follow-fork child, tcatch vfork"}
  269. }
  270. send_gdb "tcatch vfork\n"
  271. gdb_expect {
  272. -re "Catchpoint .*(vfork).*$gdb_prompt $"\
  273. {pass "vfork child follow, set tcatch vfork"}
  274. -re "$gdb_prompt $" {fail "vfork child follow, set tcatch vfork"}
  275. timeout {fail "(timeout) vfork child follow, set tcatch vfork"}
  276. }
  277. send_gdb "continue\n"
  278. # HP-UX 10.20 seems to stop you in "vfork", while more recent HP-UXs
  279. # stop you in "_vfork".
  280. gdb_expect {
  281. -re "vfork \\(\\) at .*$gdb_prompt $"\
  282. {pass "vfork child follow, tcatch vfork"}
  283. -re "0x\[0-9a-fA-F\]*.*(vfork|__kernel_v?syscall).*$gdb_prompt "\
  284. {pass "vfork child follow, tcatch vfork"}
  285. -re "$gdb_prompt $" {fail "vfork child follow, tcatch vfork"}
  286. timeout {fail "(timeout) vfork child follow, tcatch vfork"}
  287. }
  288. send_gdb "finish\n"
  289. gdb_expect {
  290. -re "Run till exit from.*vfork.*${srcfile}:12.*$gdb_prompt "\
  291. {pass "vfork child follow, finish after tcatch vfork"}
  292. -re "Run till exit from.*__kernel_v?syscall.*0x\[0-9a-fA-F\]* in vfork .*$gdb_prompt " {
  293. send_gdb "finish\n"
  294. exp_continue
  295. }
  296. -re "Run till exit from.*vfork.*${srcfile2}:9.*$gdb_prompt "\
  297. {pass "vfork child follow, finish after tcatch vfork (followed exec)"}
  298. -re "$gdb_prompt $" {fail "vfork child follow, finish after tcatch vfork"}
  299. timeout {fail "(timeout) vfork child follow, finish after tcatch vfork" }
  300. }
  301. # The parent has been detached; allow time for any output it might
  302. # generate to arrive, so that output doesn't get confused with
  303. # any expected debugger output from a subsequent testpoint.
  304. #
  305. exec sleep 1
  306. }
  307. proc do_vfork_and_exec_tests {} {
  308. global gdb_prompt
  309. # Check that vfork catchpoints are supported, as an indicator for whether
  310. # vfork-following is supported.
  311. if [runto_main] then { check_vfork_catchpoints }
  312. # Try following the parent process by stepping through a call to
  313. # vfork. Do this without catchpoints.
  314. if [runto_main] then { vfork_parent_follow_through_step }
  315. # Try following the parent process by setting a breakpoint on the
  316. # other side of a vfork, and running to that point. Do this
  317. # without catchpoints.
  318. if [runto_main] then { vfork_parent_follow_to_bp }
  319. # Try following the child process by just continuing through the
  320. # vfork, and letting the parent's breakpoint on "main" be auto-
  321. # magically reset in the child.
  322. #
  323. if [runto_main] then { vfork_and_exec_child_follow_to_main_bp }
  324. # Try following the child process by stepping through a call to
  325. # vfork. The child also executes an exec. Since the child cannot
  326. # be debugged until after it has exec'd, and since there's a bp on
  327. # "main" in the parent, and since the bp's for the parent are
  328. # recomputed in the exec'd child, the step through a vfork should
  329. # land us in the "main" for the exec'd child, too.
  330. #
  331. if [runto_main] then { vfork_and_exec_child_follow_through_step }
  332. # Try catching a vfork, and stepping out to the parent.
  333. #
  334. if [runto_main] then { tcatch_vfork_then_parent_follow }
  335. # Try catching a vfork, and stepping out to the child.
  336. #
  337. if [runto_main] then { tcatch_vfork_then_child_follow }
  338. # Test the ability to follow both child and parent of a vfork. Do
  339. # this without catchpoints.
  340. # ??rehrauer: NYI. Will add testpoints here when implemented.
  341. #
  342. # Test the ability to have the debugger ask the user at vfork-time
  343. # whether to follow the parent, child or both. Do this without
  344. # catchpoints.
  345. # ??rehrauer: NYI. Will add testpoints here when implemented.
  346. #
  347. }
  348. # Start with a fresh gdb
  349. gdb_exit
  350. gdb_start
  351. gdb_reinitialize_dir $srcdir/$subdir
  352. gdb_load ${binfile}
  353. # The "Detaching..." and "Attaching..." messages may be hidden by
  354. # default.
  355. gdb_test_no_output "set verbose"
  356. # This is a test of gdb's ability to follow the parent or child
  357. # of a Unix vfork() system call. (The child will subsequently
  358. # call a variant of a Unix exec() system call.)
  359. #
  360. do_vfork_and_exec_tests
  361. set timeout $oldtimeout
  362. return 0