📄 break.exp
字号:
timeout {fail "(timeout) info silent break 79"}}send_gdb "continue\n"gdb_expect { -re "Continuing.\r\n$gdb_prompt $"\ {pass "hit silent break 79"} -re "$gdb_prompt $"\ {fail "hit silent break 79"} timeout {fail "(timeout) hit silent break 79"}}send_gdb "bt\n"gdb_expect { -re "#0 main .* at .*:79.*$gdb_prompt $"\ {pass "stopped for silent break 79"} -re "$gdb_prompt $"\ {fail "stopped for silent break 79"} timeout {fail "(timeout) stopped for silent break 79"}}# Verify that GDB can at least parse a breakpoint with the# "thread" keyword. (We won't attempt to test here that a# thread-specific breakpoint really triggers appropriately.# The gdb.threads subdirectory contains tests for that.)#send_gdb "break 80 thread 999\n"gdb_expect { -re "Unknown thread 999.*$gdb_prompt $"\ {pass "thread-specific breakpoint on non-existent thread disallowed"} -re "$gdb_prompt $"\ {fail "thread-specific breakpoint on non-existent thread disallowed"} timeout {fail "(timeout) thread-specific breakpoint on non-existent thread disallowed"}}send_gdb "break 80 thread foo\n"gdb_expect { -re "Junk after thread keyword..*$gdb_prompt $"\ {pass "thread-specific breakpoint on bogus thread ID disallowed"} -re "$gdb_prompt $"\ {fail "thread-specific breakpoint on bogus thread ID disallowed"} timeout {fail "(timeout) thread-specific breakpoint on bogus thread ID disallowed"}}# Verify that GDB responds gracefully to a breakpoint command with# trailing garbage.#send_gdb "break 80 foo\n"gdb_expect { -re "Junk at end of arguments..*$gdb_prompt $"\ {pass "breakpoint with trailing garbage disallowed"} -re "$gdb_prompt $"\ {fail "breakpoint with trailing garbage disallowed"} timeout {fail "(timeout) breakpoint with trailing garbage disallowed"}}# Verify that GDB responds gracefully to a "clear" command that has# no matching breakpoint. (First, get us off the current source line,# which we know has a breakpoint.)#send_gdb "next\n"gdb_expect { -re ".*$gdb_prompt $"\ {pass "step over breakpoint"} timeout {fail "(timeout) step over breakpoint"}}send_gdb "clear 81\n"gdb_expect { -re "No breakpoint at 81..*$gdb_prompt $"\ {pass "clear line has no breakpoint disallowed"} -re "$gdb_prompt $"\ {fail "clear line has no breakpoint disallowed"} timeout {fail "(timeout) clear line has no breakpoint disallowed"}}send_gdb "clear\n"gdb_expect { -re "No breakpoint at this line..*$gdb_prompt $"\ {pass "clear current line has no breakpoint disallowed"} -re "$gdb_prompt $"\ {fail "clear current line has no breakpoint disallowed"} timeout {fail "(timeout) clear current line has no breakpoint disallowed"}}# Verify that a breakpoint can be set via a convenience variable.#send_gdb "set \$foo=81\n"gdb_expect { -re "$gdb_prompt $"\ {pass "set convenience variable \$foo to 81"} timeout {fail "(timeout) set convenience variable \$foo to 81"}}send_gdb "break \$foo\n"gdb_expect { -re "Breakpoint (\[0-9\]*) at .*, line 81.*$gdb_prompt $"\ {pass "set breakpoint via convenience variable"} -re "$gdb_prompt $"\ {fail "set breakpoint via convenience variable"} timeout {fail "(timeout) set breakpoint via convenience variable"}}# Verify that GDB responds gracefully to an attempt to set a# breakpoint via a convenience variable whose type is not integer.#send_gdb "set \$foo=81.5\n"gdb_expect { -re "$gdb_prompt $"\ {pass "set convenience variable \$foo to 81.5"} timeout {fail "(timeout) set convenience variable \$foo to 81.5"}}send_gdb "break \$foo\n"gdb_expect { -re "Convenience variables used in line specs must have integer values..*$gdb_prompt $"\ {pass "set breakpoint via non-integer convenience variable disallowed"} -re "$gdb_prompt $"\ {fail "set breakpoint via non-integer convenience variable disallowed"} timeout {fail "(timeout) set breakpoint via non-integer convenience variable disallowed"}}# Verify that we can set and trigger a breakpoint in a user-called function.#send_gdb "break marker2\n"gdb_expect { -re "Breakpoint (\[0-9\]*) at .*, line 4\[49\].*$gdb_prompt $"\ {pass "set breakpoint on to-be-called function"} -re "$gdb_prompt $"\ {fail "set breakpoint on to-be-called function"} timeout {fail "(timeout) set breakpoint on to-be-called function"}}send_gdb "print marker2(99)\n"gdb_expect { -re "The program being debugged stopped while in a function called from GDB.\r\nWhen the function .marker2$proto. is done executing, GDB will silently\r\nstop .instead of continuing to evaluate the expression containing\r\nthe function call...*$gdb_prompt $"\ {pass "hit breakpoint on called function"} -re "$gdb_prompt $"\ {fail "hit breakpoint on called function"} timeout {fail "(timeout) hit breakpoint on called function"}}# As long as we're stopped (breakpointed) in a called function,# verify that we can successfully backtrace & such from here.#if [istarget "hppa*-*-hpux*"] then { send_gdb "bt\n" gdb_expect { -re "#0\[ \t\]*$hex in marker2.*:4\[49\]\r\n#1.*_sr4export.*$gdb_prompt $"\ {pass "backtrace while in called function"} -re "#0\[ \t\]*$hex in marker2.*:4\[49\]\r\n#1.*function called from gdb.*$gdb_prompt $"\ {pass "backtrace while in called function"} -re "$gdb_prompt $"\ {fail "backtrace while in called function"} timeout {fail "(timeout) backtrace while in called function"} } send_gdb "finish\n" gdb_expect { -re "Run till exit from .*marker2.* at .*4\[49\]\r\n.* in _sr4export.*$gdb_prompt $"\ {pass "finish from called function"} -re "Run till exit from .*marker2.* at .*4\[49\]\r\n.*function called from gdb.*$gdb_prompt $"\ {pass "finish from called function"} -re "Run till exit from .*marker2.* at .*4\[49\]\r\n.*Value returned.*$gdb_prompt $"\ {pass "finish from called function"} -re "$gdb_prompt $"\ {fail "finish from called function"} timeout {fail "(timeout) finish from called function"} }}# Verify that GDB responds gracefully to a "finish" command with# arguments.#if ![runto_main] then { fail "break tests suppressed" }send_gdb "finish 123\n"gdb_expect { -re "The \"finish\" command does not take any arguments.\r\n$gdb_prompt $"\ {pass "finish with arguments disallowed"} -re "$gdb_prompt $"\ {fail "finish with arguments disallowed"} timeout {fail "(timeout) finish with arguments disallowed"}}# Verify that GDB responds gracefully to a request to "finish" from# the outermost frame. On a stub that never exits, this will just# run to the stubs routine, so we don't get this error... Thus the # second condition.#send_gdb "finish\n"gdb_expect { -re "\"finish\" not meaningful in the outermost frame.\r\n$gdb_prompt $"\ {pass "finish from outermost frame disallowed"} -re "Run till exit from.*\r\n$gdb_prompt $" { pass "finish from outermost frame disallowed" } -re "$gdb_prompt $"\ {fail "finish from outermost frame disallowed"} timeout {fail "(timeout) finish from outermost frame disallowed"}}# Verify that we can explicitly ask GDB to stop on all shared library# events, and that it does so.#if [istarget "hppa*-*-hpux*"] then { if ![runto_main] then { fail "break tests suppressed" } send_gdb "set stop-on-solib-events 1\n" gdb_expect { -re "$gdb_prompt $"\ {pass "set stop-on-solib-events"} timeout {fail "(timeout) set stop-on-solib-events"} } send_gdb "run\n" gdb_expect { -re ".*Start it from the beginning.*y or n. $"\ {send_gdb "y\n" gdb_expect { -re ".*Stopped due to shared library event.*$gdb_prompt $"\ {pass "triggered stop-on-solib-events"} -re "$gdb_prompt $"\ {fail "triggered stop-on-solib-events"} timeout {fail "(timeout) triggered stop-on-solib-events"} } } -re "$gdb_prompt $"\ {fail "rerun for stop-on-solib-events"} timeout {fail "(timeout) rerun for stop-on-solib-events"} } send_gdb "set stop-on-solib-events 0\n" gdb_expect { -re "$gdb_prompt $"\ {pass "reset stop-on-solib-events"} timeout {fail "(timeout) reset stop-on-solib-events"} }}# Hardware breakpoints are unsupported on HP-UX. Verify that GDB# gracefully responds to requests to create them.#if [istarget "hppa*-*-hpux*"] then { if ![runto_main] then { fail "break tests suppressed" } send_gdb "hbreak\n" gdb_expect { -re "No hardware breakpoint support in the target.*$gdb_prompt $"\ {pass "hw breaks disallowed"} -re "$gdb_prompt $"\ {fail "hw breaks disallowed"} timeout {fail "(timeout) hw breaks disallowed"} } send_gdb "thbreak\n" gdb_expect { -re "No hardware breakpoint support in the target.*$gdb_prompt $"\ {pass "temporary hw breaks disallowed"} -re "$gdb_prompt $"\ {fail "temporary hw breaks disallowed"} timeout {fail "(timeout) temporary hw breaks disallowed"} }}#********proc test_clear_command {} { gdb_test "break main" "Breakpoint.*at.*" "break main #1" gdb_test "break main" "Breakpoint.*at.*" "break main #2" # We don't test that it deletes the correct breakpoints. We do at # least test that it deletes more than one breakpoint. gdb_test "clear main" {Deleted breakpoints [0-9]+ [0-9]+.*}}## Test "next" over recursive function call.#proc test_next_with_recursion {} { global gdb_prompt global decimal global binfile if [target_info exists use_gdb_stub] { # Reload the program. delete_breakpoints gdb_load ${binfile}; } else { # FIXME: should be using runto gdb_test "kill" "" "kill program" "Kill the program being debugged.*y or n. $" "y" delete_breakpoints } gdb_test "break factorial" "Breakpoint $decimal at .*" "break at factorial" # Run until we call factorial with 6 if [istarget "*-*-vxworks*"] then { send_gdb "run vxmain \"6\"\n" } else { gdb_run_cmd } gdb_expect { -re "Break.* factorial .value=6. .*$gdb_prompt $" {} -re ".*$gdb_prompt $" { fail "run to factorial(6)"; gdb_suppress_tests; } timeout { fail "run to factorial(6) (timeout)" ; gdb_suppress_tests } } # Continue until we call factorial recursively with 5. if [gdb_test "continue" \ "Continuing.*Break.* factorial .value=5. .*" \ "continue to factorial(5)"] then { gdb_suppress_tests } # Do a backtrace just to confirm how many levels deep we are. if [gdb_test "backtrace" \ "#0\[ \t\]+ factorial .value=5..*" \ "backtrace from factorial(5)"] then { gdb_suppress_tests } # Now a "next" should position us at the recursive call, which # we will be performing with 4. if [gdb_test "next" \ ".* factorial .value - 1.;.*" \ "next to recursive call"] then { gdb_suppress_tests } # Disable the breakpoint at the entry to factorial by deleting them all. # The "next" should run until we return to the next line from this # recursive call to factorial with 4. # Buggy versions of gdb will stop instead at the innermost frame on # the line where we are trying to "next" to. delete_breakpoints if [istarget "mips*tx39-*"] { set timeout 60 } else { set timeout 20 } gdb_test next "\[0-9\]*\[\t \]+return \\(value\\);.*" \ "next over recursive call" # OK, we should be back in the same stack frame we started from. # Do a backtrace just to confirm. set result [gdb_test "backtrace" \ "#0\[ \t\]+ factorial .value=120.*\r\n#1\[ \t\]+ \[0-9a-fx\]+ in factorial .value=6..*" \ "backtrace from factorial(5.1)"] if { $result != 0 } { gdb_suppress_tests } if [target_info exists gdb,noresults] { gdb_suppress_tests } gdb_continue_to_end "recursive next test" gdb_stop_suppressing_tests;}test_clear_commandtest_next_with_recursion#********# build a new file with optimization enabled so that we can try breakpoints# on targets with optimized prologuesset binfileo2 ${objdir}/${subdir}/${testfile}o2if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfileo2}" executable {debug additional_flags="-O2" }] != "" } { gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."}if [get_compiler_info ${binfileo2}] { return -1}gdb_exitgdb_startgdb_reinitialize_dir $srcdir/$subdirgdb_load ${binfileo2}if [target_info exists gdb_stub] { gdb_step_for_stub;}## test break at function#gdb_test "break main" \ "Breakpoint.*at.* file .*$srcfile, line.*" \ "breakpoint function, optimized file"## test break at function#gdb_test "break marker4" \ "Breakpoint.*at.* file .*$srcfile, line.*" \ "breakpoint small function, optimized file"## run until the breakpoint at main is hit. For non-stubs-using targets.#if ![target_info exists use_gdb_stub] { if [istarget "*-*-vxworks*"] then { send_gdb "run vxmain \"2\"\n" set timeout 120 verbose "Timeout is now $timeout seconds" 2 } else { send_gdb "run\n" } gdb_expect { -re "The program .* has been started already.*y or n. $" { send_gdb "y\n" exp_continue } -re "Starting program.*Breakpoint \[0-9\]+,.*main .*argc.*argv.* at .*$srcfile:75.*75\[\t \]+if .argc.* \{.*$gdb_prompt $"\ { pass "run until function breakpoint, optimized file" } -re ".*$gdb_prompt $" { fail "run until function breakpoint, optimized file" } timeout { fail "run until function breakpoint, optimized file (timeout)" } }} else { if ![target_info exists gdb_stub] { gdb_test continue ".*Continuing\\..*Breakpoint \[0-9\]+, main \\(argc=.*, argv=.*, envp=.*\\) at .*$srcfile:75.*75\[\t \]+if .argc.*\{.*" "stub continue, optimized file" }}## run until the breakpoint at a small function#gdb_test continue "Continuing\\..*Breakpoint \[0-9\]+, marker4 \\(d=177601976\\) at .*$srcfile:51.*51\[\t \]+void.*marker4.*" \ "run until breakpoint set at small function, optimized file"# Reset the default arguments for VxWorksif [istarget "*-*-vxworks*"] { set timeout 10 verbose "Timeout is now $timeout seconds" 2 send_gdb "set args main\n" gdb_expect -re ".*$gdb_prompt $" {}}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -