Purpose: to discuss the tools and techniques for debugging Tcl/Tk/etc. applications making use of Tcl's introspection capabilities. * Tools to leverage Tcl's native introspection 1. [TkInspect] (the [Tcl Dev Kit] has an enhanced version) 1. [TkCon] 1. [XotclIDE] * Techniques 1. [info] is your friend. ''[escargo]'' is fond of using a proc containing '''puts [[lindex [[info level -1]] 0 ]]''' [[I'd love to see pointers to tutorials, white papers, etc. on how to make use of tkinspect, tkcon, etc. for debugging Tcl/Tk applications]. ''So would I'' :-) ---- '''TkInspect''': a simple example. [[[PT]]] Lets fire up wish and do something simple. Now Windows Tk doesn't have a [send] command, so we need to help it along a little by using a substitute. Either [dde], [winsend] or [comm] can help here - Tcl provides [dde] by default. package require dde dde servername TestApp proc main {} { set dlg [toplevel .dlg] set but [button ${dlg}.b -text "OK" -command [list destroy $dlg]] pack $but -side bottom tkwait window .dlg } Now we have this evaluated in our shell, lets fire up [tkinspect]. The starkit is a handy way to get this. If you set up some file associations under Windows you can launch it very simply: assoc .kit=TclkitFile ftype TclkitFile=tclkit.exe %1 %* By using winsend or dde, tkinspect can automatically find your other Tk applications. Under X Windows it'll do this anyway. Go to the ''File->Select interpreter (send)'' menu item and select ''TestApp''. You are now connected to your Test App interpreter. The default view has Namespaces, Procs and Globals views. In Namespaces, select the ''::'' item at the top. The lower window should now be filled with lots of tcl's predefined variables and their values. If you scroll down a bit you will find a list of procedure defined in the global namespace. Now in the Procs view, select your ''main'' procedure. You should see the source as above. Hmm. Lets edit this a bit. Replace the text in the window with this proc main {} { set dlg [toplevel .dlg] set but [button ${dlg}.b -text "OK" -command [list destroy $dlg]] set can [button ${dlg}.c -text "Cancel" -command [list destroy $dlg]] pack $but $can -side left tkwait window .dlg } Now press the ''Send Value'' button at the top right, near the menu bar. It should say 'Value sent' in the status bar. As we don't want to bother switching windows, type 'main' in the Command entry and press the ''Send Command''. Your other application should now pop up a dialog with OK and Cancel buttons. If you close this and enter 'info body main' in your wish shell, you'll see the body has indeed been changed. While we are in the TestApp - lets create a variable. Enter 'set A 0' and then switch back to tkinspect. The Globals view in tkinspect displays the global variables defined in the remote interpreter. You'll notice that your variable doesn't appear yet. Right click and select ''Update this list'' or select the ''Globals->Update this list'' menu item and it should appear. If you select this now, the value window will display the value as a set statement. ---- [Category Debugging]