From: Pedro Alves <palves@redhat.com>
To: Simon Marchi <simon.marchi@polymtl.ca>
Cc: Andrew Burgess <andrew.burgess@embecosm.com>, gdb-patches@sourceware.org
Subject: Re: [PATCH] gdb/testsuite/sim: Remove redundant setting of timeout
Date: Tue, 04 Dec 2018 16:11:00 -0000 [thread overview]
Message-ID: <b5f43265-30a1-aa36-e0ef-06983238317c@redhat.com> (raw)
In-Reply-To: <37e9f834bac94720a257148d45bd0325@polymtl.ca>
On 12/04/2018 04:08 PM, Simon Marchi wrote:
> On 2018-12-04 10:54, Pedro Alves wrote:
>> On 12/04/2018 03:43 PM, Simon Marchi wrote:
>>> On 2018-12-04 06:33, Andrew Burgess wrote:
>>>> In the config/sim.exp file two functions are defined. Both of these
>>>> functions define local timeout variables and then call gdb_expect,
>>>> which (through a call to get_largest_timeout) will find the local
>>>> definition of timeout.
>>>>
>>>> However, both of these functions set the local timeout to some
>>>> arbitrary value and print a log message for this "new" timeout just
>>>> before returning.
>>>>
>>>> As in both cases, the timeout is a local variable, this final setting
>>>> of the timeout has no effect and can be removed.
>>>
>>> Hi Andrew,
>>>
>>> Can you verify whether the remaining "set timeout" in those functions have any effect at all? As you said, they are just local variables, so I don't expect them to influence the behavior of gdb_expect. Either we need "global timeout", or we pass the timeout directly as an argument to gdb_expect (the latter sounds better).
>>
>> Keep this in mind, from man expect:
>>
>>       Expect takes a rather liberal view of scoping. In particular,
>> Â Â Â Â Â Â variables read by commands specific to the Expect program will be sought
>>       first from the local scope, and if not found, in the global scope. For
>> Â Â Â Â Â Â example, this obviates the need to place "global timeout" in
>> every procedure
>>       you write that uses expect.  On the other hand, variables
>> written are always
>>       in the local scope (unless a "global" command has been issued). The most
>> Â Â Â Â Â Â common problem this causes is when spawn is executed in a
>> procedure. Outside
>> Â Â Â Â Â Â the procedure, spawn_id no longer exists, so the spawned
>> process is no longer
>>       accessible simply because of scoping. Add a "global spawn_id"
>> to such a procedure.
>>
>>
>> Mimicking that behavior, gdb_test, gdb_test_multiple and gdb_expect pick the
>> local timeout variable in the caller via upvar. E.g.:
>>
>> proc gdb_test { args } {
>> Â Â Â global gdb_prompt
>> Â Â Â upvar timeout timeout
>>
>> gdb_expect is a little more disguised, but it does the same, here,
>> in the get_largest_timeout path:
>>
>> proc gdb_expect { args } {
>> ...
>> Â Â Â # A timeout argument takes precedence, otherwise of all the timeouts
>> Â Â Â # select the largest.
>> Â Â Â if [info exists atimeout] {
>> Â Â Â Â set tmt $atimeout
>> Â Â Â } else {
>> Â Â Â Â set tmt [get_largest_timeout]
>> Â Â Â }
>> ...
>> }
>>
>> and then get_largest_timeout does:
>>
>> proc get_largest_timeout {} {
>> Â Â Â upvar #0 timeout gtimeout
>> Â Â Â upvar 2 timeout timeout
>> Â Â Â ^^^^^^^^^^^^^^^^^^^^^^^
>> Â Â Â ...
>
> That's very confusing, to say the least.
Don't shoot the messenger. :-)
Thanks,
Pedro Alves
next prev parent reply other threads:[~2018-12-04 16:11 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-12-04 11:33 Andrew Burgess
2018-12-04 15:43 ` Simon Marchi
2018-12-04 15:54 ` Pedro Alves
2018-12-04 16:08 ` Simon Marchi
2018-12-04 16:11 ` Pedro Alves [this message]
2018-12-04 16:15 ` Simon Marchi
2018-12-04 16:33 ` Pedro Alves
2018-12-04 21:34 ` Andrew Burgess
2018-12-04 23:03 ` Pedro Alves
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=b5f43265-30a1-aa36-e0ef-06983238317c@redhat.com \
--to=palves@redhat.com \
--cc=andrew.burgess@embecosm.com \
--cc=gdb-patches@sourceware.org \
--cc=simon.marchi@polymtl.ca \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox