This is the mail archive of the insight@sources.redhat.com mailing list for the Insight project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Plug-in C code sample


As pointed by Jim, one can also writes C command procedures (Tcl
commands written
in C) to their plug-ins.

This is important, for instance, if your plug-in needs to be linked and
call the
C API that gets information from your target or something of a sort.

If you think the way things are set up, Tcl is making the bridge between
the standard
Insight/GDB code and the plug-in code.  And there is people that don't
like Tcl... 
go figure.


P.S.: Please check it out and play with it a bit if you can.


	* library/plugins/rhabout.tcl: Add load for optional sample C command 
	procedure.
	* library/plugins/rhabout/rhabout.itcl (constructor): Try calling
	optional sample C command procedure rhabout_extra_text.
	* library/plugins/rhabout/rhabout.c: New file. Implement an example
	plug-in shared library with a sample C command procedure.
	* library/plugins/rhabout/Makefile: New file. Makefile for the sample
	shared library above (Linux only).

-- 
Fernando Nasser
Red Hat Canada Ltd.                     E-Mail:  fnasser@redhat.com
2323 Yonge Street, Suite #300
Toronto, Ontario   M4P 2C9


$ cat library/plugins/rhabout.tcl
package provide RHABOUT 1.0
set dirname [file dirname [info script]]
lappend auto_path [file join $dirname rhabout]
catch {load [file join $dirname rhabout rhabout.so]}


$ cat library/plugins/rhabout/rhabout.itcl
class RHAbout {
  inherit ManagedWin ModalDialog
  constructor {args} {
    global gdb_ImageDir
    set f [frame $itk_interior.f]
    label $f.image1 -bg white -image \
      [image create photo -file [file join $gdb_ImageDir insight.gif]]

    # Here we call an interface function provided by GDBTCL
    set text [gdb_cmd {show version}]

    # Here we call a command procedure that we created, if it exists
    catch {append text [rhabout_extra_text]}

    message $f.m -bg white -fg black -text $text -aspect 500 -relief
flat
    pack $f.image1 $f.m $itk_interior.f -fill both -expand yes
    pack  $itk_interior
    bind $f.image1 <1> [code $this unpost]
    bind $f.m <1> [code $this unpost]
    window_name "About Cygnus Insight"
  }

  # Don't quit if this is the last window.  The only way that this can
  # happen is if we are the splash screen. 

  method quit_if_last {} { 
    return 0
  }

}


$ cat library/plugins/rhabout/rhabout.c
/* Sample command procedure library for a plug-in. */

/* You have to include the Tcl headers, of course. */
#include <tcl.h>

/* Define the functions that implement your commands as required by Tcl
*/

int extra_text (ClientData clientData,
                Tcl_Interp *interp,
                int argc, char *argv[]);

/* Here you actually do whatever you want, like calling your target 
   libraries etc.  Here we just return a string. */

int
extra_text (ClientData clientData,
                Tcl_Interp *interp,
                int argc, char *argv[])
{
  interp->result = "\nThis is a sample plug-in\n";
  return TCL_OK;
}

/* Initialization function required in Tcl libraries. */

int
Rhabout_Init (Tcl_Interp *interp)
{
  /* Register your command as a Tcl command with this interpreter. */
  Tcl_CreateCommand (interp, "rhabout_extra_text", extra_text,
                     (ClientData) NULL, (Tcl_CmdDeleteProc *) NULL);

  return TCL_OK;
}



$ cat library/plugins/rhabout/Makefile
TCL_CFLAGS = -I/home/fnasser/DEVO/insight-sourceware/src/tcl/generic
TCL =  -L/home/fnasser/BUILD/insight-sourceware/native/tcl/unix -ltcl8.0

PRE=
POS= ".so"

rhabout: rhabout.c
	gcc -fPIC $(TCL_CFLAGS) -I. -o rhabout.o -c rhabout.c
	gcc -shared -o rhabout$(POS) rhabout.o $(TCL)

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]