gdb.threads/thread-specific.exp: Fix uninitialized variable references
Commit Message
On Thu, 20 Mar 2014, Pedro Alves wrote:
> Thanks! Close, but needs a little tweak.
>
> Using "info exists" uses like this isn't safe, given that
> in a single dejagnu run that tests multiple .exp test files (like just
> plain "make check"), global variables set in previous test files leak
> into the current test file. So what we usually do instead is set
> the variable unconditionally upfront to some invalid value, and
> then compare against that value. E.g.:
>
> set this_breakpoint -1
> gdb_test_multiple "continue" "continue to thread-specific breakpoint" {
> -re "Breakpoint $main_breakpoint, .* at .*\r\n$gdb_prompt $" {
> fail "continue to thread-specific breakpoint (wrong breakpoint)"
> }
> -re "Breakpoint (\[0-9\]*), .* at .*\r\n$gdb_prompt $" {
> set this_breakpoint $expect_out(1,string)
> pass "continue to thread-specific breakpoint"
> }
> }
> if { $this_breakpoint == -1 } {
> untested ...
> } else {
> ...
> }
>
> Of course we could unset the variable instead of setting it
> to -1, using 'unset -nocomplain'. Same thing. Somehow I'm
> inclined to think that pattern is more prone to copy-paste
> forgetting to do the unset though, but I'd be fine with it.
OK, I'd prefer keeping the usual case first in the conditional though.
How about this version then? I have tested it on the failing system and
it still works.
2014-03-21 Maciej W. Rozycki <macro@codesourcery.com>
gdb/testsuite/
* gdb.threads/thread-specific.exp: Handle the lack of usable
$this_breakpoint and $this_thread.
Maciej
gdb-test-thread-specific-this-foo.diff
Comments
On 03/21/2014 12:03 AM, Maciej W. Rozycki wrote:
> 2014-03-21 Maciej W. Rozycki <macro@codesourcery.com>
>
> gdb/testsuite/
> * gdb.threads/thread-specific.exp: Handle the lack of usable
> $this_breakpoint and $this_thread.
OK. Thanks!
On Fri, 21 Mar 2014, Pedro Alves wrote:
> > gdb/testsuite/
> > * gdb.threads/thread-specific.exp: Handle the lack of usable
> > $this_breakpoint and $this_thread.
>
> OK. Thanks!
Applied, thanks.
Maciej
===================================================================
@@ -95,6 +95,7 @@ foreach thread [lrange $threads 1 end] {
gdb_breakpoint "$line thread $thread"
}
+set this_breakpoint -1
gdb_test_multiple "continue" "continue to thread-specific breakpoint" {
-re "Breakpoint $main_breakpoint, .* at .*\r\n$gdb_prompt $" {
fail "continue to thread-specific breakpoint (wrong breakpoint)"
@@ -105,13 +106,22 @@ gdb_test_multiple "continue" "continue t
}
}
-gdb_test_multiple "info breakpoint $this_breakpoint" "info on bp" {
- -re ".*stop only in thread (\[0-9\]*).*$gdb_prompt $" {
- set this_thread $expect_out(1,string)
- pass "found breakpoint for thread number"
+set this_thread -1
+if { $this_breakpoint != -1 } {
+ gdb_test_multiple "info breakpoint $this_breakpoint" "info on bp" {
+ -re ".*stop only in thread (\[0-9\]*).*$gdb_prompt $" {
+ set this_thread $expect_out(1,string)
+ pass "found breakpoint for thread number"
+ }
}
+} else {
+ untested "info on bp"
}
-gdb_test {print $_thread} ".* = $this_thread" "thread var at break"
+if { $this_thread != -1 } {
+ gdb_test {print $_thread} ".* = $this_thread" "thread var at break"
+} else {
+ untested "thread var at break"
+}
return 0