From 4081c0f1222810746068579c6fbbcd8a9b59cbb8 Mon Sep 17 00:00:00 2001 From: Yao Qi Date: Fri, 30 Oct 2015 15:51:33 +0000 Subject: [PATCH] Simplify gdb.threads/wp-replication.exp on counting HW watchpoints Nowadays, test gdb.threads/wp-replication.exp uses a while loop to repeatedly insert HW watchpoint, resume and check no error message coming out, in order to count HW watchpoints There are some drawbacks in this way, - the loop could be endless. I think this is use to making trouble to S/390, since we had such comment # Some targets (like S/390) behave as though supporting # unlimited hardware watchpoints. In this case we just take a # safe exit out of the loop. I hit this today too because a GDB internal error is triggered on "continue" in the loop, and $done is 0 invariantly, so the loop can't end. - the code counting hardware watchpoint is too complicated. We can use "set breakpoint always-inserted on" to get the result of inserting HW watchpoint without resuming the inferior. In this way, watch_count_done and empty_cycle in c file is no longer needed. In this patch, I change to use "set breakpoint always-inserted on" trick, and only iterate $NR_THREADS times, to count the HW watchpoint. In this way, the loop can't be endless, and GDB doesn't need to resume the inferior. gdb/testsuite: 2015-10-30 Yao Qi * gdb.threads/wp-replication.c (watch_count_done): Remove. (empty_cycle): Remove. (main): Don't call empty_cycle. Don't use watch_count_done. * gdb.threads/wp-replication.exp: Don't set breakpoint on empty_cycle. Rewrite the code counting HW watchpoints. --- gdb/testsuite/ChangeLog | 8 +++ gdb/testsuite/gdb.threads/wp-replication.c | 24 --------- gdb/testsuite/gdb.threads/wp-replication.exp | 76 ++++++++++------------------ 3 files changed, 36 insertions(+), 72 deletions(-) diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog index 45641e2..e01ee86 100644 --- a/gdb/testsuite/ChangeLog +++ b/gdb/testsuite/ChangeLog @@ -1,3 +1,11 @@ +2015-10-30 Yao Qi + + * gdb.threads/wp-replication.c (watch_count_done): Remove. + (empty_cycle): Remove. + (main): Don't call empty_cycle. Don't use watch_count_done. + * gdb.threads/wp-replication.exp: Don't set breakpoint on + empty_cycle. Rewrite the code counting HW watchpoints. + 2015-10-30 Marcin Kościelnicki * gdb.reverse/fstatat-reverse.c: New test. diff --git a/gdb/testsuite/gdb.threads/wp-replication.c b/gdb/testsuite/gdb.threads/wp-replication.c index a7250b0..9fdc87a 100644 --- a/gdb/testsuite/gdb.threads/wp-replication.c +++ b/gdb/testsuite/gdb.threads/wp-replication.c @@ -47,11 +47,6 @@ int test_ready = 0; watchpoint triggers. */ int can_terminate = 0; -/* Used to push the program out of the waiting loop after the - testcase is done counting the number of hardware watchpoints - available for our target. */ -int watch_count_done = 0; - /* Number of watchpoints GDB is capable of using (this is provided by GDB during the test run). */ int hw_watch_count = 0; @@ -60,14 +55,6 @@ int hw_watch_count = 0; static int watched_data[NR_THREADS]; pthread_mutex_t data_mutex; -/* Wait function to keep threads busy while the testcase does - what it needs to do. */ -void -empty_cycle (void) -{ - usleep (1); -} - int main () { @@ -75,17 +62,6 @@ main () pthread_t threads[NR_THREADS]; int i; - /* Something to ensure that the breakpoint used to run to main - is only hit once. */ - empty_cycle (); - - while (watch_count_done == 0) - { - /* GDB will modify the value of "watch_count_done" at runtime and we - will get past this point. */ - empty_cycle (); - } - pthread_mutex_init (&data_mutex, NULL); for (i = 0; i < NR_THREADS; i++) diff --git a/gdb/testsuite/gdb.threads/wp-replication.exp b/gdb/testsuite/gdb.threads/wp-replication.exp index ebfc332..9de27b2 100644 --- a/gdb/testsuite/gdb.threads/wp-replication.exp +++ b/gdb/testsuite/gdb.threads/wp-replication.exp @@ -47,56 +47,41 @@ if ![runto_main] then { return 0 } -# First, break at empty_cycle. -gdb_test "break empty_cycle" \ - "Breakpoint 2 at .*: file .*${srcfile}, line .*" \ - "Breakpoint on empty_cycle" - # Set some default values. set hwatch_count 0 -set done 0 +set count 0 # Count the number of hardware watchpoints available on # this target. -while { $done == 0 } { - - gdb_test "continue" \ - ".*Breakpoint 2, empty_cycle \\(\\) at .*${srcfile}.*" \ - "Continue to empty_cycle to insert watchpoint $hwatch_count" - - # Some targets do resource counting as we insert watchpoints. - # Such targets won't cause a watchpoint insertion failure, but - # will switch to software watchpoints silently. We check for - # both cases here. - gdb_test_multiple "watch watched_data\[$hwatch_count\]" \ - "watch watched_data\[$hwatch_count\]" { - -re "Hardware watchpoint .*$gdb_prompt $" { - } - -re "Watchpoint .*$gdb_prompt $" { - set done 1 - break - } - } - - gdb_test_multiple "continue" "watchpoint created successfully" { - -re ".*Breakpoint 2, empty_cycle \\(\\).*$gdb_prompt $" { - incr hwatch_count - - # Some targets (like S/390) behave as though supporting - # unlimited hardware watchpoints. In this case we just take a - # safe exit out of the loop. - if { $hwatch_count == $NR_THREADS } { - set done 1 - break - } - } - -re ".*Could not insert hardware watchpoint.*$gdb_prompt $" { - set done 1 - break - } - } + +# So we get an immediate warning/error if the target doesn't support a +# hardware watchpoint or run out of hardware resource. +gdb_test_no_output "set breakpoint always-inserted on" + +while { $count < $NR_THREADS } { + # Some targets do resource counting as we insert watchpoints. + # Such targets won't cause a watchpoint insertion failure, but + # will switch to software watchpoints silently. We check for + # both cases here. + gdb_test_multiple "watch watched_data\[$hwatch_count\]" \ + "watch watched_data\[$hwatch_count\]" { + -re ".*Could not insert hardware watchpoint.*$gdb_prompt $" { + # End the loop. + set count $NR_THREADS + } + -re "Hardware watchpoint .*$gdb_prompt $" { + incr hwatch_count + } + -re "Watchpoint .*$gdb_prompt $" { + # End the loop. + set count $NR_THREADS + } + } + incr count } +gdb_test_no_output "set breakpoint always-inserted off" + # Target cannot insert hardware watchpoints. It should have reported # (through board settings) that it did not support them in the first place. # Just exit. @@ -114,11 +99,6 @@ gdb_test_no_output "set var hw_watch_count=${hwatch_count}" \ # the target supports. Use that to do further testing. delete_breakpoints -# Break out of the empty_cycle loop by changing the -# controlling variable. -gdb_test_no_output "set var watch_count_done=1" \ - "set var watch_count_done=1" - # Prepare to create all the threads. gdb_test "break thread_started" \ "Breakpoint \[0-9\]+ at .*: file .*${srcfile}, line .*" \ -- 2.7.4