URL
https://opencores.org/ocsvn/or1k/or1k/trunk
Subversion Repositories or1k
[/] [or1k/] [trunk/] [insight/] [gdb/] [gdbtcl/] [plugins/] [HOW-TO] - Rev 1765
Compare with Previous | Blame | View Log
INSIGHT PLUG-INS HOW-TO=======================This text describes the technical aspects of adding a plug-in windowto Insight, the graphical front-end to the GNU debugger GDB.1) INTRODUCTIONThe plug-in facility allows for the addition of custom windows toInsight. These windows are not to become part of the Insightdistribution, but rather to be distributed separately. They can bedownloaded from the authors web site, may accompany some developmentboard or embedded OS or come with anything else that can benefit froma custom window being added to the standard Insight. As the plug-inswill be loaded into Insight/GDB for execution, the terms of the GPLalso apply to the plug-in code. Also, Red Hat provides this facilityas-is and accepts no responsibility from its use. Please refer to thetext of the GPL for more details.The facilities described here provide support for customvisualizations (custom windows for displaying information retrievedfrom the target). By writing a plug-in, it is possible to visualizetarget specific data that is not shown in the standard Insightwindows.The plug-in facility cannot be used to control target execution. Thecurrent implementation of Insight assumes that only the Source Windowissues commands related to target execution control. There is nomechanism to prevent one to call the commands that control execution,but its use may result in inconsistent GUI states. This restrictionmay be lifted in future versions of Insight.The facility works as follows: A "plugins" subdirectory is added underthe gdbtcl directory where Insight Tcl code is installed. The customplug-in code will be installed in a subdirectory of this "plugins"directory. The plug-in window will be written as a [incr Tcl/Tk]class which inherits from the provided PluginWindow class andimplements the methods necessary to display the desired customdata. GDB will read plug-in files on start-up and add a menu item tothe PlugIn menu of the Insight Source Window. When the menu item ischosen, GDB instantiates the custom plug-in class.The PluginWindow base class constructor creates a toplevel window (anInsight ManagedWin) which contains a "childsite". In this case, the"childsite" is a frame in which the derived class (the custom plug-in)can draw. The PluginWindow class also provides facilities to add amenu and a toolbar. Among the methods provided by this class, the"running" method is called every time the debugger starts the targetand the "stopped" method is called every time the target stops. In the"stopped" method, information can be gathered from the target anddisplayed. The "running" method indicates that GDB is busy runningthe target. No activities should be initiated by any GUI componentwhile in this state (except for the STOP button in the Source Window).The remainder of this document describes how to install a customplug-in and some details of the PluginWindow class. Writing TclExtensions (technically is what plug-ins are) is beyond the scope ofthis document, but a simple example is given and some documentationreferences are provided.Please see the file CONTRIBUTE in this directory for someadministrative details before you start developing your plug-in.2) HOW TO ADD A PLUG-IN WINDOW TO INSIGHTOnce you have your plug-in class ready, here is how to make it show upin the Insight Source Window "PlugIn" menu. You may perform thesesteps manually, but if you are distributing your plug-in, it may beconvenient to provide with it an installation script that automatethis steps.The examples in this section refer to the sample plug-in code providedwith the Insight sources, located in the$(SOURCE)/gdb/gdbtk/library/plugins and$(SOURCE)/gdb/gdbtk/library/plugins/rhabout directories.Custom plug-ins are provided as "packages" (see [Welch 2000] and[Smith 2000]). The following setup will cause your plug-in package tobe loaded.i) First, locate the $(INSTALL)/share/gdbtcl directory. This is thedirectory which contains the Tcl/Tk code used by Insight. Create a"plugins" subdirectory if it does not exist yet (i.e., if your plug-inis the first to be installed). Now you must have a directory:$(INSTALL)/share/gdbtcl/pluginsin your installation tree.ii) Create a subdirectory for your plug-in code (named in accordance tothe conventions set forth in the CONTRIBUTE file). Add all your codeto that directory. Make sure you have a tclIndex file or useauto_mkindex to create it. For instance, in the sample case we wouldhave:$(INSTALL)/share/gdbtcl/plugins/rhaboutand it would contain:rhabout.itcl rhabout.so tclIndexiii) In the "plugins" directory create a file that will actually load yourplug-in package (named accordingly to the CONTRIBUTE conventions). Inthe provided sample, this file is "rhabout.tcl" and would contain thefollowing lines:package provide RHABOUT 1.0set dirname [file dirname [info script]]lappend auto_path [file join $dirname rhabout]load [file join $dirname rhabout rhabout.so] RHABOUTThe first line states what package the sample plug-in code isproviding. Note that the subdirectory "rhabout" which contains thesample plug-in is added to the auto_path in the third line and thereis a tclIndex file in that directory (that is how plug-in classes andmethods are found).The last line is only necessary if your plug-in contains Tcl commandprocedures written in C. Loading Tcl libraries is described in [Welch2000] and the [incr Tcl/Tk] bits can be found in [Smith 2000]. It isrecommended that the reader also refer to the "load" Tcl man page ifthese dynamic libraries are to be loaded.iv) In the "plugins" directory, add an entry to the pkgIndex.tcl file,if it exists, with a "package ifneeded" command to source the filecreated in step (iii). If the file does not exist, create it. Forthe sample plug-in, this entry is:package ifneeded RHABOUT 1.0 [list source [file join $dir rhabout.tcl]]This roughly corresponds to what would be created by a pkg_mkIndexcommand with the "-direct" option.If you are writing a install script, make sure to append to this file,not overwrite it. If there are other plug-ins already installed youdon't want to remove their "package ifneeded" commands (e.g., use ">>"in a c-shell script). Be considerate.v) Create the file "plugins.tcl" in the "plugins" directory if it doesnot yet exist. Again, this is a file shared by all plug-ins so makesure your install script does not overwrite, but append to it.This is a Tcl code fragment that will be sourced by the Insight SourceWindow constructor to add menu entries to the "PlugIn" menu that willinstantiate the plug-in classes. If there is any error in this fewlines of code Insight will not start and a Tcl stack trace will beshown. So test it in your build directory before installing in asystem shared by others.For the sample plug-in, this lines would be:# Add your window to the PlugIn menu here# Don't forget to add your packet as wellif {1} { #test here if your target is configured#package require LIBGDB 1.0package require RHABOUT 1.0$Menu add command Other "About Red Hat" \{ManagedWin::open RHAbout} \-underline 0set plugins_available 1}You can ignore the LIBGDB "package require" command for now. LIBGDBis under construction and not yet available. But do not forget toadd a "package require" command for your plug-in package. Otherwise,when someone choses your plug-in menu entry a stack trace will beproduced.The Tcl command starting with "$Menu" is similar to the ones providedby the "menubar" component of the PluginWindow class (described laterin this document), but all one needs to do is to copy the abovereplacing the menu entry text "About Red Hat", the plug-in class name"RHAbout" and the underline index with the appropriate values.The "set plugins_available 1" command is important. If the variable"plugins_available" is not set to 1 by any of the plug-in codefragments, the Source Window will not have a "PlugIn" menu.This brings us to the "if" statement in the first line. The sampleplug-in is generic, it works with any target. However, a customplug-in may be written for a specific target and be of no genericuse. Furthermore, a target specific plug-in may not even work withother host and target configurations different from the one it wasdesigned for.The Tcl code used by Insight is shared by all configurations (thus thesubdirectory name "shared") and adding a plug-in in the wrongconfiguration could render Insight unusable. To avoid this, a testfor the right configuration must be made so that the plug-in menuentry is only added in the configurations that support it (the"package require" must also be protected).Insight has a global variable which contains configurationinformation. The array "GDBStartup" has the elements:host_name - host configuration triplettarget_name - target configuration tripletUse these values, $GDBStartup(host_name) and $GDBStartup(target_name),to verify that your plug-in code is supported. Don't forget to add"global GDBStartup" before you refer to this array.For instance, if the sample code could only be used with Linux hosts,the sample code above would look like this:# Add your window to the PlugIn menu here# Don't forget to add your packet as wellglobal GDBStartupif {[string first "linux" $GDBStartup(host_name)] != -1} {#package require LIBGDB 1.0package require RHABOUT 1.0$Menu add command Other "About Red Hat" \{ManagedWin::open RHAbout} \-underline 0set plugins_available 1}3) DEVELOPING AN INSIGHT PLUG-INOnly itcl based windows will work. They must also be derived (i.e.,inherit) from the PluginWindow class described in the next section.You must also follow the name conventions described in the CONTRIBUTEfile to avoid class name clashes.The PluginWindow base class has facilities for adding a menu and atoolbar. It already provides the code to deactivate buttons and menuentries when GDB is busy (running the target) and reactivate them whenthe target stops. Your job usually consists of calling a method toredraw your window with updated information when the target stops.You can do this simply by adding a call to this method inside the"stopped" method provided.The Insight Tcl source file gdb/gdbtk/library/interface.tcl and the Cfile gdb/gdbtk/generic/gdbtk-cmds.c contain a (quite volatile) set ofTcl commands that can be used to retrieve information from and aboutthe target. Examples of the use of such commands exist all around theInsight source code and details are usually given near the procedureor function definitions. Please refrain from using commands thatcontrol the target execution or change the GDB state in any way, theyare reserved for use by the Source Window only. Remember, plug-ins area visualization facility only.A special remark is necessary about the gdb_cmd and gdb_immediatecommands. These are deprecated and will disappear (stop working) soon.The GDB maintainers have asked the Insight maintainers to stop usingthe hooks in GDB code that make them possible. Conversion is alreadyunder way. You can use them for prototyping (for now), but beprepared to write Tcl command procedures instead of parsing console textoutput.If you need to issue target-dependent commands to retrieve informationfrom your target (that cannot be retrieved with the standard registerand memory access operations), you can write Tcl command proceduresand add them to your target dependent file enclosed in#ifdef GDBTK#endifThe target dependent Tcl code will move to a subdirectory of gdbtk inthe future, but for now, just add it to your existent target-dependentfile.If you must access gdb functions that are not yet available ingdbtk-cmds.c (or in any of the spun-offs that will soon exist in thegdb/gdbtk/generic directory), consider writing to the Insightmaintainers. They will be able to tell you what command should beimplemented and, if they have the time, add it to Insight. As theymay be busy, consider offering to write the code yourself andsubmitting it for approval (see CONTRIBUTE). You can see how theseTcl command procedures in C are written by looking at what it is donein the gdbtk-cmds.c file and others in the gdb/gdbtk/genericsubdirectory. Again, you can use the gdb_cmd and gdb_immediatecommands to invoke a GDB command line interface command, but they willnot be available for long.Please refer to the sample source code located in the files:gdb/gdbtk/library/plugins/rhabout/rhabout.itclgdb/gdbtk/library/plugins/rhabout/rhabout.cThe comments in these files provide a basic framework for a Insightplug-in.4) THE "PluginWindow" BASE CLASSThe PluginWindow base class provides the following methods:childsite - returns the path of the frame component that can be usedby the plug-in code to pack its custom display components.stopped - called when the target stops. It should be overloaded andcall the plug-in procedure that updates the display. The childversion must call the base class method implementation if it wantsmenu items and/or buttons to be automatically controlled.running - called when GDB becomes busy by running the target. Nocommands shall be issued by a plug-in while GDB is busy. The childversion must call the base class method implementation if it wantsmenu items and/or buttons to be automatically controlled.no_inferior - called when GDB disconnects from the target. Theplug-in may want to forget some context information in this case,depending on the specifics of its implementation. The childversion must call the base class method implementation if it wantsmenu items and/or buttons to be automatically controlled.The PluginWindow base class contains two components which can beoptionally used:menubar - allows a menu to be added to the plug-in window. Thisfacility is implemented by the GDBMenuBar class (gdbmenubar.itcl).toolbar - allows a toolbar to be added to the plug-in window. Thisfacility is implemented by the GDBToolBar class (gdbtoolbar.itcl).Both buttons and menu entries have "class" attributes. Button classesand Menu entry classes are specified when they are created and areused for the automatic control of button and menu entry states.If the class is specified as "None", the menu entry or button willremain always active. The classes "Control" and "Other" follow thefollowing convention:Control Other Stateoff off gdb is busyon on gdb has inferior, and is idleoff on gdb has no inferior, and is idleThe "menubutton" component offers the following supported commands:add menubutton - add a menu button to the window menu bar.add command - add an entry to the last menu created.add separator - add a separator to the last menu created.show - attach the created menu to the window.If the show command is not issued, the plug-in window will have nomenu bar. There are other methods and commands defined in theGDBMenuBar class. They are for Insight internal use only and shouldnot be used by plug-in windows.A menu named "help" will automatically be aligned to the right.The sample plug-in code creates a simple menu with the following commands:$menubar add menubutton file "File" 0$menubar add command None "Close" \[code $this destroy_toplevel] \-underline 1$menubar add menubutton help "Help" 0$menubar add command Other "Help Topics" \{HtmlViewer::open_help index.html} \-underline 0$menubar add separator$menubar add command Other "About GDB..." \{ManagedWin::open About -transient} \-underline 0# The menu only shows up if you do this:$menubar showThe "toolbar" component offers the following supported commands:add button - add a button to the window tool bar.add label - add an label widget to the tool bar.add separator - add a separator to the tool bar.itemconfigure - configure a tool bar element.show - make the toolbar visible.If the show command is not issued, the plug-in window will have notool bar. There are other methods and commands defined in theGDBToolBar class. They are for Insight internal use only and shouldnot be used by plug-in windows.Use the "itemconfigure" command to fill the label elements with thecurrent data as necessary.The sample plug-in code creates a single button with the following commands:$toolbar add button con Other {ManagedWin::open Console} \"Console (Ctrl+N)" -image console_img# The toolbar will only show up if you do this:$toolbar showThe complete Tcl code of the sample plug-in can be found in the filegdb/gdbtk/library/plugins/rhabout/rhabout.itcland the PluginWindow class definition and implementation is in the filegdb/gdbtk/library/pluginwin.itclPlease refer to the filesgdb/gdbtk/library/gdbmenubar.itclandgdb/gdbtk/library/gdbtoolbar.itclfor the current arguments accepted by the menubar and toolbar commandsrespectively.REFERENCES[Smith 2000] Chad Smith, "[incr Tcl/Tk] from the Ground Up".Chapters 9 and 10. Osborne/McGraw-Hill, 2000.[Welch 2000] Brent B. Welch, "Practical Programming in Tcl and Tk",3/e. Chapters 12, 14, 44, 45, 46 and 47. Prentice Hall PTR, 2000.
