This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] gdb.threads/thread-specific.exp: Fix uninitialized variable references


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
Index: gdb-fsf-trunk-quilt/gdb/testsuite/gdb.threads/thread-specific.exp
===================================================================
--- gdb-fsf-trunk-quilt.orig/gdb/testsuite/gdb.threads/thread-specific.exp	2014-03-18 19:00:40.000000000 +0000
+++ gdb-fsf-trunk-quilt/gdb/testsuite/gdb.threads/thread-specific.exp	2014-03-20 23:48:55.277523035 +0000
@@ -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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]