home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / gnu / gdb-4.9 / gdb / testsuite / gdb.t06 / break.exp next >
Encoding:
Text File  |  1993-05-12  |  11.9 KB  |  419 lines

  1. #   Copyright (C) 1988, 1990, 1991, 1992 Free Software Foundation, Inc.
  2.  
  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 2 of the License, or
  6. # (at your option) any later version.
  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. # You should have received a copy of the GNU General Public License
  12. # along with this program; if not, write to the Free Software
  13. # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  14.  
  15. # Please email any bugs, comments, and/or additions to this file to:
  16. # bug-gdb@prep.ai.mit.edu
  17.  
  18. # This file was written by Rob Savoye. (rob@cygnus.com)
  19.  
  20. if $tracelevel then {
  21.     strace $tracelevel
  22.     }
  23.  
  24. #
  25. # test running programs
  26. #
  27. set prms_id 0
  28. set bug_id 0
  29.  
  30. set binfile "gdbme"
  31. set srcfile $binfile.c
  32.  
  33. if ![file exists $objdir/$subdir/$binfile] then {
  34.     error "$objdir/$subdir/$binfile does not exist."
  35.     alldone
  36. }
  37.  
  38. gdb_exit
  39. gdb_start
  40. gdb_reinitialize_dir $srcdir/$subdir
  41. gdb_load $objdir/$subdir/$binfile
  42.  
  43. #
  44. # test simple breakpoint setting commands
  45. #
  46.  
  47. #
  48. # test deleting all breakpoints; note that gdb-init.exp provides a
  49. # "delete_breakpoints" proc for general use elsewhere
  50. #
  51. send "delete breakpoints\n"
  52. expect {
  53.     -re "Delete all breakpoints\? \(y or n\) $"\
  54.     { send "y\n"
  55.         expect {
  56.         -re ".*$prompt $"\
  57.             { send "info breakpoints\n"
  58.             expect {
  59.                 -re "No breakpoints or watchpoints..*$prompt $" { pass "Deleted all breakpoints" }
  60.                 -re ".*$prompt $"       { fail "Deleted all breakpoints" }
  61.                 timeout                { fail "Deleted all breakpoints" }
  62.             }
  63.             }
  64.         timeout                { fail "Deleted all breakpoints" }        
  65.         }
  66.     }
  67.     -re ".*$prompt $"       { fail "Deleted all breakpoints" }
  68.     timeout                { fail "Deleted all breakpoints" }
  69. }
  70.  
  71. #
  72. # test break at function
  73. #
  74. send "break main\n"
  75. expect {
  76.     -re "Breakpoint.*at.* file .*$srcfile, line.*$prompt $" { pass "breakpoint function" }
  77.     -re ".*$prompt $"   { fail "breakpoint function" }
  78.     timeout        { fail "(timeout) breakpoint function" }
  79. }
  80.  
  81.  
  82. #
  83. # test break at function in file
  84. #
  85. send "break $srcfile:factorial\n"
  86. expect {
  87.     -re "Breakpoint.*at.* file .*$srcfile, line.*$prompt $" { pass "breakpoint function in file" }
  88.     -re ".*$prompt $"   { fail "breakpoint function in file" }
  89.     timeout        { fail "(timeout) breakpoint function in file" }
  90. }
  91.  
  92.  
  93. #
  94. # test break at line number
  95. #
  96. send "break 60\n"
  97. expect {
  98.     -re "Breakpoint.*at.* file .*$srcfile, line 60.*$prompt $" { pass "breakpoint line number" }
  99.     -re ".*$prompt $"   { fail "breakpoint line number" }
  100.     timeout        { fail "(timeout) breakpoint line number" }
  101. }
  102.  
  103.  
  104. #
  105. # test duplicate breakpoint
  106. #
  107. send "break 60\n"
  108. expect {
  109.     -re "Note: breakpoint \[0-9\]+ also set at pc.*Breakpoint \[0-9\]+ at.* file .*$srcfile, line 60.*$prompt $"\
  110.                         { pass "breakpoint duplicate" }
  111.     -re ".*$prompt $"   { fail "breakpoint duplicate" }
  112.     timeout        { fail "(timeout) breakpoint duplicate" }
  113. }
  114.  
  115.  
  116. #
  117. # test break at line number in file
  118. #
  119. send "break $srcfile:66\n"
  120. expect {
  121.     -re "Breakpoint.*at.* file .*$srcfile, line 66.*$prompt $" { pass "breakpoint line number in file" }
  122.     -re ".*$prompt $"   { fail "breakpoint line number in file" }
  123.     timeout        { fail "(timeout) breakpoint line number in file" }
  124. }
  125.  
  126.  
  127. #
  128. # check to see what breakpoints are set
  129. #
  130. send "info break\n"
  131. expect {
  132.     -re "Num Type\[ \]+Disp Enb Address\[ \]+What.*\
  133. \[0-9\]+\[\t \]+breakpoint     keep y.* in main at .*$srcfile:56.*\
  134. \[0-9\]+\[\t \]+breakpoint     keep y.* in factorial at .*$srcfile:72.*\
  135. \[0-9\]+\[\t \]+breakpoint     keep y.* in main at .*$srcfile:60.*\
  136. \[0-9\]+\[\t \]+breakpoint     keep y.* in main at .*$srcfile:60.*\
  137. \[0-9\]+\[\t \]+breakpoint     keep y.* in main at .*$srcfile:66.*$prompt $" { pass "breakpoint info" }
  138.     -re ".*$prompt $"   { fail "breakpoint info" }
  139.     timeout        { fail "(timeout) breakpoint info" }
  140. }
  141.  
  142.  
  143. # FIXME: The rest of this test doesn't work with anything that can't
  144. # handle arguments.
  145. if [istarget "mips-idt-*"] then {
  146.     return
  147. }
  148.  
  149. #
  150. # run until the breakpoint at main is hit
  151. #
  152. if [istarget "*-*-vxworks"] then {
  153.     send "run vxmain \"2\"\n"
  154.     set timeout 120
  155. } else {
  156.     if [istarget "a29k-*-udi"] then {
  157.     send "run gdbme 2\n"
  158.     } else {
  159.     send "run 2\n"
  160.     }
  161. }
  162. expect {
  163.     -re "Starting program.*Breakpoint \[0-9\]+,.*main \(argc.*argv.*envp.*\) at .*$srcfile:56.*\
  164. 56\[\t \]+if \(argc.*\) \{.*$prompt $"\
  165.                         { pass "run until function breakpoint" }
  166.     -re ".*$prompt $"       { fail "run until function breakpoint" }
  167.     timeout                { fail "(timeout) run until function breakpoint" }
  168. }
  169.  
  170.  
  171. #
  172. # run until the breakpoint at a line number
  173. #
  174. send "continue\n"
  175. expect {
  176.     -re "continue.*Continuing..*Breakpoint \[0-9\]+, main \(argc.*argv.*envp.*\) at .*$srcfile:60.*\
  177. 60\[\t ]+printf.*factorial.*$prompt $" { pass "run until breakpoint set at a line number" }
  178.     -re ".*$prompt $"       { fail "run until breakpoint set at a line number" }
  179.     timeout                { fail "(timeout) run until breakpoint set at a line number" }
  180. }
  181.  
  182.  
  183. #
  184. # Run until the breakpoint set in a function in a file
  185. #
  186. send "continue\n"
  187. expect {
  188.     -re "continue.*Continuing..*Breakpoint \[0-9\]+, factorial \(value=2\) at .*$srcfile:72.*\
  189. 72\[\t ]+if \(value > 1\) \{.*$prompt $"\
  190.     { send "continue\n"
  191.         expect {
  192.         -re "continue.*Continuing..*Breakpoint \[0-9\]+, factorial \(value=1\) at .*$srcfile:72.*\
  193. 72\[\t ]+if \(value > 1\) \{.*$prompt $" { pass "run until file:function breakpoint" }
  194.         -re ".*$prompt $"       { fail "run until file:function breakpoint" }
  195.         timeout                { fail "(timeout) run until file:function breakpoint" }
  196.         }
  197.     }
  198.     -re ".*$prompt $"       { fail "run until file:function breakpoint" }
  199.     timeout                { fail "(timeout) run until file:function breakpoint" }
  200. }
  201.  
  202.  
  203. #
  204. # run until the file:function breakpoint at a line number in a file
  205. #
  206. send "continue\n"
  207. expect {
  208.     -re "continue.*Continuing..*Breakpoint \[0-9\]+, main \(argc.*argv.*envp.*\) at .*$srcfile:66.*\
  209. 66\[\t ]+return 0;.*$prompt $" { pass "run until file:linenum breakpoint" }
  210.     -re ".*$prompt $"       { fail "run until file:linenum breakpoint" }
  211.     timeout                { fail "(timeout) run until file:linenum breakpoint" }
  212. }
  213.  
  214.  
  215. #
  216. # delete all breakpoints so we can start over, course this can be a test too
  217. #
  218. send "delete breakpoints\n"
  219. expect {
  220.     -re "Delete all breakpoints\? \(y or n\) $"\
  221.     { send "y\n"
  222.         expect {
  223.         -re ".*$prompt $"\
  224.             { send "info breakpoints\n"
  225.             expect {
  226.                 -re "No breakpoints or watchpoints..*$prompt $" { pass "Deleted all breakpoints" }
  227.                 -re ".*$prompt $"       { fail "Deleted all breakpoints" }
  228.                 timeout                { fail "Deleted all breakpoints" }
  229.             }
  230.             }
  231.         timeout                { fail "Deleted all breakpoints" }        
  232.         }
  233.     }
  234.     -re ".*$prompt $"       { fail "Deleted all breakpoints" }
  235.     timeout                { fail "Deleted all breakpoints" }
  236. }
  237.  
  238.  
  239. #
  240. # test temporary breakpoint at function
  241. #
  242. send "tbreak main\n"
  243. expect {
  244.     -re "Breakpoint.*at.* file .*$srcfile, line.*$prompt $" { pass "Temporary breakpoint function" }
  245.     -re ".*$prompt $"   { pass "Temporary breakpoint function" }
  246.     timeout        { fail "(timeout) breakpoint function" }
  247. }
  248.  
  249.  
  250. #
  251. # test break at function in file
  252. #
  253. send "tbreak $srcfile:factorial\n"
  254. expect {
  255.     -re "Breakpoint.*at.* file .*$srcfile, line.*$prompt $" { pass "Temporary breakpoint function in file" }
  256.     -re ".*$prompt $"   { pass "Temporary breakpoint function in file" }
  257.     timeout        { fail "(timeout) breakpoint function in file" }
  258. }
  259.  
  260.  
  261. #
  262. # test break at line number
  263. #
  264. send "tbreak 60\n"
  265. expect {
  266.     -re "Breakpoint.*at.* file .*$srcfile, line 60.*$prompt $" { pass "Temporary breakpoint line number" }
  267.     -re ".*$prompt $"   { pass "Temporary breakpoint line number" }
  268.     timeout        { fail "(timeout) breakpoint line number" }
  269. }
  270.  
  271.  
  272. #
  273. # test break at line number in file
  274. #
  275. send "tbreak $srcfile:66\n"
  276. expect {
  277.     -re "Breakpoint.*at.* file .*$srcfile, line 66.*$prompt $" { pass "Temporary breakpoint line number in file" }
  278.     -re ".*$prompt $"   { pass "Temporary breakpoint line number in file" }
  279.     timeout        { fail "(timeout) breakpoint line number in file" }
  280. }
  281.  
  282.  
  283. #
  284. # check to see what breakpoints are set (temporary this time)
  285. #
  286. send "info break\n"
  287. expect {
  288.     -re "Num Type.*Disp Enb Address.*What.*\
  289. \[0-9\]+\[\t \]+breakpoint     del.*y.*in main at .*$srcfile:56.*\
  290. \[0-9\]+\[\t \]+breakpoint     del.*y.*in factorial at .*$srcfile:72.*\
  291. \[0-9\]+\[\t \]+breakpoint     del.*y.*in main at .*$srcfile:60.*\
  292. \[0-9\]+\[\t \]+breakpoint     del.*y.*in main at .*$srcfile:66.*$prompt $" { pass "Temporary breakpoint info" }
  293.     -re ".*$prompt $"   { fail "Temporary breakpoint info" }
  294.     timeout        { fail "(timeout) Temporary breakpoint info" }
  295. }
  296.  
  297.  
  298. #
  299. # Test "next" over recursive function call.
  300. # FIXME:  Gdb currently has problems with this.
  301. #
  302.  
  303. proc test_next_with_recursion {} { 
  304.    global prompt
  305.    global decimal
  306.  
  307.     send "kill\n"
  308.     expect {
  309.     -re ".*Kill the program being debugged\? \(y or n\) $" {
  310.         send "y\n"
  311.         continue -expect
  312.     }
  313.     -re ".*$prompt $" {}
  314.     timeout { fail "killing inferior" ; return }
  315.     }
  316.  
  317.     if [istarget "a29k-*-udi"] then {
  318.     # FIXME: If PR 2415 is fixed, this is not needed.
  319.     gdb_target_udi
  320.     gdb_load $objdir/$subdir/$binfile
  321.     }
  322.  
  323.     delete_breakpoints
  324.  
  325.     send "break factorial\n"
  326.     expect {
  327.     -re "Breakpoint $decimal at .*$prompt" {}
  328.     timeout { fail "break at factorial" ; return }
  329.     }
  330.  
  331.     # Run until we call factorial with 6
  332.  
  333.     if [istarget "*-*-vxworks"] then {
  334.     send "run vxmain \"6\"\n"
  335.     } else {
  336.     if [istarget "a29k-*-udi"] then {
  337.         send "run gdbme 6\n"
  338.     } else {
  339.         send "run 6\n"
  340.     }
  341.     }
  342.     expect {
  343.     -re "Starting .*Break.* factorial \(value=6\) .*$prompt $" {}
  344.     timeout { fail "run to factorial(6)" ; return }
  345.     }
  346.  
  347.     # Continue until we call factorial recursively with 5.
  348.  
  349.     send "continue\n"
  350.     expect {
  351.     -re "Continuing.*Break.* factorial \(value=5\) .*$prompt $" {}
  352.     timeout { fail "continue to factorial(5)" ; return }
  353.     }
  354.  
  355.     # Do a backtrace just to confirm how many levels deep we are.
  356.  
  357.     set result [gdb_test "backtrace" \
  358.             "#0\[ \t\]+ factorial \(value=5\)" \
  359.             "backtrace from factorial(5)"]
  360.     if $result!=0 then { return }
  361.  
  362.     # Now a "next" should position us at the recursive call, which
  363.     # we will be performing with 4.
  364.  
  365.     send "next\n"
  366.     expect {
  367.     -re ".* factorial \(value - 1\);.*$prompt $" {}
  368.     timeout { fail "next to recursive call (timeout)" ; return }
  369.     }
  370.  
  371.     # Disable the breakpoint at the entry to factorial by deleting them all.
  372.     # The "next" should run until we return to the next line from this
  373.     # recursive call to factorial with 4.
  374.     # Buggy versions of gdb will stop instead at the innermost frame on
  375.     # the line where we are trying to "next" to.
  376.  
  377.     delete_breakpoints
  378.  
  379.     setup_xfail "*-*-*"
  380.     send "next\n"
  381.     expect {
  382.     -re "factorial \(value=5\) .* return \(value\);.*$prompt $" {
  383.         pass "next over recursive call"
  384.     }
  385.     -re "factorial \(value=2\) .* return \(value\);.*$prompt $" {
  386.         fail "next over recursive call" ; return
  387.     }
  388.     timeout { fail "next over recursive call (timeout)" ; return }
  389.     }
  390.  
  391.     # OK, we should be back in the same stack frame we started from.
  392.     # Do a backtrace just to confirm.
  393.  
  394.     set result [gdb_test "backtrace" \
  395.              "#0\[ \t\]+ factorial \(value=5\)" \
  396.              "backtrace from factorial(5)"]
  397.     if $result!=0 then { return }
  398.  
  399.     # Continue until we exit.  Should not stop again.
  400.     gdb_test "continue" "720\r\nContinuing.\r\n"\
  401.         "continue until exit in recursive next test"
  402. }
  403.  
  404. test_next_with_recursion
  405.  
  406. # Reset the default arguments for VxWorks
  407. if [istarget "*-*-vxworks"] then {
  408.     set timeout 10
  409.     send "set args main\n"
  410.     expect -re ".*$prompt $" {}
  411. }
  412.  
  413. if [istarget "a29k-*-udi"] then {
  414.     # FIXME: If PR 2415 is fixed, this is not needed.
  415.     gdb_target_udi
  416. }
  417.