Index: attach.c =================================================================== RCS file: /cvs/src/src/gdb/testsuite/gdb.base/attach.c,v retrieving revision 1.1.1.1 diff -u -p -r1.1.1.1 attach.c --- attach.c 28 Jun 1999 23:02:40 -0000 1.1.1.1 +++ attach.c 20 Nov 2003 06:17:45 -0000 @@ -5,15 +5,28 @@ exit unless/until gdb sets the variable to non-zero.) */ #include +#include int should_exit = 0; +/* Wait for 0.1 sec. */ + +void +small_delay () +{ + const struct timespec ts = { 0, 1000000 }; /* 0.1 sec */ + nanosleep (&ts, NULL); +} + int main () { int local_i = 0; while (! should_exit) { + /* Insert a small delay in order to avoid consuming all the CPU + while waiting for the debugger to take control. */ + small_delay (); local_i++; } return 0; Index: attach.exp =================================================================== RCS file: /cvs/src/src/gdb/testsuite/gdb.base/attach.exp,v retrieving revision 1.12 diff -u -p -r1.12 attach.exp --- attach.exp 7 Aug 2003 17:55:41 -0000 1.12 +++ attach.exp 20 Nov 2003 06:17:45 -0000 @@ -173,12 +173,16 @@ proc do_attach_tests {} { send_gdb "attach $testpid\n" gdb_expect { - -re "Attaching to program.*`?$escapedbinfile'?, process $testpid.*main.*at .*$srcfile:.*$gdb_prompt $"\ + -re "Attaching to program.*`?$escapedbinfile'?, process $testpid.*$gdb_prompt $"\ {pass "attach1, after setting file"} -re "$gdb_prompt $" {fail "attach1, after setting file"} timeout {fail "(timeout) attach1, after setting file"} } + gdb_test "backtrace" \ + ".*in nanosleep ().*in small_delay ().*in main ().*" \ + "backtrace after attach1" + # Verify that we can "see" the variable "should_exit" in the # program, and that it is zero. # @@ -236,12 +240,16 @@ proc do_attach_tests {} { # send_gdb "attach $testpid\n" gdb_expect { - -re "Attaching to process $testpid.*Reading symbols from $escapedbinfile.*main.*at .*$gdb_prompt $"\ + -re "Attaching to process $testpid.*Reading symbols from $escapedbinfile.*$gdb_prompt $"\ {pass "attach2"} -re "$gdb_prompt $" {fail "attach2"} timeout {fail "(timeout) attach2"} } + gdb_test "backtrace" \ + ".*in nanosleep ().*in small_delay ().*in main ().*" \ + "backtrace after attach2" + # Verify that we can modify the variable "should_exit" in the # program. # @@ -253,16 +261,16 @@ proc do_attach_tests {} { # Verify that the modification really happened. # - send_gdb "tbreak 19\n" + send_gdb "tbreak 32\n" gdb_expect { - -re "Breakpoint .*at.*$srcfile, line 19.*$gdb_prompt $"\ + -re "Breakpoint .*at.*$srcfile, line 32.*$gdb_prompt $"\ {pass "after attach2, set tbreak postloop"} -re "$gdb_prompt $" {fail "after attach2, set tbreak postloop"} timeout {fail "(timeout) after attach2, set tbreak postloop"} } send_gdb "continue\n" gdb_expect { - -re "main.*at.*$srcfile:19.*$gdb_prompt $"\ + -re "main.*at.*$srcfile:32.*$gdb_prompt $"\ {pass "after attach2, reach tbreak postloop"} -re "$gdb_prompt $" {fail "after attach2, reach tbreak postloop"} timeout {fail "(timeout) after attach2, reach tbreak postloop"} @@ -337,11 +345,15 @@ proc do_attach_tests {} { send_gdb "attach $testpid\n" gdb_expect { - -re "Attaching to process $testpid.*Reading symbols from $escapedbinfile.*main.*at .*$gdb_prompt $"\ + -re "Attaching to process $testpid.*Reading symbols from $escapedbinfile.*$gdb_prompt $"\ {pass "attach when process' a.out not in cwd"} -re "$gdb_prompt $" {fail "attach when process' a.out not in cwd"} timeout {fail "(timeout) attach when process' a.out not in cwd"} } + + gdb_test "backtrace" \ + ".*in nanosleep ().*in small_delay ().*in main ().*" \ + "backtrace after attach when process' a.out not in cwd" send_gdb "kill\n" gdb_expect {