itcl::class WatchWin {
inherit EmbeddedWin GDBWin
constructor {args} {
debug
gdbtk_busy
build_win $itk_interior
gdbtk_idle
add_hook gdb_no_inferior_hook "$this no_inferior"
add_hook gdb_clear_file_hook [code $this clear_file]
add_hook file_changed_hook [code $this clear_file]
}
method busy {event} {
debug
set Running 1
cursor watch
}
method idle {event} {
debug
set Running 0
cursor {}
}
method no_inferior {} {
debug
cursor {}
set Running 0
}
method cursor {what} {
[winfo toplevel [namespace tail $this]] configure -cursor $what
::update idletasks
}
method build_win {f} {
set f [::frame $f.f]
set treeFrame [frame $f.top]
set entryFrame [frame $f.expr]
set tree [VarTree $treeFrame.tree]
pack $tree -expand yes -fill both
set Entry [entry $entryFrame.ent -font global/fixed]
button $entryFrame.but -text "Add Watch" -command [code $this validateEntry]
pack $f -fill both -expand yes
grid $entryFrame.ent -row 0 -column 0 -sticky news -padx 2
grid $entryFrame.but -row 0 -column 1 -padx 2
grid columnconfigure $entryFrame 0 -weight 1
grid columnconfigure $entryFrame 1
grid $treeFrame -row 0 -column 0 -sticky news
grid $entryFrame -row 1 -column 0 -padx 5 -pady 5 -sticky news
grid columnconfigure $f 0 -weight 1
grid rowconfigure $f 0 -weight 1
window_name "Watch"
::update idletasks
bind $entryFrame.ent <Return> "$entryFrame.but flash; $entryFrame.but invoke"
}
method validateEntry {} {
if {!$Running} {
debug "Getting entry value...."
set variable [$Entry get]
debug "Got $variable, going to add"
set ok [add $variable]
debug "Added... with ok: $ok"
$Entry delete 0 end
}
}
method clear_file {} {
debug
set Watched {}
}
destructor {
debug
set tree {}
remove_hook gdb_no_inferior_hook "$this no_inferior"
remove_hook gdb_clear_file_hook [code $this clear_file]
remove_hook file_changed_hook [code $this clear_file]
foreach var $Watched {
$var delete
}
}
method remove {entry} {
debug $entry
set Watched [lremove $Watched $entry]
$entry remove
$entry delete
}
method update {event} {
$tree update
}
method add {name} {
debug "Trying to add \"$name\" to watch"
set var [split $name \n]
set var [lindex $var 0]
set var [split $var =]
set var [lindex $var 0]
set var [string trim $var +-\;\ \r\n,]
set err [catch {gdb_cmd "set variable $var"} errTxt]
if {$err} {
dbug W "ERROR adding variable: $errTxt"
ManagedWin::open WarningDlg -transient \
-over $this -message [list $errTxt] -ignorable "watchvar"
} else {
if {[string index $var 0] == "\$"} {
catch {gdb_cmd "p $var"} msg
set msg [split $msg =]
set msg [string trim [lindex $msg 1] \ \r\n]
if {$msg == "void"} {
return 0
}
}
debug "In add, going to add $name"
set err [catch {set foo($name) 1}]
debug "err1=$err"
set err [expr {$err + [catch {expr {$foo($name) + 1}}]}]
debug "err2=$err"
if {!$err} {
set var [gdb_variable create -expr $name]
debug "var=$var"
$tree add $var
lappend Watched $var
return 1
}
}
return 0
}
protected variable Entry
protected variable Watched {}
protected variable tree
protected variable Running
}