Thu Aug 7 13:39:31 1997 Geoffrey Noer <noer@cygnus.com>
[deliverable/binutils-gdb.git] / gdb / gdbtk.c
index fc2b0deca1c77a317f7a3da41271720068535748..13e8959bb0f75e6fc7e7e65affa61cd9de6050d7 100644 (file)
@@ -29,7 +29,14 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
 #include "target.h"
 #include <tcl.h>
 #include <tk.h>
-/* #include <itcl.h> */
+#include <itcl.h> 
+#include <tix.h> 
+
+#ifdef IDE
+#include "event.h"
+#include "idetcl.h"
+#endif
+
 #ifdef ANSI_PROTOTYPES
 #include <stdarg.h>
 #else
@@ -69,7 +76,7 @@ static void gdbtk_flush PARAMS ((FILE *));
 static void gdbtk_fputs PARAMS ((const char *, FILE *));
 static int gdbtk_query PARAMS ((const char *, va_list));
 static char *gdbtk_readline PARAMS ((char *));
-static void gdbtk_init PARAMS ((void));
+static void gdbtk_init PARAMS ((char *));
 static void tk_command_loop PARAMS ((void));
 static void gdbtk_call_command PARAMS ((struct cmd_list_element *, char *, int));
 static int gdbtk_wait PARAMS ((int, struct target_waitstatus *));
@@ -127,9 +134,11 @@ static int running_now;
 
 static int disassemble_from_exec = -1;
 
-static char *Gdbtk_Library;
+#ifndef _WIN32
 
-/* Supply malloc calls for tcl/tk.  */
+/* Supply malloc calls for tcl/tk.  We do not want to do this on
+   Windows, because Tcl_Alloc is probably in a DLL which will not call
+   the mmalloc routines.  */
 
 char *
 Tcl_Alloc (size)
@@ -153,6 +162,8 @@ Tcl_Free(ptr)
   free (ptr);
 }
 
+#endif /* _WIN32 */
+
 static void
 null_routine(arg)
      int arg;
@@ -193,7 +204,6 @@ gdbtk_fputs (ptr, stream)
      const char *ptr;
      FILE *stream;
 {
-
   if (result_ptr)
     Tcl_DStringAppend (result_ptr, (char *)ptr, -1);
   else
@@ -205,7 +215,7 @@ gdbtk_fputs (ptr, stream)
       Tcl_DStringAppend (&str, "gdbtk_tcl_fputs", -1);
       Tcl_DStringAppendElement (&str, (char *)ptr);
 
-      Tcl_Eval (interp, Tcl_DStringValue (&str));
+      Tcl_Eval (interp, Tcl_DStringValue (&str)); 
       Tcl_DStringFree (&str);
     }
 }
@@ -376,7 +386,7 @@ gdb_get_breakpoint_info (clientData, interp, argc, argv)
                              "longjmp", "longjmp resume", "step resume",
                              "through sigtramp", "watchpoint scope",
                              "call dummy" };
-  static char *bpdisp[] = {"delete", "disable", "donttouch"};
+  static char *bpdisp[] = {"delete", "delstop", "disable", "donttouch"};
   struct command_line *cmd;
   int bpnum;
   struct breakpoint *b;
@@ -425,13 +435,16 @@ breakpoint_notify(b, action)
 {
   char buf[100];
   int v;
+  struct symtab_and_line sal;
 
   if (b->type != bp_breakpoint)
     return;
 
   /* We ensure that ACTION contains no special Tcl characters, so we
      can do this.  */
-  sprintf (buf, "gdbtk_tcl_breakpoint %s %d", action, b->number);
+  sal = find_pc_line (b->address, 0);
+  sprintf (buf, "gdbtk_tcl_breakpoint %s %d 0x%lx %d {%s}", action, b->number, 
+          (long)b->address, sal.line, symtab_to_filename (sal.symtab));
 
   v = Tcl_Eval (interp, buf);
 
@@ -515,7 +528,9 @@ gdb_loc (clientData, interp, argc, argv)
 
   dsprintf_append_element (result_ptr, "%d", sal.line); /* line number */
 
-  dsprintf_append_element (result_ptr, "0x%s", paddr_nz(pc)); /* PC */
+  dsprintf_append_element (result_ptr, "0x%s", paddr_nz(pc)); /* PC in current frame */
+
+  dsprintf_append_element (result_ptr, "0x%s", paddr_nz(stop_pc)); /* Real PC */
 
   return TCL_OK;
 }
@@ -806,6 +821,26 @@ gdb_cmd (clientData, interp, argc, argv)
   return TCL_OK;
 }
 
+/* Client of call_wrapper - this routine performs the actual call to
+   the client function. */
+
+struct wrapped_call_args
+{
+  Tcl_Interp *interp;
+  Tcl_CmdProc *func;
+  int argc;
+  char **argv;
+  int val;
+};
+
+static int
+wrapped_call (args)
+     struct wrapped_call_args *args;
+{
+  args->val = (*args->func) (args->func, args->interp, args->argc, args->argv);
+  return 1;
+}
+
 /* This routine acts as a top-level for all GDB code called by tcl/Tk.  It
    handles cleanups, and calls to return_to_top_level (usually via error).
    This is necessary in order to prevent a longjmp out of the bowels of Tk,
@@ -820,26 +855,22 @@ call_wrapper (clientData, interp, argc, argv)
      int argc;
      char *argv[];
 {
-  int val;
-  struct cleanup *saved_cleanup_chain;
-  Tcl_CmdProc *func;
-  jmp_buf saved_error_return;
+  struct wrapped_call_args wrapped_args;
   Tcl_DString result, *old_result_ptr;
 
   Tcl_DStringInit (&result);
   old_result_ptr = result_ptr;
   result_ptr = &result;
 
-  func = (Tcl_CmdProc *)clientData;
-  memcpy (saved_error_return, error_return, sizeof (jmp_buf));
+  wrapped_args.func = (Tcl_CmdProc *)clientData;
+  wrapped_args.interp = interp;
+  wrapped_args.argc = argc;
+  wrapped_args.argv = argv;
+  wrapped_args.val = 0;
 
-  saved_cleanup_chain = save_cleanups ();
-
-  if (!setjmp (error_return))
-    val = func (clientData, interp, argc, argv);
-  else
+  if (!catch_errors (wrapped_call, &wrapped_args, "", RETURN_MASK_ALL))
     {
-      val = TCL_ERROR;         /* Flag an error for TCL */
+      wrapped_args.val = TCL_ERROR;    /* Flag an error for TCL */
 
       gdb_flush (gdb_stderr);  /* Flush error output */
 
@@ -853,16 +884,10 @@ call_wrapper (clientData, interp, argc, argv)
       Tcl_Eval (interp, "gdbtk_tcl_idle");
     }
 
-  do_cleanups (ALL_CLEANUPS);
-
-  restore_cleanups (saved_cleanup_chain);
-
-  memcpy (error_return, saved_error_return, sizeof (jmp_buf));
-
   Tcl_DStringResult (interp, &result);
   result_ptr = old_result_ptr;
 
-  return val;
+  return wrapped_args.val;
 }
 
 static int
@@ -892,7 +917,10 @@ gdb_stop (clientData, interp, argc, argv)
      int argc;
      char *argv[];
 {
-  target_stop ();
+  if (target_stop)
+    target_stop ();
+  else
+    quit_flag = 1; /* hope something sees this */
 
   return TCL_OK;
 }
@@ -1254,8 +1282,8 @@ gdbtk_call_command (cmdblk, arg, from_tty)
       running_now = 1;
       Tcl_Eval (interp, "gdbtk_tcl_busy");
       (*cmdblk->function.cfunc)(arg, from_tty);
-      Tcl_Eval (interp, "gdbtk_tcl_idle");
       running_now = 0;
+      Tcl_Eval (interp, "gdbtk_tcl_idle");
     }
   else
     (*cmdblk->function.cfunc)(arg, from_tty);
@@ -1276,13 +1304,19 @@ tk_command_loop ()
 }
 
 static void
-gdbtk_init ()
+gdbtk_init ( argv0 )
+     char *argv0;
 {
   struct cleanup *old_chain;
   char *lib, *gdbtk_lib, gdbtk_lib_tmp[1024],gdbtk_file[128];
   int i, found_main;
   struct sigaction action;
   static sigset_t nullsigmask = {0};
+#ifdef IDE
+  struct ide_event_handle *h;
+  const char *errmsg;
+  char *libexecdir;
+#endif 
 
   /* If there is no DISPLAY environment variable, Tk_Init below will fail,
      causing gdb to abort.  If instead we simply return here, gdb will
@@ -1296,7 +1330,7 @@ gdbtk_init ()
   old_chain = make_cleanup (cleanup_init, 0);
 
   /* First init tcl and tk. */
-
+  Tcl_FindExecutable (argv0); 
   interp = Tcl_CreateInterp ();
 
   if (!interp)
@@ -1305,14 +1339,53 @@ gdbtk_init ()
   if (Tcl_Init(interp) != TCL_OK)
     error ("Tcl_Init failed: %s", interp->result);
 
-  /*
-    if (Itcl_Init(interp) == TCL_ERROR) 
-  error ("Itcl_Init failed: %s", interp->result);
-    */
-  
   if (Tk_Init(interp) != TCL_OK)
     error ("Tk_Init failed: %s", interp->result);
 
+  if (Itcl_Init(interp) == TCL_ERROR) 
+    error ("Itcl_Init failed: %s", interp->result);
+
+  if (Tix_Init(interp) != TCL_OK)
+    error ("Tix_Init failed: %s", interp->result);
+
+#ifdef IDE
+  /* Initialize the Paths variable.  
+  if (ide_initialize_paths (interp, "gdb") != TCL_OK)
+    return (TCL_ERROR);
+    */
+  /* Find the directory where we expect to find idemanager.  We ignore
+     errors since it doesn't really matter if this fails.  */
+  libexecdir = Tcl_GetVar2 (interp, "Paths", "libexecdir", TCL_GLOBAL_ONLY);
+
+  IluTk_Init ();
+
+  h = ide_event_init_client (&errmsg, libexecdir);
+  if (h == NULL)
+    {
+      Tcl_AppendResult (interp, "can't initialize event system: ", errmsg,
+                       (char *) NULL);
+      fprintf(stderr, "WARNING: ide_event_init_client failed: %s\n", interp->result);
+    }
+  else 
+    {
+      if (ide_create_tclevent_command (interp, h) != TCL_OK)
+       error ("ide_create_tclevent_command failed: %s", interp->result);
+      if (ide_create_edit_command (interp, h) != TCL_OK)
+       error ("ide_create_edit_command failed: %s", interp->result);
+      
+      if (ide_create_property_command (interp, h) != TCL_OK)
+       error ("ide_create_property_command failed: %s", interp->result);
+      
+      /*
+       if (ide_initialize (interp, "gdb") != TCL_OK)
+       error ("ide_initialize failed: %s", interp->result);
+      */
+    }
+  Tcl_SetVar (interp, "GDBTK_IDE", "1", 0);
+#else
+  Tcl_SetVar (interp, "GDBTK_IDE", "0", 0);
+#endif /* IDE */
+
   Tcl_CreateCommand (interp, "gdb_cmd", call_wrapper, gdb_cmd, NULL);
   Tcl_CreateCommand (interp, "gdb_loc", call_wrapper, gdb_loc, NULL);
   Tcl_CreateCommand (interp, "gdb_path_conv", call_wrapper, gdb_path_conv, NULL);
@@ -1424,7 +1497,7 @@ gdbtk_init ()
            }
        }
      } 
-  while (lib = strtok (NULL, ":"));
+  while ((lib = strtok (NULL, ":")) != NULL);
   
   if (!found_main)
     {
This page took 0.026177 seconds and 4 git commands to generate.