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]

[PATCH] testsuite: Pass "break" and "continue" exceptions up


Hi,

 This is a change to gdb_expect and gdb_test_multi that follows up my 
recent update to DejaGNU's remote_expect that was accepted upstream and 
now released in version 1.5.  Here's my original explanation -- that 
applies to gdb_expect and gdb_test_multi just as it did to remote_expect:

 'In the GDB testsuite there are several places where gdb_expect (that 
expands to remote_expect) is called with "break" and "continue" commands 
used within to control the loop the procedure call is within.  The authors 
of these pieces must have been unaware these commands are ineffective, 
because remote_expect has this piece at the end:

	    set code [catch {uplevel $error_sect} string]
[...]
    if {$code == 1} {
	return -code error -errorinfo $errorInfo -errorcode $errorCode $string
    } elseif {$code == 2} {
	return -code return $string
    } elseif {$code == 3} {
	return
    } elseif {$code > 4} {
	return -code $code $string
    }

As you can see error codes #3 and #4 that correspond to the "break" and 
"continue" exceptions respectively are not passed through and are treated 
as if the procedure exited with the "return" command and by reaching its 
end respectively.  The end result is that a piece of code like this:

for {set i 1} {$i <= 10} {incr i} {
    remote_expect {
	"foo" {
	    puts foo
	    break
	}
	"bar" {
	    puts bar
	    continue
	}
    }
    puts "baz"
}

is treated effectively (barring any extra features remote_expect provides) 
like:

for {set i 1} {$i <= 10} {incr i} {
    expect {
	"foo" {
	    puts foo
	}
	"bar" {
	    puts bar
	}
    }
    puts "baz"
}

rather than:

for {set i 1} {$i <= 10} {incr i} {
    expect {
	"foo" {
	    puts foo
	    break
	}
	"bar" {
	    puts bar
	    continue
	}
    }
    puts "baz"
}

as one might (nomen omen) expect.

 'Documentation on remote_expect is vague, essentially all it says is: 
"[it] works basically the same as standard expect," which given the above 
is clearly untrue.  Historical records, such as ChangeLog entries did not 
provide any further insight, nor did a search of the Internet.

 'My proposal therefore is to simplify the return path from remote_expect 
and except from keeping the current special handling of the error 
exception intact, pass all the other conditions expect might have produced 
up to the caller.  Below is the proposed implementation.  It makes a loop 
like above behave as expected.

 'NB gdb_expect (from the GDB testsuite) will require a corresponding 
change as its return path clearly has been copied and pasted from here; 
I'll handle that separately if we agree on the change below.  The two 
changes did not cause any testsuite regressions in a randomly picked up 
GDB configuration.'

 So far the original justification, and now the patch itself.  I have 
included the change to DejaGNU for a reference below as well.

 I have tested this with the following targets mips-linux-gnu (natively), 
mips-sde-elf (remotely, with a simulator) and i386-linux-gnu (remotely, 
via gdbserver), no regressions.

 Comments?

2011-11-11  Maciej W. Rozycki  <macro@codesourcery.com>

	gdb/testsuite/
        * lib/gdb.exp (gdb_expect): Pass all the exception conditions up 
	to the caller.
	(gdb_test_multiple): Likewise.

  Maciej

gdb-test-tcl-exceptions.patch
Index: gdb-fsf-trunk-quilt/gdb/testsuite/lib/gdb.exp
===================================================================
--- gdb-fsf-trunk-quilt.orig/gdb/testsuite/lib/gdb.exp	2011-11-11 14:55:45.000000000 +0000
+++ gdb-fsf-trunk-quilt/gdb/testsuite/lib/gdb.exp	2011-11-11 18:08:46.935750892 +0000
@@ -844,11 +844,7 @@ proc gdb_test_multiple { command message
     if {$code == 1} {
 	global errorInfo errorCode;
 	return -code error -errorinfo $errorInfo -errorcode $errorCode $string
-    } elseif {$code == 2} {
-	return -code return $string
-    } elseif {$code == 3} {
-	return
-    } elseif {$code > 4} {
+    } elseif {$code > 1} {
 	return -code $code $string
     }
     return $result
@@ -2610,11 +2606,7 @@ proc gdb_expect { args } {
         global errorInfo errorCode;
 
 	return -code error -errorinfo $errorInfo -errorcode $errorCode $string
-    } elseif {$code == 2} {
-	return -code return $string
-    } elseif {$code == 3} {
-	return
-    } elseif {$code > 4} {
+    } else {
 	return -code $code $string
     }
 }

2010-10-06  Maciej W. Rozycki  <macro@codesourcery.com>

	* lib/remote.exp (remote_expect): Pass all the exception
	conditions up to the caller.

dejagnu-1.4.99-remote-expect-0.patch
diff --git a/lib/remote.exp b/lib/remote.exp
index abe8b20..8a26518 100644
--- a/lib/remote.exp
+++ b/lib/remote.exp
@@ -1256,11 +1256,7 @@ proc remote_expect { board timeout args } {
 
     if {$code == 1} {
 	return -code error -errorinfo $errorInfo -errorcode $errorCode $string
-    } elseif {$code == 2} {
-	return -code return $string
-    } elseif {$code == 3} {
-	return
-    } elseif {$code > 4} {
+    } else {
 	return -code $code $string
     }
 }


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