bug-dejagnu
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Bug-dejagnu] [PATCH] remote_expect: Pass "break" and "continue" excepti


From: Maciej W. Rozycki
Subject: [Bug-dejagnu] [PATCH] remote_expect: Pass "break" and "continue" exceptions up
Date: Wed, 6 Oct 2010 13:21:27 +0100 (BST)
User-agent: Alpine 1.10 (DEB 962 2008-03-14)

Hi,

 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.

 Comments?

2010-10-06  Maciej W. Rozycki  <address@hidden>

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

  Maciej

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
     }
 }



reply via email to

[Prev in Thread] Current Thread [Next in Thread]