Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

is there a way to pause Tcl ?

1,654 views
Skip to first unread message

maura.m...@gmail.com

unread,
May 2, 2006, 4:53:32 PM5/2/06
to
I woder whether there exist a way to stop Tcl interpreter, read some
variable values and then resume the executaion ,,,
Thank you so much.
Maura

Gerry Snyder

unread,
May 2, 2006, 5:26:17 PM5/2/06
to

Look at the Tcl command vwait and see if that does what you want.


Gerry

Donal K. Fellows

unread,
May 2, 2006, 5:48:24 PM5/2/06
to
Maura Monville wrote:
>I woder whether there exist a way to stop Tcl interpreter, read some
>variable values and then resume the executaion

I'm sure there is, but what does "read some variable values" mean to
you? If we can get that straight, I just know we'll be able to help you
achieve satisfaction using one of the language's facilities.

Donal.

Uwe Klein

unread,
May 2, 2006, 5:59:56 PM5/2/06
to
as debugger/introspection tool?

you could use tkcon:
http://wiki.tcl.tk/tkcon

some more info:
http://wiki.tcl.tk/2?tkcon

for just following some variables
and maybe changing some of them
create a new toplevel and fill it with
labels and entries
#
set ::var1 42
# set ::var2 nix
set var3(this,element) 1234
set var3(other,element) 5678
set var3(other,item) dontshow


set watchlist {::var1 ::var2 ::var3(*,element }

set w .debug
toplevel $w
set idx 0

foreach varname $watchlist {
foreach {arrayname globpattern} [ split $varname () ] break
if {[array exist $arrayname ]} {
label $w.l$idx -text $arrayname
grid $w.l$idx -column 1 -row $idx
set ecnt 0
if { "$globpattern" == "" } {
set globpattern *
}
set elements [ array names $arrayname $globpattern ]
foreach elem $elements {
# handle similar to plain vars
label $w.l${idx}i$ecnt -text $elem
entry $w.e${idx}i$ecnt -textvariable ${varname}($elem)
grid $w.l${idx}i$ecnt -column 2 -row $idx
grid $w.e${idx}i$ecnt -column 3 -row $idx
incr ecnt
incr idx
}
} else {
label $w.l$idx -text $varname
entry $w.e$idx -textvariable $varname
grid $w.l$idx -column 1 -row $idx
grid $w.e$idx -column 3 -row $idx
}
incr idx
}

voila, a window into your app
G!
uwe

Uwe Klein

unread,
May 2, 2006, 6:02:19 PM5/2/06
to
as debugger/introspection tool?

entry $w.e${idx}i$ecnt -textvariable ${arrayname}($elem)

Message has been deleted

Neil Madden

unread,
May 2, 2006, 10:57:50 PM5/2/06
to

You probably want a debugger. http://wiki.tcl.tk/4003 gives some
pointers. To satisfy your exact request, it's pretty easy to hand-roll
some of these tools yourself. For instance, here is a proc that will
"pause" execution when called and present an interactive prompt (just
like at the tclsh prompt) at that point in your program. You can then
use normal Tcl commands to examine the state of the program. Use
"continue" to then resume execution, or "break" to abort.

proc debug-prompt {} {
set cmd ""
set level [expr {[info level]-1}]
set prompt "DEBUG\[$level\]% "
while 1 {
puts -nonewline $prompt
flush stdout
gets stdin line
append cmd $line\n
if {[info complete $cmd]} {
set code [catch {uplevel #$level $cmd} result]
if {$code == 0 && [string length $result]} {
puts stdout $result
} elseif {$code == 3} {
# break
error "aborted debugger"
} elseif {$code == 4} {
# continue
return
} else {
puts stderr $result
}
set prompt "DEBUG\[$level\]% "
set cmd ""
} else {
set prompt " "
}
}
}

And an example session:

% proc foo {args} {
set a 1
debug-prompt
puts "Resumed, a = $a, args = $args"
}
% proc bar val {
foo $val
}
% bar 12
DEBUG[2]% info locals
args a
DEBUG[2]% info level 0
foo 12
DEBUG[2]% set a
1
DEBUG[2]% set a "4 8 15 16 23 42"
4 8 15 16 23 42
DEBUG[2]% continue
Resumed, a = 4 8 15 16 23 42, args = 12

Hopefully that is self-explanatory. You can use "uplevel 1 debug-prompt"
to move up the callstack, and "continue" to move back down. With a
little alteration you can make this code present a debug shell over a
network socket or any other channel. Tkcon builds in this kind of
functionality (and more), as do other debugging tools available, but as
you can see, Tcl makes this kind of thing easy to begin with.

-- Neil

Paul Whitfield

unread,
May 2, 2006, 11:45:47 PM5/2/06
to
Neil Madden wrote:
> maura.m...@gmail.com wrote:
>> I woder whether there exist a way to stop Tcl interpreter, read some
>> variable values and then resume the executaion ,,,
>> Thank you so much.
>> Maura
>>

Are you asking for something as simple such as gets?

In tcl,

gets stdin var
puts "Variable is $var"


Regards

Paul

Cameron Laird

unread,
May 3, 2006, 10:07:43 AM5/3/06
to
In article <O_U5g.1275$VF....@newsfe2-win.ntli.net>,

Neil Madden <n...@cs.nott.ac.uk> wrote:
>maura.m...@gmail.com wrote:
>> I woder whether there exist a way to stop Tcl interpreter, read some
>> variable values and then resume the executaion ,,,
>> Thank you so much.
>> Maura
>>
>
>You probably want a debugger. http://wiki.tcl.tk/4003 gives some
>pointers. To satisfy your exact request, it's pretty easy to hand-roll
>some of these tools yourself. For instance, here is a proc that will
>"pause" execution when called and present an interactive prompt (just
>like at the tclsh prompt) at that point in your program. You can then
>use normal Tcl commands to examine the state of the program. Use
>"continue" to then resume execution, or "break" to abort.
>
>proc debug-prompt {} {
.
.
.
It's possible that Maura wants something that fits in one line
of code, or a few words of explanation. All the follow-ups have
been valuable and accurate, but we're still fumbling to achieve
a common vocabulary.

I don't want her thinking, "Why, I asked for something that
every other language builds in automatically, and these jokers
tell me that Tcl requires pages of code to achieve the same",
when the apparent mismatch results merely from confusion between
different vernaculars (Fortran vs. Tcl, for example).

Uwe Klein

unread,
May 3, 2006, 11:50:18 AM5/3/06
to
Cameron Laird wrote:

> It's possible that Maura wants something that fits in one line
> of code, or a few words of explanation. All the follow-ups have
> been valuable and accurate, but we're still fumbling to achieve
> a common vocabulary.

may the dialogs begin! <deep boing>

uwe


Uwe Klein

unread,
May 5, 2006, 2:44:36 AM5/5/06
to

did this just loose moentum or was it continued under the rose?

uwe

0 new messages