1 |
578 |
markom |
# Debug window for GDBtk.
|
2 |
|
|
# Copyright 1998, 1999, 2001 Red Hat
|
3 |
|
|
#
|
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.
|
8 |
|
|
#
|
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.
|
13 |
|
|
|
14 |
|
|
|
15 |
|
|
# -----------------------------------------------------------------------------
|
16 |
|
|
# NAME: DebugWin::constructor
|
17 |
|
|
#
|
18 |
|
|
# SYNOPSIS: constructor::args
|
19 |
|
|
#
|
20 |
|
|
# DESC: Creates the debug window
|
21 |
|
|
#
|
22 |
|
|
# ARGS: None are used yet.
|
23 |
|
|
# -----------------------------------------------------------------------------
|
24 |
|
|
body DebugWin::constructor {args} {
|
25 |
|
|
debug ""
|
26 |
|
|
window_name "Insight Debug" "Debug"
|
27 |
|
|
|
28 |
|
|
build_win
|
29 |
|
|
incr numTopWins
|
30 |
|
|
}
|
31 |
|
|
|
32 |
|
|
# -----------------------------------------------------------------------------
|
33 |
|
|
# NAME: DebugWin::destructor
|
34 |
|
|
#
|
35 |
|
|
# SYNOPSIS: Not called by hand
|
36 |
|
|
#
|
37 |
|
|
# DESC: Destroys the debug window
|
38 |
|
|
#
|
39 |
|
|
# ARGS: None
|
40 |
|
|
# -----------------------------------------------------------------------------
|
41 |
|
|
body DebugWin::destructor {} {
|
42 |
|
|
# notify debug code that window is going away
|
43 |
|
|
::debug::debugwin ""
|
44 |
|
|
incr numTopWins -1
|
45 |
|
|
}
|
46 |
|
|
|
47 |
|
|
# -----------------------------------------------------------------------------
|
48 |
|
|
# NAME: DebugWin::build_win
|
49 |
|
|
#
|
50 |
|
|
# SYNOPSIS: build_win
|
51 |
|
|
#
|
52 |
|
|
# DESC: Creates the Debug Window. Reads the contents of the debug log
|
53 |
|
|
# file, if it exists. Notifies the debug functions in ::debug
|
54 |
|
|
# to send output here.
|
55 |
|
|
# -----------------------------------------------------------------------------
|
56 |
|
|
body DebugWin::build_win {} {
|
57 |
|
|
global gdb_ImageDir GDBTK_LIBRARY
|
58 |
|
|
|
59 |
|
|
set top [winfo toplevel $itk_interior]
|
60 |
|
|
|
61 |
|
|
# initialize the gdbtk_de array
|
62 |
|
|
if {![info exists ::gdbtk_de]} {
|
63 |
|
|
set ::gdbtk_de(ALL) 1
|
64 |
|
|
set ::gdbtk_de(others) 0
|
65 |
|
|
}
|
66 |
|
|
|
67 |
|
|
# create menubar
|
68 |
|
|
set menu [menu $itk_interior.m -tearoff 0]
|
69 |
|
|
$menu add cascade -menu $menu.file -label "File" -underline 0
|
70 |
|
|
set m [menu $menu.file]
|
71 |
|
|
$m add command -label "Clear" -underline 1 \
|
72 |
|
|
-command [code $this _clear]
|
73 |
|
|
$m add command -label "Mark Old" -underline 1 \
|
74 |
|
|
-command [code $this _mark_old]
|
75 |
|
|
$m add separator
|
76 |
|
|
$m add command -label "Save" -underline 0 \
|
77 |
|
|
-command [code $this _save_contents]
|
78 |
|
|
$m add separator
|
79 |
|
|
$m add command -label "Close" -underline 0 \
|
80 |
|
|
-command "::debug::debugwin {};delete object $this"
|
81 |
|
|
$menu add cascade -menu $menu.trace -label "Trace"
|
82 |
|
|
set m [menu $menu.trace]
|
83 |
|
|
$m add radiobutton -label Start -variable ::debug::tracing -value 1
|
84 |
|
|
$m add radiobutton -label Stop -variable ::debug::tracing -value 0
|
85 |
|
|
$menu add cascade -menu $menu.rs -label "ReSource"
|
86 |
|
|
set m [menu $menu.rs]
|
87 |
|
|
foreach f [lsort [glob [file join $GDBTK_LIBRARY *.itb]]] {
|
88 |
|
|
$m add command -label "Source [file tail $f]"\
|
89 |
|
|
-command [list source $f]
|
90 |
|
|
}
|
91 |
|
|
$m add separator
|
92 |
|
|
$m add command -label "Source ALL" -command [code $this _source_all]
|
93 |
|
|
|
94 |
|
|
$menu add cascade -menu $menu.opt -label "Options"
|
95 |
|
|
set m [menu $menu.opt]
|
96 |
|
|
$m add command -label "Display" -underline 0 \
|
97 |
|
|
-command [list ManagedWin::open DebugWinDOpts -over $this]
|
98 |
|
|
if {!$::debug::initialized} {
|
99 |
|
|
$menu entryconfigure 1 -state disabled
|
100 |
|
|
$menu add cascade -label " Tracing Not Initialized" -foreground red \
|
101 |
|
|
-activeforeground red
|
102 |
|
|
}
|
103 |
|
|
$menu add cascade -menu $menu.help -label "Help" -underline 0
|
104 |
|
|
set m [menu $menu.help]
|
105 |
|
|
$m add command -label "Debugging Functions" -underline 0 \
|
106 |
|
|
-command {ManagedWin::open HtmlViewer -force -file debug.html \
|
107 |
|
|
-topics {{{"Debug Functions" debug.html}}}}
|
108 |
|
|
|
109 |
|
|
$top configure -menu $menu
|
110 |
|
|
|
111 |
|
|
iwidgets::scrolledtext $itk_interior.s -hscrollmode static \
|
112 |
|
|
-vscrollmode static -wrap none -textbackground black -foreground white
|
113 |
|
|
set _t [$itk_interior.s component text]
|
114 |
|
|
pack $itk_interior.s -expand 1 -fill both
|
115 |
|
|
|
116 |
|
|
# define tags
|
117 |
|
|
foreach color $_colors {
|
118 |
|
|
$_t tag configure [lindex $color 0] -foreground [lindex $color 1]
|
119 |
|
|
}
|
120 |
|
|
$_t tag configure trace -foreground gray
|
121 |
|
|
$_t tag configure args -foreground blue
|
122 |
|
|
$_t tag configure marked -background grey20
|
123 |
|
|
|
124 |
|
|
loadlog
|
125 |
|
|
|
126 |
|
|
# now notify the debug functions to use this window
|
127 |
|
|
::debug::debugwin $this
|
128 |
|
|
|
129 |
|
|
# override the window delete procedure so the messages are
|
130 |
|
|
# turned off first.
|
131 |
|
|
wm protocol $top WM_DELETE_WINDOW "::debug::debugwin {};destroy $top"
|
132 |
|
|
|
133 |
|
|
}
|
134 |
|
|
|
135 |
|
|
# -----------------------------------------------------------------------------
|
136 |
|
|
# NAME: DebugWin::puts
|
137 |
|
|
#
|
138 |
|
|
# SYNOPSIS: puts {level cls func msg}
|
139 |
|
|
#
|
140 |
|
|
# DESC: Writes debugging information into the DebugWin. A filter
|
141 |
|
|
# will be applied to determine if the message should be
|
142 |
|
|
# displayed or not.
|
143 |
|
|
#
|
144 |
|
|
# ARGS: level - priority level. See debug::dbug for details.
|
145 |
|
|
# cls - class name of caller, for example "SrcWin"
|
146 |
|
|
# func - function name of caller
|
147 |
|
|
# msg - message to display
|
148 |
|
|
# -----------------------------------------------------------------------------
|
149 |
|
|
body DebugWin::puts {level cls func msg} {
|
150 |
|
|
|
151 |
|
|
# filter. check if we should display this message
|
152 |
|
|
# for now we always let high-level messages through
|
153 |
|
|
if {!$::gdbtk_de(ALL) && $level == "I"} {
|
154 |
|
|
if {[info exists ::gdbtk_de($cls)]} {
|
155 |
|
|
if {!$::gdbtk_de($cls)} {
|
156 |
|
|
return
|
157 |
|
|
}
|
158 |
|
|
} elseif {!$::gdbtk_de(others)} {
|
159 |
|
|
return
|
160 |
|
|
}
|
161 |
|
|
}
|
162 |
|
|
|
163 |
|
|
if {$func != ""} {
|
164 |
|
|
append cls ::$func
|
165 |
|
|
}
|
166 |
|
|
$_t insert end "($cls) " {} "$msg\n" $level
|
167 |
|
|
$_t see insert
|
168 |
|
|
}
|
169 |
|
|
|
170 |
|
|
# -----------------------------------------------------------------------------
|
171 |
|
|
# NAME: DebugWin::put_trace
|
172 |
|
|
#
|
173 |
|
|
# SYNOPSIS: put_trace {enter level func ar}
|
174 |
|
|
#
|
175 |
|
|
# DESC: Writes trace information into the DebugWin. A filter
|
176 |
|
|
# will be applied to determine if the message should be
|
177 |
|
|
# displayed or not.
|
178 |
|
|
#
|
179 |
|
|
# ARGS: enter - 1 if this is a function entry, 0 otherwise.
|
180 |
|
|
# level - stack level
|
181 |
|
|
# func - function name
|
182 |
|
|
# ar - function arguments
|
183 |
|
|
# -----------------------------------------------------------------------------
|
184 |
|
|
body DebugWin::put_trace {enter level func ar} {
|
185 |
|
|
set x [expr {$level * 2 - 2}]
|
186 |
|
|
if {$enter} {
|
187 |
|
|
$_t insert end "[string range $_bigstr 0 $x]$func " trace "$ar\n" args
|
188 |
|
|
} else {
|
189 |
|
|
$_t insert end "[string range $_bigstr 0 $x]<- $func " trace "$ar\n" args
|
190 |
|
|
}
|
191 |
|
|
$_t see insert
|
192 |
|
|
}
|
193 |
|
|
|
194 |
|
|
# -----------------------------------------------------------------------------
|
195 |
|
|
# NAME: DebugWin::loadlog
|
196 |
|
|
#
|
197 |
|
|
# SYNOPSIS: loadlog
|
198 |
|
|
#
|
199 |
|
|
# DESC: Reads the contents of the debug log file, if it exists, into
|
200 |
|
|
# the DebugWin.
|
201 |
|
|
# -----------------------------------------------------------------------------
|
202 |
|
|
body DebugWin::loadlog {} {
|
203 |
|
|
$_t delete 0.0 end
|
204 |
|
|
# Now load in log file, if possible.
|
205 |
|
|
# this is rather rude, using the logfile variable in the debug namespace
|
206 |
|
|
if {$::debug::logfile != "" && $::debug::logfile != "stdout"} {
|
207 |
|
|
flush $::debug::logfile
|
208 |
|
|
seek $::debug::logfile 0 start
|
209 |
|
|
while {[gets $::debug::logfile line] >= 0} {
|
210 |
|
|
while {[catch {set f [lindex $line 0]} f]} {
|
211 |
|
|
# If the lindex failed its because the remainder of the
|
212 |
|
|
# list is on the next line. Get it.
|
213 |
|
|
if {[gets $::debug::logfile line2] < 0} {
|
214 |
|
|
break
|
215 |
|
|
}
|
216 |
|
|
append line \n $line2
|
217 |
|
|
}
|
218 |
|
|
if {$f == "T"} {
|
219 |
|
|
put_trace [lindex $line 1] [lindex $line 2] [lindex $line 3] \
|
220 |
|
|
[lindex $line 4]
|
221 |
|
|
} else {
|
222 |
|
|
puts $f [lindex $line 1] [lindex $line 2] [lindex $line 3]
|
223 |
|
|
}
|
224 |
|
|
}
|
225 |
|
|
}
|
226 |
|
|
}
|
227 |
|
|
|
228 |
|
|
# -----------------------------------------------------------------------------
|
229 |
|
|
# NAME: DebugWin::_source_all
|
230 |
|
|
#
|
231 |
|
|
# SYNOPSIS: _source_all
|
232 |
|
|
#
|
233 |
|
|
# DESC: Re-sources all the .itb files.
|
234 |
|
|
# -----------------------------------------------------------------------------
|
235 |
|
|
body DebugWin::_source_all {} {
|
236 |
|
|
foreach f [glob [file join $::GDBTK_LIBRARY *.itb]] {
|
237 |
|
|
source $f
|
238 |
|
|
}
|
239 |
|
|
}
|
240 |
|
|
|
241 |
|
|
# -----------------------------------------------------------------------------
|
242 |
|
|
# NAME: DebugWin::_clear
|
243 |
|
|
#
|
244 |
|
|
# SYNOPSIS: _clear
|
245 |
|
|
#
|
246 |
|
|
# DESC: Clears out the content of the debug window.
|
247 |
|
|
# -----------------------------------------------------------------------------
|
248 |
|
|
body DebugWin::_clear {} {
|
249 |
|
|
$_t delete 1.0 end
|
250 |
|
|
}
|
251 |
|
|
|
252 |
|
|
# -----------------------------------------------------------------------------
|
253 |
|
|
# NAME: DebugWin::_mark_old
|
254 |
|
|
#
|
255 |
|
|
# SYNOPSIS: _mark_old
|
256 |
|
|
#
|
257 |
|
|
# DESC: Changes the background of the current contents of the window.
|
258 |
|
|
# -----------------------------------------------------------------------------
|
259 |
|
|
body DebugWin::_mark_old {} {
|
260 |
|
|
$_t tag add marked 1.0 "end - 1c"
|
261 |
|
|
}
|
262 |
|
|
|
263 |
|
|
# -----------------------------------------------------------------------------
|
264 |
|
|
# NAME: DebugWin::_save_contents
|
265 |
|
|
#
|
266 |
|
|
# SYNOPSIS: _save_contents
|
267 |
|
|
#
|
268 |
|
|
# DESC: Changes the background of the current contents of the window.
|
269 |
|
|
# -----------------------------------------------------------------------------
|
270 |
|
|
body DebugWin::_save_contents {} {
|
271 |
|
|
set file [tk_getSaveFile -title "Choose debug window dump file" \
|
272 |
|
|
-parent [winfo toplevel $itk_interior]]
|
273 |
|
|
if {$file == ""} {
|
274 |
|
|
return
|
275 |
|
|
}
|
276 |
|
|
|
277 |
|
|
if {[catch {::open $file w} fileH]} {
|
278 |
|
|
tk_messageBox -type ok -icon error -message \
|
279 |
|
|
"Can't open file: \"$file\". \n\nThe error was:\n\n\"$fileH\""
|
280 |
|
|
return
|
281 |
|
|
}
|
282 |
|
|
::puts $fileH [$_t get 1.0 end]
|
283 |
|
|
|
284 |
|
|
}
|
285 |
|
|
|
286 |
|
|
###############################################################################
|
287 |
|
|
# -----------------------------------------------------------------------------
|
288 |
|
|
# NAME: DebugWinDOpts::constructor
|
289 |
|
|
#
|
290 |
|
|
# SYNOPSIS: constructor
|
291 |
|
|
#
|
292 |
|
|
# DESC: Creates the Debug Window Options Dialog.
|
293 |
|
|
# -----------------------------------------------------------------------------
|
294 |
|
|
body DebugWinDOpts::constructor {args} {
|
295 |
|
|
window_name "Debug Window Options"
|
296 |
|
|
build_win
|
297 |
|
|
eval itk_initialize $args
|
298 |
|
|
}
|
299 |
|
|
|
300 |
|
|
###############################################################################
|
301 |
|
|
# -----------------------------------------------------------------------------
|
302 |
|
|
# NAME: DebugWinDOpts::destructor
|
303 |
|
|
#
|
304 |
|
|
# SYNOPSIS: Not called by hand
|
305 |
|
|
#
|
306 |
|
|
# DESC: Destroys the Debug Window Options Dialog.
|
307 |
|
|
# -----------------------------------------------------------------------------
|
308 |
|
|
body DebugWinDOpts::destructor {} {
|
309 |
|
|
}
|
310 |
|
|
|
311 |
|
|
|
312 |
|
|
# -----------------------------------------------------------------------------
|
313 |
|
|
# NAME: DebugWinDOpts::build_win
|
314 |
|
|
#
|
315 |
|
|
# SYNOPSIS: build_win
|
316 |
|
|
#
|
317 |
|
|
# DESC: Creates the Debug Window Options Dialog. This dialog allows the
|
318 |
|
|
# user to select which information is displayed in the debug
|
319 |
|
|
# window and (eventually) how it looks.
|
320 |
|
|
# -----------------------------------------------------------------------------
|
321 |
|
|
body DebugWinDOpts::build_win {} {
|
322 |
|
|
wm title [winfo toplevel $itk_interior] "Debug Display Options"
|
323 |
|
|
# initialize here so we can resource this file and update the list
|
324 |
|
|
set _classes {DebugWin RegWin SrcBar SrcWin ToolBar WatchWin EmbeddedWin \
|
325 |
|
|
ManagedWin GDBWin StackWin SrcTextWin VariableWin global BPWin \
|
326 |
|
|
TargetSelection ModalDialog ProcessWin}
|
327 |
|
|
set f [frame $itk_interior.f]
|
328 |
|
|
set btns [frame $itk_interior.buttons]
|
329 |
|
|
|
330 |
|
|
iwidgets::Labeledframe $f.classes -labelpos nw -labeltext {Classes}
|
331 |
|
|
set fr [$f.classes childsite]
|
332 |
|
|
|
333 |
|
|
checkbutton $fr.0 -text ALL -variable ::gdbtk_de(ALL) -command [code $this _all]
|
334 |
|
|
set i 1
|
335 |
|
|
foreach cls [lsort $_classes] {
|
336 |
|
|
if {![info exists ::gdbtk_de($cls)]} {
|
337 |
|
|
set ::gdbtk_de($cls) 0
|
338 |
|
|
}
|
339 |
|
|
checkbutton $fr.$i -text $cls -variable ::gdbtk_de($cls)
|
340 |
|
|
incr i
|
341 |
|
|
}
|
342 |
|
|
checkbutton $fr.$i -text others -variable ::gdbtk_de(others)
|
343 |
|
|
incr i
|
344 |
|
|
|
345 |
|
|
set k [expr 3*(int($i/3))]
|
346 |
|
|
set more [expr $i - $k]
|
347 |
|
|
set j 0
|
348 |
|
|
while {$j < $k} {
|
349 |
|
|
grid $fr.$j $fr.[expr $j+1] $fr.[expr $j+2] -sticky w -padx 5 -pady 5
|
350 |
|
|
incr j 3
|
351 |
|
|
}
|
352 |
|
|
switch $more {
|
353 |
|
|
1 { grid $fr.$j x x -sticky w -padx 5 -pady 5}
|
354 |
|
|
2 { grid $fr.$j $fr.[expr $j+1] x -sticky w -padx 5 -pady 5}
|
355 |
|
|
}
|
356 |
|
|
|
357 |
|
|
pack $f.classes -side top -expand 1 -fill both
|
358 |
|
|
|
359 |
|
|
button $btns.ok -text [gettext OK] -width 7 -command [code delete object $this] \
|
360 |
|
|
-default active
|
361 |
|
|
button $btns.apply -text "Apply to All" -width 7 \
|
362 |
|
|
-command [code $this _apply]
|
363 |
|
|
if {$::debug::logfile == "" || $::debug::logfile == "stdout"} {
|
364 |
|
|
$btns.apply configure -state disabled
|
365 |
|
|
}
|
366 |
|
|
button $btns.help -text [gettext Help] -width 10 -command [code $this help] \
|
367 |
|
|
-state disabled
|
368 |
|
|
standard_button_box $btns
|
369 |
|
|
bind $btns.ok "$btns.ok flash; $btns.ok invoke"
|
370 |
|
|
bind $btns.apply "$btns.apply flash; $btns.apply invoke"
|
371 |
|
|
bind $btns.help "$btns.help flash; $btns.help invoke"
|
372 |
|
|
|
373 |
|
|
pack $btns $f -side bottom -expand 1 -fill both -anchor e
|
374 |
|
|
focus $btns.ok
|
375 |
|
|
}
|
376 |
|
|
|
377 |
|
|
# -----------------------------------------------------------------------------
|
378 |
|
|
# NAME: DebugWinDOpts::_all
|
379 |
|
|
#
|
380 |
|
|
# SYNOPSIS: _all
|
381 |
|
|
#
|
382 |
|
|
# DESC: Callback for selecting ALL classes. If the user selects ALL,
|
383 |
|
|
# deselect all the individual class checkbuttons.
|
384 |
|
|
# -----------------------------------------------------------------------------
|
385 |
|
|
body DebugWinDOpts::_all {} {
|
386 |
|
|
if {$::gdbtk_de(ALL)} {
|
387 |
|
|
foreach cls $_classes {
|
388 |
|
|
set ::gdbtk_de($cls) 0
|
389 |
|
|
}
|
390 |
|
|
set ::gdbtk_de(others) 0
|
391 |
|
|
}
|
392 |
|
|
}
|
393 |
|
|
|
394 |
|
|
|
395 |
|
|
# -----------------------------------------------------------------------------
|
396 |
|
|
# NAME: DebugWinDOpts::_apply
|
397 |
|
|
#
|
398 |
|
|
# SYNOPSIS: _apply
|
399 |
|
|
#
|
400 |
|
|
# DESC: Callback for the "Apply" button. Loads the contents of the
|
401 |
|
|
# log file through the new filter into the debug window. The
|
402 |
|
|
# button is disabled if there is no log file.
|
403 |
|
|
# -----------------------------------------------------------------------------
|
404 |
|
|
body DebugWinDOpts::_apply {} {
|
405 |
|
|
set dw [ManagedWin::find DebugWin]
|
406 |
|
|
if {$dw != ""} {
|
407 |
|
|
$dw loadlog
|
408 |
|
|
}
|
409 |
|
|
}
|