1 # Local Variable Window for Insight.
2 # Copyright (C) 2002, 2003, 2006 Red Hat
4 # This program is free software; you can redistribute it and/or modify it
5 # under the terms of the GNU General Public License (GPL) as published by
6 # the Free Software Foundation; either version 2 of the License, or (at
7 # your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
15 # ----------------------------------------------------------------------
16 # Implements local variables windows for gdb.
17 # ----------------------------------------------------------------------
19 itcl::class LocalsWin {
20 inherit EmbeddedWin GDBWin
21 # ------------------------------------------------------------------
22 # CONSTRUCTOR - create new locals window
23 # ------------------------------------------------------------------
28 build_win $itk_interior
31 add_hook gdb_no_inferior_hook "$this no_inferior"
32 add_hook gdb_clear_file_hook [code $this clear_file]
33 add_hook file_changed_hook [code $this clear_file]
39 # ------------------------------------------------------------------
40 # PUBLIC METHOD: busy - BusyEvent handler
41 # Disable all ui elements that could affect gdb's state
42 # ------------------------------------------------------------------
54 # ------------------------------------------------------------------
57 # ------------------------------------------------------------------
58 method no_inferior {} {
61 catch {delete object $_frame}
66 # ------------------------------------------------------------------
67 # METHOD: cursor - change the toplevel's cursor
68 # ------------------------------------------------------------------
69 method cursor {what} {
70 [winfo toplevel [namespace tail $this]] configure -cursor $what
75 # ------------------------------------------------------------------
76 # METHOD: build_win - build window for variables.
77 # ------------------------------------------------------------------
78 method build_win {f} {
81 set tree [VarTree $f.tree -type "local"]
82 pack $f.tree -expand yes -fill both
83 pack $f -expand yes -fill both
85 window_name "Local Variables"
90 # ------------------------------------------------------------------
91 # METHOD: clear_file - Clear out state so that a new executable
92 # can be loaded. For LocalWins, this means doing
93 # everything that no_inferior does.
94 # ------------------------------------------------------------------
95 method clear_file {} {
99 # ------------------------------------------------------------------
100 # DESTRUCTOR - delete locals window
101 # ------------------------------------------------------------------
106 # Remove this window and all hooks
107 remove_hook gdb_no_inferior_hook "$this no_inferior"
108 remove_hook gdb_clear_file_hook [code $this clear_file]
109 remove_hook file_changed_hook [code $this clear_file]
112 method context_switch {} {
115 set err [catch {gdb_selected_frame} current_frame]
116 #debug "1: err=$err; _frame=\"$_frame\"; current_frame=\"$current_frame\""
118 if {$err && $_frame != ""} {
120 debug "no current frame"
121 catch {delete object $_frame}
124 } elseif {$current_frame == "" && $_frame == ""} {
127 } elseif {$_frame == "" || $current_frame != [$_frame address]} {
128 # We've changed frames. If we knew something about
129 # the stack layout, we could be more intelligent about
130 # destroying variables, but we don't know that here (yet).
131 debug "switching to frame at $current_frame"
133 # Destroy the old frame and create the new one
134 catch {destroy $_frame}
135 set _frame [Frame ::\#auto $current_frame]
136 debug "created new frame: $_frame at [$_frame address]"
146 method update {event} {
149 # Check that a context switch has not occured
150 if {[context_switch]} {
151 debug "CONTEXT SWITCH"
153 # delete variables in tree
157 $tree add [$_frame variables]
160 if {$_frame == ""} {return}
161 # check for any new variables in the same frame
162 $tree add [$_frame new]
164 after idle [code $tree update]
167 protected variable Entry
168 protected variable tree
169 protected variable _frame {}