~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

Open Mash Cross Reference
mash/tcl/common/dbg-err.tcl

Component: ~ [ mash ] ~ [ apps ] ~ [ gsm ] ~ [ lib ] ~ [ otcl ] ~ [ srm ] ~ [ tcl8.3 ] ~ [ tclcl ] ~ [ tk8.3 ] ~ [ tutorials ] ~

  1 # dbg-err.tcl --
  2 #
  3 #       Error procedures, this file should be preloaded
  4 #       These procedures allow some simple diagnostics to be performed when
  5 #       there is an error.
  6 #
  7 # Copyright (c) 1993-2002 The Regents of the University of California.
  8 # All rights reserved.
  9 #
 10 # Redistribution and use in source and binary forms, with or without
 11 # modification, are permitted provided that the following conditions are met:
 12 #
 13 # A. Redistributions of source code must retain the above copyright notice,
 14 #    this list of conditions and the following disclaimer.
 15 # B. Redistributions in binary form must reproduce the above copyright notice,
 16 #    this list of conditions and the following disclaimer in the documentation
 17 #    and/or other materials provided with the distribution.
 18 # C. Neither the names of the copyright holders nor the names of its
 19 #    contributors may be used to endorse or promote products derived from this
 20 #    software without specific prior written permission.
 21 #
 22 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
 23 # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 24 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 25 # ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR
 26 # ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 27 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
 28 # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
 29 # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
 30 # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 31 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 32 
 33 
 34 proc tkerror msg {
 35         global errorInfo mb
 36 
 37         if {[string match "no more colors*" $msg]} {
 38                 set app [tk appname]
 39                 puts "$app: $msg"
 40                 return
 41         }
 42         append errmsg "Error message: "
 43         append errmsg $msg\n
 44         set errInf $errorInfo
 45 
 46         if {[winfo exists .masherrdiag] || [winfo exists .mashstacktrace]} {
 47                 puts stderr "$errmsg stack trace: $errorInfo"
 48                 return
 49         }
 50         puts stderr "error: $errorInfo"
 51         set retCode [tk_dialog .masherrdiag Error $errmsg error \
 52                         0 Exit "Stack Trace" Continue Dump]
 53 
 54         case $retCode {
 55                 0 {abort}
 56                 1 {     set p [new StackTrace]
 57                         $p open $errInf
 58                 }
 59                 2 {puts stderr $errmsg}
 60         }
 61         return 1
 62 }
 63 
 64 proc bgerror msg {
 65         tkerror $msg
 66 }
 67 
 68 # individual apps should overwrite this to do more stuff if needed
 69 proc abort {} {
 70         exit -1
 71 }
 72 
 73 Class StackTrace
 74 
 75 StackTrace instproc open {errmsg} {
 76         global traceok traceCmd
 77         $self instvar t_
 78 
 79         set p [toplevel .mashstacktrace]
 80         set f [frame $p.top]
 81         set t_ [text $f.t -yscrollcommand "$f.sy set" \
 82                         -xscrollcommand "$p.sx set"]
 83         bind $t_ <Button-3> "$t_ get sel.first sel.last"
 84 
 85         set sx [scrollbar $p.sx -orient horiz -command "$t_ xview"]
 86         set sy [scrollbar $f.sy -orient vert -command "$t_ yview"]
 87 
 88         pack $f -side top -expand true -fill both
 89         pack $sy -side right -fill y
 90         pack $sx -side top -fill x
 91         pack $t_ -side left -expand true -fill both
 92 
 93         set panel [frame $p.b]
 94         pack $panel -side bottom -fill x
 95         set abort [button $panel.abort -command "abort" -text "abort"]
 96         set exitB  [button $panel.exitB -text "exit" \
 97                     -command "delete [Application instance] ; exit"]
 98         set cont  [button $panel.continue -command {set traceok ok} \
 99                         -text continue]
100         set sep [label $panel.gap -width 10 -text "" -relief flat]
101         set ent [entry $panel.entry -textvar traceCmd -width 40]
102         set evl [button $panel.evl -text eval \
103                         -command "$self eval_str \$traceCmd"]
104         set cls [button $panel.info -text class \
105                         -command "$self get_info \$traceCmd"]
106         bind $ent <Return> "$evl invoke"
107 
108         $t_ insert insert $errmsg
109         pack $exitB $abort $cont $sep $ent $evl $cls -side left -fill both
110         wm title $p "DebugInfo@[info hostname]"
111 
112         tkwait variable traceok
113         destroy $p
114         return
115 }
116 
117 if 0 {
118         StackTrace instproc get_next {} {
119                 $self instvar t_
120                 set i [$t_ search -forwards -regexp --  "_o[0-9]*"  sel.first]
121                 puts stderr $i
122                 set str [$t_ get $i wordend]
123                 puts stderr $str
124         }
125 }
126 
127 StackTrace instproc destroy {} {
128         $self next
129 }
130 
131 StackTrace instproc get_info {str} {
132         $self instvar t_
133         if {$str==""} {
134              set str [$t_ get sel.first sel.last]
135         }
136         $self eval_str [concat $str info class]
137 }
138 
139 StackTrace instproc eval_str {str} {
140         $self instvar t_
141         $t_ insert 1.0 "eval: $str\n"
142         if [catch {eval $str} result] {
143                 $t_ insert 1.0 "error: $result\n"
144         } else {
145 #                DbgOut "$result"
146                 $t_ insert 1.0 "result: $result\n"
147         }
148 }
149 
150 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.