* Makefile.in (VERSION): Roll to 4.6.8.
[deliverable/binutils-gdb.git] / gdb / energize.c
index 80048d472450def55cfeefd12501a3c11799c0b3..b9bce2fb1faddad992364f6ad4b40826939453be 100644 (file)
@@ -24,14 +24,15 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
 #include "bfd.h"
 #include "symfile.h"
 #include "objfiles.h"
+#include "target.h"
 #include <sys/types.h>
 #include <sys/time.h>
 #include <sys/param.h>
-#include <connection.h>
-#include <genericreq.h>
-#include <debuggerreq.h>
-#include <debuggerconn.h>
-#include <ttyconn.h>
+#include "energize/connection.h"
+#include "energize/genericreq.h"
+#include "energize/debuggerreq.h"
+#include "energize/debuggerconn.h"
+#include "energize/ttyconn.h"
 #include <varargs.h>
 #include <sys/stat.h>
 #ifdef USG
@@ -44,10 +45,17 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
 #include <sys/errno.h>
 #include <termios.h>
 #include <string.h>
+#ifdef NCR486
+#include <sys/stropts.h>
+#endif
 
 /* Non-zero means that we're doing the energize interface. */
 int energize = 0;
 
+/* Non-zero means we are reloading breakpoints, etc from the
+   Energize kernel, and we should suppress various messages */
+static int energize_reloading = 0;
+
 /* Connection block for debugger<=>kernel communications. */
 static Connection *conn = 0;
 
@@ -69,7 +77,8 @@ extern int pgrp_inferior;
 
 extern char *source_path;
 
-char **pprompt;                        /* Pointer to pointer to prompt */
+/* The name of the executable file */
+static char *exec_file;
 
 /* Tell energize_command_line_input() where to get its text from */
 static int doing_breakcommands_message = 0;
@@ -82,6 +91,8 @@ static int command_line_length = 0;
 #define KERNEL_EVENT 1
 #define PTY_EVENT 2
 
+static void execute_command_1();
+
 \f
 /* This routine redirects the output of fputs_filtered to the kernel so that
    the user can see what's going on in his debugger window. */
@@ -143,14 +154,15 @@ pty_to_kernel()
 
       if (cc == 0
          || (cc < 0
-             && errno == EWOULDBLOCK))
+             && (errno == EWOULDBLOCK
+                 || errno == EAGAIN)))
        break;
 
       if (cc < 0)
        {
          close(inferior_pty);
          inferior_pty = -1;
-         perror("pty read error");
+         perror("pty_to_kernel: pty read error");
          break;
        }
 
@@ -178,7 +190,7 @@ kernel_to_pty(data, len)
        {
          close(inferior_pty);
          inferior_pty = -1;
-         perror("pty write error");
+         perror("kernel_to_pty: pty write error");
          return;
        }
       printf("Couldn't write all the data to the pty, wanted %d, got %d\n",
@@ -199,6 +211,9 @@ full_filename(symtab)
   if (symtab->fullname)
     return savestring(symtab->fullname, strlen(symtab->fullname));
 
+  if (symtab->filename[0] == '/')
+    return savestring(symtab->filename, strlen(symtab->filename));
+
   if (symtab->dirname)
     pathlen = strlen(symtab->dirname);
   else
@@ -304,18 +319,52 @@ send_stack_info()
   stack_info_valid = 1;
 }
 
+/* Tell the Energize server about the file and line # that corresponds to pc,
+   and which stack frame level that pc corresponds to. */
+
+static void
+send_location(pc, frame_level)
+     CORE_ADDR pc;
+     int frame_level;
+{
+  char *funcname, *filename;
+  struct symtab_and_line sal;
+  struct symbol *symbol;
+
+  sal = find_pc_line(pc, 0);
+  symbol = find_pc_function(pc);
+
+  funcname = symbol ? symbol->name : "";
+  filename = full_filename(sal.symtab);
+
+  send_stack_info();
+
+  CVWriteStackFrameInfo(conn,
+                       instance_id,
+                       sal.line,
+                       CFileLinePos,
+                       frame_level,
+                       funcname,
+                       filename,
+                       ""      /* XXX ? transcript */
+                       );
+  if (filename)
+    free(filename);
+}
+
 /* Tell the kernel where we are in the program, and what the stack looks like.
    */
 
 static void
 send_status()
-{
-  static int linecount = 48;
-  struct symtab_and_line sal;
+{ 
+  char *funcname;
   struct symbol *symbol;
-  char *funcname, *filename;
   static int sent_prog_inst = 0;
 
+  symbol = find_pc_function(stop_pc);
+  funcname = symbol ? symbol->name : "";
+
   if (!has_run)
     return;
 
@@ -328,12 +377,6 @@ send_status()
       return;
     }
 
-  sal = find_pc_line(stop_pc, 0);
-  symbol = find_pc_function(stop_pc);
-
-  funcname = symbol ? symbol->name : "";
-  filename = full_filename(sal.symtab);
-
   if (!sent_prog_inst)
     {
       sent_prog_inst = 1;
@@ -346,17 +389,8 @@ send_status()
                                 );
     }
 
-  send_stack_info();
-
-  CVWriteStackFrameInfo(conn,
-                       instance_id,
-                       sal.line,
-                       CFileLinePos,
-                       0,      /* XXX - frame # */
-                       funcname,
-                       filename,
-                       ""      /* XXX ? transcript */
-                       );
+  send_location(stop_pc,
+               selected_frame_level); /* Had better be 0! */
 
   CVWriteProgramStoppedInfo(conn,
                            instance_id,
@@ -366,8 +400,6 @@ send_status()
                            ""  /* XXX ? transcript */
                            );
 
-  if (filename)
-    free(filename);
 }
 
 /* Call this to output annotated function names.  Names will be demangled if
@@ -390,7 +422,10 @@ energize_annotate_function(funcname, arg_mode, level)
       demangled_name = cplus_demangle(funcname, arg_mode);
 
       if (demangled_name)
-       funcname = demangled_name;
+       {
+         funcname = demangled_name;
+         printf_filtered("'");
+       }
     }
 
   send_stack_info();
@@ -403,7 +438,10 @@ energize_annotate_function(funcname, arg_mode, level)
                            funcname);
 
   if (demangled_name)
-    free(demangled_name);
+    {
+      free(demangled_name);
+      printf_filtered("'");
+    }
 }
 
 /* Call this just prior to printing out the name & value of a variable.  This
@@ -635,8 +673,8 @@ execute_command_1(va_alist)
   va_list args;
 
   va_start(args);
-
   echo = va_arg(args, int);
+
   queue = va_arg(args, int);
   cmd = va_arg(args, char *);
 
@@ -717,7 +755,9 @@ breakpoint_notify(b, action)
   char *filename;
   char *included_in_filename = "";
 
-  if (!energize)
+  if (!energize
+      || energize_reloading)   /* Don't notify energize about breakpoint changes, as it's about to send us
+                                  a new bunch.  */
     return;
 
   if (b->type != bp_breakpoint)
@@ -789,6 +829,7 @@ energize_ignore_breakpoint(b)
 \f
 /* Open up a pty and its associated tty.  Return the fd of the tty. */
 
+#ifndef NCR486
 static void
 getpty()
 {
@@ -809,7 +850,11 @@ getpty()
        continue;
       sprintf(dev, "/dev/tty%c%x", n/16 + 'p', n%16);
       ttyfd = open(dev, O_RDWR);
-      if (ttyfd < 0) {close(ptyfd); continue;}
+      if (ttyfd < 0)
+       {
+         close(ptyfd);
+         continue;
+       }
 
       /* Setup pty for non-blocking I/O.  Also make it give us a SIGIO when
         there's data available.  */
@@ -829,6 +874,81 @@ getpty()
 
   error ("getpty: can't get a pty\n");
 }
+#endif
+/* Alternate getpty for NCRs */
+
+#ifdef NCR486 /* LTL */
+#define MAX_PTM_TRY 16
+#define MAX_GRANTPT_TRY 4
+static void
+getpty()
+{
+  char *slavename;
+  extern char *ptsname();
+  int j, i;
+  int n, mfd, sfd;
+  struct stat statbuf; 
+  struct termios termios;
+
+  mfd = open("/dev/ptmx", O_RDWR); /* get the master */
+  if (mfd < 0)
+    error ("getpty: can't locate master\n");
+
+  if (grantpt(mfd) < 0)        /* get a slave */
+    error ("getpty: can't acquire slave");
+
+  unlockpt(mfd);
+
+  slavename = ptsname(mfd); /* get the slave device name */
+  if (!slavename)
+    error ("getpty: can't get a pts\n");
+
+  /* Drop controlling tty, become pgrp master */
+
+  if (setpgid(0, getppid()) == -1)
+    perror("setpgid() failed: ");
+
+  if (setsid() == -1)
+    perror("setsid() failed: ");
+
+  sfd = open(slavename, O_RDWR);
+  if (sfd < 0)
+    {
+      close(mfd);
+      error ("getpty: can't open slave\n");
+    }
+
+
+  if (ioctl(sfd, I_PUSH, "ptem")) perror ("getpty: ioctl I_PUSH fails");
+  if (ioctl(sfd, I_PUSH, "ldterm")) perror ("getpty: ioctl I_PUSH fails");
+
+  /* setup mty for non-blocking I/O. */
+
+  n = fcntl(mfd, F_GETFL);
+  if (n < 0)
+    perror ("getpty: fcntl F_GETFL failed");
+
+  if (fcntl(mfd, F_SETFL, n|O_NDELAY) <0)
+    perror("getpty: fcntl F_SETFL failed");
+
+  /* set up for async i/o - V.4 will send SIGPOLL when data available */
+
+  if (ioctl (mfd,  I_SETSIG, S_INPUT|S_RDNORM) < 0)
+    perror ("getpty: ioctl I_SETSIG failed");
+
+  if (tcgetattr(sfd, &termios))
+    perror("getpty: tcgetattr fails");
+  termios.c_oflag &= ~OPOST;   /* no post-processing */
+  if (tcsetattr(sfd, TCSANOW, &termios))
+    perror("getpty: tcsetattr fails");
+
+  inferior_pty=mfd;
+  inferior_tty=sfd;
+
+  return;
+} 
+
+#endif /* NCR486 */
 \f
 /* Examine a protocol packet from the driver. */
 
@@ -873,7 +993,7 @@ kernel_dispatch(queue)
          }
          break;
        default:
-         fprintf(stderr, "Unknown request type = %d\n",
+         fprintf(stderr, "Unknown Tty request type = %d\n",
                  req->head.reqType);
          break;
        }
@@ -980,7 +1100,7 @@ kernel_dispatch(queue)
          }
          break;
        case StopRType:
-         killpg(pgrp_inferior, SIGINT);
+         kill(-pgrp_inferior, SIGINT);
          break;
        case UserInputRType:
          {
@@ -1148,8 +1268,41 @@ kernel_dispatch(queue)
                              req->setValue.value.text);
          }
          break;
+       case DynamicLoadRType:
+         {
+           char *filename;
+
+           filename = req->dynamicLoad.filenames.byteLen ?
+             req->dynamicLoad.filenames.text : exec_file;
+
+           switch (req->dynamicLoad.request->action)
+             {
+             case CDynamicLoadUpdateSymtab:
+               energize_reloading = 1;
+               execute_command_1(1, queue, "set confirm no");
+               execute_command_1(1, queue, "delete");
+/*             execute_command_1(1, queue, "set $bpnum=1");*/ /* Use this to reset breakpoint #s */
+               execute_command_1(1, queue, "exec-file %s", filename);
+               execute_command_1(1, queue, "symbol-file %s", filename);
+               execute_command_1(1, queue, "set confirm yes");
+               energize_reloading = 0;
+               break;
+             case CDynamicLoadRestoreStart:
+               break;
+             case CDynamicLoadRestoreEnd: /* Not used anymore??? */
+               printf_filtered("\n[Target has changed, automatic restoration of state has been done.]\n");
+               print_prompt();
+               break;
+             default:
+               printf_filtered("DynamicLoadRType: unknown action=%d, filename=%s\n",
+                               req->dynamicLoad.request->action,
+                               req->dynamicLoad.filenames.text);
+               break;
+             }
+         }
+         break;
        default:
-         fprintf(stderr, "Unknown request type = %d\n",
+         fprintf(stderr, "Unknown Debugger request type = %d\n",
                  req->head.request->reqType);
          break;
        }
@@ -1181,8 +1334,9 @@ wait_for_events(poll)
   do
     {
       FD_SET(kerfd, &readfds);
-      if (inferior_pty > 0)
-       FD_SET(inferior_pty, &readfds);
+
+      FD_SET(inferior_pty, &readfds);
+
       if (poll)
        numfds = select(sizeof(readfds)*8, &readfds, 0, 0, &tv);
       else
@@ -1190,6 +1344,9 @@ wait_for_events(poll)
     }
   while (numfds <= 0 && !poll);
 
+  if (numfds == 0)
+    return 0;
+
   if (FD_ISSET(inferior_pty, &readfds))
     eventmask |= PTY_EVENT;
 
@@ -1295,6 +1452,8 @@ energize_initialize(energize_id, execarg)
 
   if (!execarg) execarg = "";
 
+  exec_file = strdup(execarg); /* Save for later */
+
   printf("\ngdb-debugger pid=%d\n", getpid()); /* XXX - debugging only */
   
   /* First establish the connection with the kernel. */
@@ -1307,9 +1466,16 @@ energize_initialize(energize_id, execarg)
 
   /* Setup for I/O interrupts when appropriate. */
 
+  signal(SIGIO, SIG_IGN);
+
+#ifdef NCR486
+  if (ioctl (kerfd,  I_SETSIG, S_INPUT|S_RDNORM) < 0)
+    perror ("getpty: ioctl I_SETSIG failed");
+#else
   n = fcntl(kerfd, F_GETFL, 0);
   fcntl(kerfd, F_SETFL, n|FASYNC);
-  fcntl(kerfd, F_SETOWN, getpid());
+  fcntl(kerfd, F_SETOWN, getpid()); 
+#endif
 
   /* Setup connection buffering. */
 
@@ -1349,7 +1515,7 @@ energize_initialize(energize_id, execarg)
 
   req = CWriteTtyRequest (conn, RunningProgramRType);
   req->runningprogram.argc = 8;
-  getwd (pathname);
+  getcwd (pathname, MAXPATHLEN);
   CWriteVstring0 (conn, pathname);
 
   CWriteVstring0 (conn, "0");
@@ -1374,9 +1540,11 @@ energize_initialize(energize_id, execarg)
   /* Tell the rest of the world that Energize is now set up. */
   energize = 1;
 
-  setsid();                    /* Drop controlling tty, become pgrp master */
   getpty();                    /* Setup the pty */
-  dup2(inferior_tty, 0);       /* Attach all GDB I/O to the pty */
+
+  /* Attach all GDB I/O to the pty */
+
+  dup2(inferior_tty, 0);
   dup2(inferior_tty, 1);
   dup2(inferior_tty, 2);
 }
@@ -1408,6 +1576,11 @@ energize_call_command(cmdblk, arg, from_tty)
   else
     (*cmdblk->function.cfunc)(arg, from_tty);
 
+  if (strcmp(cmdblk->name, "up") == 0
+      || strcmp(cmdblk->name, "down") == 0
+      || strcmp(cmdblk->name, "frame") == 0)
+    send_location(get_frame_info(selected_frame)->pc,
+                 selected_frame_level);
   print_prompt();
 }
 
@@ -1443,15 +1616,50 @@ energize_wait(status)
      int *status;
 {
   int pid;
+  struct sigaction action;
+  static sigset_t nullsigmask = {0};
+
+  if (!energize)
+    return target_wait(status);
+
+#ifdef NCR486
+  action.sa_handler = iosig;
+  action.sa_mask = nullsigmask;
+  action.sa_flags = SA_RESTART;
+  sigaction(SIGIO, &action, NULL);
+#else
+  signal(SIGIO, iosig);
+#endif
+
+  pid = target_wait(status);
+
+  signal(SIGIO, SIG_IGN);
+  return pid;
+}
+
+int
+energize_shell_wait(status)
+     int *status;
+{
+  int pid;
+  struct sigaction action;
+  static sigset_t nullsigmask = {0};
 
   if (!energize)
     return wait(status);
 
+#ifdef NCR486
+  action.sa_handler = iosig;
+  action.sa_mask = nullsigmask;
+  action.sa_flags = SA_RESTART;
+  sigaction(SIGIO, &action, NULL);
+#else
   signal(SIGIO, iosig);
+#endif
 
   pid = wait(status);
 
-  signal(SIGIO, SIG_DFL);
+  signal(SIGIO, SIG_IGN);
   return pid;
 }
 
This page took 0.030168 seconds and 4 git commands to generate.