1 # Debug window for GDBtk.
2 # Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
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 # NAME: DebugWin::constructor
18 # SYNOPSIS: constructor::args
20 # DESC: Creates the debug window
22 # ARGS: None are used yet.
23 # -----------------------------------------------------------------------------
24 itcl::body DebugWin::constructor {args} {
26 window_name "Insight Debug" "Debug"
31 # -----------------------------------------------------------------------------
32 # NAME: DebugWin::destructor
34 # SYNOPSIS: Not called by hand
36 # DESC: Destroys the debug window
39 # -----------------------------------------------------------------------------
40 itcl::body DebugWin::destructor {} {
41 # notify debug code that window is going away
45 # -----------------------------------------------------------------------------
46 # NAME: DebugWin::reconfig
48 # SYNOPSIS: Reconfigure callback
50 # DESC: Fixes up window colors
53 # -----------------------------------------------------------------------------
54 itcl::body DebugWin::reconfig {} {
55 # This keeps the Debug window using its unique black background.
56 # Otherwise, a reconfigure event will color it to match the other windows
57 $itk_interior.s configure -textbackground black
60 # -----------------------------------------------------------------------------
61 # NAME: DebugWin::build_win
65 # DESC: Creates the Debug Window. Reads the contents of the debug log
66 # file, if it exists. Notifies the debug functions in ::debug
67 # to send output here.
68 # -----------------------------------------------------------------------------
69 itcl::body DebugWin::build_win {} {
70 global gdb_ImageDir GDBTK_LIBRARY
72 set top [winfo toplevel $itk_interior]
74 # initialize the gdbtk_de array
75 if {![info exists ::gdbtk_de]} {
77 set ::gdbtk_de(ERRORS_ONLY) 0
78 set ::gdbtk_de(others) 0
79 set ::gdbtk_de(filter_var) ALL
83 set menu [menu $itk_interior.m -tearoff 0]
84 $menu add cascade -menu $menu.file -label "File" -underline 0
85 set m [menu $menu.file]
86 $m add command -label "Clear" -underline 1 \
87 -command [code $this _clear]
88 $m add command -label "Mark Old" -underline 1 \
89 -command [code $this _mark_old]
91 $m add command -label "Save" -underline 0 \
92 -command [code $this _save_contents]
94 $m add command -label "Close" -underline 0 \
95 -command "::debug::debugwin {};delete object $this"
96 $menu add cascade -menu $menu.trace -label "Trace"
97 set m [menu $menu.trace]
98 $m add radiobutton -label Start -variable ::debug::tracing -value 1
99 $m add radiobutton -label Stop -variable ::debug::tracing -value 0
100 $menu add cascade -menu $menu.rs -label "ReSource"
101 set m [menu $menu.rs]
102 foreach f [lsort [glob [file join $GDBTK_LIBRARY *.itb]]] {
103 $m add command -label "Source [file tail $f]"\
104 -command [list source $f]
107 $m add command -label "Source ALL" -command [code $this _source_all]
109 $menu add cascade -menu $menu.opt -label "Options"
110 set m [menu $menu.opt]
111 $m add command -label "Display" -underline 0 \
112 -command [list ManagedWin::open DebugWinDOpts -over $this]
113 if {!$::debug::initialized} {
114 $menu entryconfigure 1 -state disabled
115 $menu add cascade -label " Tracing Not Initialized" -foreground red \
116 -activeforeground red
118 $menu add cascade -menu $menu.help -label "Help" -underline 0
119 set m [menu $menu.help]
120 $m add command -label "Debugging Functions" -underline 0 \
121 -command {open_help debug.html}
123 $top configure -menu $menu
125 iwidgets::scrolledtext $itk_interior.s -hscrollmode static \
126 -vscrollmode static -wrap none -textbackground black -foreground white
127 set _t [$itk_interior.s component text]
128 pack $itk_interior.s -expand 1 -fill both
131 foreach color $_colors {
132 $_t tag configure [lindex $color 0] -foreground [lindex $color 1]
134 $_t tag configure trace -foreground gray
135 $_t tag configure args -foreground blue
136 $_t tag configure marked -background grey20
140 # now notify the debug functions to use this window
141 ::debug::debugwin $this
143 # override the window delete procedure so the messages are
145 wm protocol $top WM_DELETE_WINDOW "::debug::debugwin {};destroy $top"
148 # -----------------------------------------------------------------------------
149 # NAME: DebugWin::puts
151 # SYNOPSIS: puts {level cls func msg}
153 # DESC: Writes debugging information into the DebugWin. A filter
154 # will be applied to determine if the message should be
157 # ARGS: level - priority level. See debug::dbug for details.
158 # cls - class name of caller, for example "SrcWin"
159 # func - function name of caller
160 # msg - message to display
161 # -----------------------------------------------------------------------------
162 itcl::body DebugWin::puts {level cls func msg} {
163 # filter. check if we should display this message
164 # for now we always let high-level messages through
167 # errors and warnings only
168 if {$::gdbtk_de(ERRORS_ONLY)} { return }
170 # ALL classes except those set
171 if {$::gdbtk_de(ALL)} {
172 if {[info exists ::gdbtk_de($cls)]} {
173 if {$::gdbtk_de($cls)} {
176 } elseif {$::gdbtk_de(others)} {
181 # ONLY the classes set
182 if {!$::gdbtk_de(ALL)} {
183 if {[info exists ::gdbtk_de($cls)]} {
184 if {!$::gdbtk_de($cls)} {
187 } elseif {!$::gdbtk_de(others)} {
196 $_t insert end "($cls) " {} "$msg\n" $level
200 # -----------------------------------------------------------------------------
201 # NAME: DebugWin::put_trace
203 # SYNOPSIS: put_trace {enter level func ar}
205 # DESC: Writes trace information into the DebugWin. A filter
206 # will be applied to determine if the message should be
209 # ARGS: enter - 1 if this is a function entry, 0 otherwise.
210 # level - stack level
211 # func - function name
212 # ar - function arguments
213 # -----------------------------------------------------------------------------
214 itcl::body DebugWin::put_trace {enter level func ar} {
215 set x [expr {$level * 2 - 2}]
217 $_t insert end "[string range $_bigstr 0 $x]$func " trace "$ar\n" args
219 $_t insert end "[string range $_bigstr 0 $x]<- $func " trace "$ar\n" args
224 # -----------------------------------------------------------------------------
225 # NAME: DebugWin::loadlog
229 # DESC: Reads the contents of the debug log file, if it exists, into
231 # -----------------------------------------------------------------------------
232 itcl::body DebugWin::loadlog {} {
234 # Now load in log file, if possible.
235 # this is rather rude, using the logfile variable in the debug namespace
236 if {$::debug::logfile != "" && $::debug::logfile != "stdout"} {
237 flush $::debug::logfile
238 seek $::debug::logfile 0 start
239 while {[gets $::debug::logfile line] >= 0} {
240 while {[catch {set f [lindex $line 0]} f]} {
241 # If the lindex failed its because the remainder of the
242 # list is on the next line. Get it.
243 if {[gets $::debug::logfile line2] < 0} {
246 append line \n $line2
249 put_trace [lindex $line 1] [lindex $line 2] [lindex $line 3] \
252 puts $f [lindex $line 1] [lindex $line 2] [lindex $line 3]
258 # -----------------------------------------------------------------------------
259 # NAME: DebugWin::_source_all
261 # SYNOPSIS: _source_all
263 # DESC: Re-sources all the .itb files.
264 # -----------------------------------------------------------------------------
265 itcl::body DebugWin::_source_all {} {
266 foreach f [glob [file join $::GDBTK_LIBRARY *.itb]] {
271 # -----------------------------------------------------------------------------
272 # NAME: DebugWin::_clear
276 # DESC: Clears out the content of the debug window.
277 # -----------------------------------------------------------------------------
278 itcl::body DebugWin::_clear {} {
282 # -----------------------------------------------------------------------------
283 # NAME: DebugWin::_mark_old
285 # SYNOPSIS: _mark_old
287 # DESC: Changes the background of the current contents of the window.
288 # -----------------------------------------------------------------------------
289 itcl::body DebugWin::_mark_old {} {
290 $_t tag add marked 1.0 "end - 1c"
293 # -----------------------------------------------------------------------------
294 # NAME: DebugWin::_save_contents
296 # SYNOPSIS: _save_contents
298 # DESC: Changes the background of the current contents of the window.
299 # -----------------------------------------------------------------------------
300 itcl::body DebugWin::_save_contents {} {
301 set file [tk_getSaveFile -title "Choose debug window dump file" \
302 -parent [winfo toplevel $itk_interior]]
307 if {[catch {::open $file w} fileH]} {
308 tk_messageBox -type ok -icon error -message \
309 "Can't open file: \"$file\". \n\nThe error was:\n\n\"$fileH\""
312 ::puts $fileH [$_t get 1.0 end]
316 ###############################################################################
317 # -----------------------------------------------------------------------------
318 # NAME: DebugWinDOpts::constructor
320 # SYNOPSIS: constructor
322 # DESC: Creates the Debug Window Options Dialog.
323 # -----------------------------------------------------------------------------
324 itcl::body DebugWinDOpts::constructor {args} {
325 window_name "Debug Window Options"
327 eval itk_initialize $args
330 ###############################################################################
331 # -----------------------------------------------------------------------------
332 # NAME: DebugWinDOpts::destructor
334 # SYNOPSIS: Not called by hand
336 # DESC: Destroys the Debug Window Options Dialog.
337 # -----------------------------------------------------------------------------
338 itcl::body DebugWinDOpts::destructor {} {
342 # -----------------------------------------------------------------------------
343 # NAME: DebugWinDOpts::build_win
345 # SYNOPSIS: build_win
347 # DESC: Creates the Debug Window Options Dialog. This dialog allows the
348 # user to select which information is displayed in the debug
349 # window and (eventually) how it looks.
350 # -----------------------------------------------------------------------------
351 itcl::body DebugWinDOpts::build_win {} {
352 wm title [winfo toplevel $itk_interior] "Debug Display Options"
353 # initialize here so we can resource this file and update the list
354 set _classes {DebugWin RegWin SrcBar SrcWin ToolBar WatchWin EmbeddedWin \
355 ManagedWin GDBWin StackWin SrcTextWin global \
356 BpWin TargetSelection ModalDialog ProcessWin \
357 GDBEventHandler MemWin VarTree}
358 set _classes [concat [lsort $_classes] others]
360 set f [frame $itk_interior.f]
361 set btns [frame $itk_interior.buttons]
363 iwidgets::Labeledframe $f.display -labelpos nw -labeltext {Classes}
364 set fr [$f.display childsite]
365 radiobutton $fr.0 -text "Messages from ALL classes EXCEPT those selected below" \
366 -variable ::gdbtk_de(filter_var) -value ALL -command [code $this _all]
367 radiobutton $fr.1 -text "Messages from ONLY those classes selected below" \
368 -variable ::gdbtk_de(filter_var) -value ONLY -command [code $this _all]
369 radiobutton $fr.2 -text "Only WARNINGS and ERRORS" \
370 -variable ::gdbtk_de(filter_var) -value ERRORS -command [code $this _all]
372 grid $fr.0 -sticky w -padx 5 -pady 5
373 grid $fr.1 -sticky w -padx 5 -pady 5
374 grid $fr.2 -sticky w -padx 5 -pady 5
376 iwidgets::Labeledframe $f.classes
377 set fr [$f.classes childsite]
380 foreach cls $_classes {
381 if {![info exists ::gdbtk_de($cls)]} {
382 set ::gdbtk_de($cls) 0
384 checkbutton $fr.$i -text $cls -variable ::gdbtk_de($cls)
388 set k [expr 3*(int($i/3))]
389 set more [expr $i - $k]
392 grid $fr.$j $fr.[expr $j+1] $fr.[expr $j+2] -sticky w -padx 5 -pady 5
396 1 { grid $fr.$j x x -sticky w -padx 5 -pady 5}
397 2 { grid $fr.$j $fr.[expr $j+1] x -sticky w -padx 5 -pady 5}
400 pack $f.display -side top -expand 1 -fill both
401 pack $f.classes -side top -expand 1 -fill both
403 button $btns.ok -text [gettext OK] -width 7 -command [code $this _apply 1] \
405 button $btns.apply -text "Apply to All" -width 7 \
406 -command [code $this _apply 0]
407 if {$::debug::logfile == "" || $::debug::logfile == "stdout"} {
408 $btns.apply configure -state disabled
410 button $btns.help -text [gettext Help] -width 10 -command [code $this help] \
412 standard_button_box $btns
413 bind $btns.ok <Return> "$btns.ok flash; $btns.ok invoke"
414 bind $btns.apply <Return> "$btns.apply flash; $btns.apply invoke"
415 bind $btns.help <Return> "$btns.help flash; $btns.help invoke"
417 pack $btns $f -side bottom -expand 1 -fill both -anchor e
421 # -----------------------------------------------------------------------------
422 # NAME: DebugWinDOpts::_all
426 # DESC: Callback for selecting ALL classes. If the user selects ALL,
427 # deselect all the individual class checkbuttons.
428 # -----------------------------------------------------------------------------
429 itcl::body DebugWinDOpts::_all {} {
430 switch $::gdbtk_de(filter_var) {
432 set ::gdbtk_de(ALL) 1
433 set ::gdbtk_de(ERRORS_ONLY) 0
434 #enable class buttons
436 foreach class $_classes {
437 [$itk_interior.f.classes childsite].$num configure -state normal
442 set ::gdbtk_de(ALL) 0
443 set ::gdbtk_de(ERRORS_ONLY) 0
444 #enable class buttons
446 foreach class $_classes {
447 [$itk_interior.f.classes childsite].$num configure -state normal
452 set ::gdbtk_de(ALL) 0
453 set ::gdbtk_de(ERRORS_ONLY) 1
454 # disable class buttons
456 foreach class $_classes {
457 [$itk_interior.f.classes childsite].$num configure -state disabled
465 # -----------------------------------------------------------------------------
466 # NAME: DebugWinDOpts::_apply
470 # DESC: Callback for the "Apply" button. Loads the contents of the
471 # log file through the new filter into the debug window. The
472 # button is disabled if there is no log file.
473 # -----------------------------------------------------------------------------
474 itcl::body DebugWinDOpts::_apply { done } {
475 set dw [ManagedWin::find DebugWin]