Beginnings of template debugging tests.
[deliverable/binutils-gdb.git] / gdb / gdbtk.c
index e93471ef42d4019d94165c1c7ad27d8a6bb961f9..c2a1e383aa620b118a2fb41a8b495f8132800f94 100644 (file)
@@ -25,20 +25,11 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
 #include "symfile.h"
 #include "objfiles.h"
 #include "target.h"
-#include <sys/types.h>
-#include <sys/time.h>
-#include <sys/param.h>
-#include <varargs.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <sys/filio.h>
-#include <setjmp.h>
-#include <signal.h>
-#include <sys/errno.h>
-#include <termios.h>
-#include <string.h>
 #include <tcl.h>
 #include <tk.h>
+#include <varargs.h>
+#include <signal.h>
+#include <fcntl.h>
 #include <unistd.h>
 
 /* Non-zero means that we're doing the gdbtk interface. */
@@ -252,13 +243,7 @@ gdb_loc (clientData, interp, argc, argv)
 
   if (argc == 1)
     {
-      struct frame_info *frame;
-      struct symbol *func;
-
-      frame = get_frame_info (selected_frame);
-
-      pc = frame ? frame->pc : stop_pc;
-
+      pc = selected_frame ? selected_frame->pc : stop_pc;
       sal = find_pc_line (pc, 0);
     }
   else if (argc == 2)
@@ -306,6 +291,87 @@ gdb_loc (clientData, interp, argc, argv)
   return TCL_OK;
 }
 \f
+/* This implements the TCL command `gdb_sourcelines', which returns a list of
+   all of the lines containing executable code for the specified source file
+   (ie: lines where you can put breakpoints). */
+
+static int
+gdb_sourcelines (clientData, interp, argc, argv)
+     ClientData clientData;
+     Tcl_Interp *interp;
+     int argc;
+     char *argv[];
+{
+  struct symtab *symtab;
+  struct linetable_entry *le;
+  int nlines;
+  char buf[100];
+
+  if (argc != 2)
+    {
+      Tcl_SetResult (interp, "wrong # args", TCL_STATIC);
+      return TCL_ERROR;
+    }
+
+  symtab = lookup_symtab (argv[1]);
+
+  if (!symtab)
+    {
+      Tcl_SetResult (interp, "No such file", TCL_STATIC);
+      return TCL_ERROR;
+    }
+
+  /* If there's no linetable, or no entries, then we are done. */
+
+  if (!symtab->linetable
+      || symtab->linetable->nitems == 0)
+    {
+      Tcl_AppendElement (interp, "");
+      return TCL_OK;
+    }
+
+  le = symtab->linetable->item;
+  nlines = symtab->linetable->nitems;
+
+  for (;nlines > 0; nlines--, le++)
+    {
+      /* If the pc of this line is the same as the pc of the next line, then
+        just skip it.  */
+      if (nlines > 1
+         && le->pc == (le + 1)->pc)
+       continue;
+
+      sprintf (buf, "%d", le->line);
+      Tcl_AppendElement (interp, buf);
+    }
+
+  return TCL_OK;
+}
+\f
+/* This implements the TCL command `gdb_regnames', which returns a list of
+   all of the register names. */
+
+static int
+gdb_regnames (clientData, interp, argc, argv)
+     ClientData clientData;
+     Tcl_Interp *interp;
+     int argc;
+     char *argv[];
+{
+  int i;
+
+  if (argc != 1)
+    {
+      Tcl_SetResult (interp, "wrong # args", TCL_STATIC);
+      return TCL_ERROR;
+    }
+
+  for (i = 0; i < NUM_REGS; i++)
+    Tcl_AppendElement (interp, reg_names[i]);
+
+  return TCL_OK;
+}
+\f
 static int
 gdb_cmd_stub (cmd)
      char *cmd;
@@ -383,12 +449,7 @@ gdb_stop (clientData, interp, argc, argv)
      int argc;
      char *argv[];
 {
-  extern pid_t inferior_process_group;
-
-  /* XXX - This is WRONG for remote targets.  Probably need a target vector
-     entry to do this right.  */
-
-  kill (-inferior_process_group, SIGINT);
+  target_stop ();
 }
 
 \f
@@ -501,6 +562,8 @@ gdbtk_init ()
 
   Tcl_CreateCommand (interp, "gdb_cmd", gdb_cmd, NULL, NULL);
   Tcl_CreateCommand (interp, "gdb_loc", gdb_loc, NULL, NULL);
+  Tcl_CreateCommand (interp, "gdb_sourcelines", gdb_sourcelines, NULL, NULL);
+  Tcl_CreateCommand (interp, "gdb_regnames", gdb_regnames, NULL, NULL);
   Tcl_CreateCommand (interp, "gdb_listfiles", gdb_listfiles, NULL, NULL);
   Tcl_CreateCommand (interp, "gdb_stop", gdb_stop, NULL, NULL);
 
@@ -514,10 +577,9 @@ gdbtk_init ()
   if (Tcl_EvalFile (interp, gdbtk_filename) != TCL_OK)
     error ("Failure reading %s: %s", gdbtk_filename, interp->result);
 
-  /* XXX - Get the file descriptor for the network socket.  This is not Kosher
-     as it involves looking at data private to Xlib.  */
+  /* Get the file descriptor for the X server */
 
-  x_fd = Tk_Display (mainWindow) -> fd;
+  x_fd = ConnectionNumber (Tk_Display (mainWindow));
 
   /* Setup for I/O interrupts */
 
This page took 0.025707 seconds and 4 git commands to generate.