import gdb-1999-06-28 snapshot
[deliverable/binutils-gdb.git] / gdb / remote.c
index 9f84f5df82b6bddec2d9825a0a33097aab7adfa1..8fadca8c4159630b4e31261a805864ee3311379e 100644 (file)
@@ -141,6 +141,17 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
                                        targets.
        or...           XAA             The process terminated with signal
                                        AA.
+       or (obsolete)   NAA;tttttttt;dddddddd;bbbbbbbb
+                                       AA = signal number
+                                       tttttttt = address of symbol "_start"
+                                       dddddddd = base of data section
+                                       bbbbbbbb = base of bss  section.
+                                       Note: only used by Cisco Systems 
+                                       targets.  The difference between this
+                                       reply and the "qOffsets" query is that
+                                       the 'N' packet may arrive spontaneously
+                                       whereas the 'qOffsets' is a query
+                                       initiated by the host debugger.
         or...           OXX..XX        XX..XX  is hex encoding of ASCII data. This
                                        can happen at any time while the 
                                        program is running and the debugger 
@@ -213,6 +224,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
 
 /* Prototypes for local functions */
 
+static void build_remote_gdbarch_data PARAMS ((void));
+
 static int remote_write_bytes PARAMS ((CORE_ADDR memaddr,
                                       char *myaddr, int len));
 
@@ -291,6 +304,10 @@ static void init_remote_ops PARAMS ((void));
 
 static void init_extended_remote_ops PARAMS ((void));
 
+static void init_remote_cisco_ops PARAMS ((void));
+
+static struct target_ops remote_cisco_ops;
+
 static void remote_stop PARAMS ((void));
 
 static int ishex PARAMS ((int ch, int *val));
@@ -313,82 +330,12 @@ static void packet_command PARAMS ((char *, int));
 
 static int stub_unpack_int PARAMS ((char *buff, int fieldlength));
 
-char *unpack_varlen_hex PARAMS ((char *buff, int *result));
-
-static char *unpack_nibble PARAMS ((char *buf, int *val));
-
-static char *pack_nibble PARAMS ((char *buf, int nibble));
-
-static char *pack_hex_byte PARAMS ((char *pkt, int/*unsigned char*/ byte));
-
-static char *unpack_byte PARAMS ((char *buf, int *value));
-
-static char *pack_int PARAMS ((char *buf, int value));
-
-static char *unpack_int PARAMS ((char *buf, int *value));
-
-static char *unpack_string PARAMS ((char *src, char *dest, int length));
-
-static char *pack_threadid PARAMS ((char *pkt, threadref *id));
-
-static char *unpack_threadid PARAMS ((char *inbuf, threadref *id));
-
-void int_to_threadref PARAMS ((threadref *id, int value));
-
-static int threadref_to_int PARAMS ((threadref *ref));
-
-static void copy_threadref PARAMS ((threadref *dest, threadref *src));
-
-static int threadmatch PARAMS ((threadref *dest, threadref *src));
-
-static char *pack_threadinfo_request PARAMS ((char *pkt, int mode,
-                                             threadref *id));
-
-static int remote_unpack_thread_info_response PARAMS ((char *pkt,
-                                                      threadref *expectedref,
-                                                      struct gdb_ext_thread_info *info));
-
-
-static int remote_get_threadinfo PARAMS ((threadref *threadid,
-                                         int fieldset, /*TAG mask */
-                                         struct gdb_ext_thread_info *info));
-
-static int adapt_remote_get_threadinfo PARAMS ((gdb_threadref *ref,
-                                               int selection,
-                                               struct gdb_ext_thread_info *info));
-
-static char *pack_threadlist_request PARAMS ((char *pkt, int startflag,
-                                             int threadcount,
-                                             threadref *nextthread));
-
-static int parse_threadlist_response PARAMS ((char *pkt,
-                                             int result_limit,
-                                             threadref *original_echo,
-                                             threadref *resultlist,
-                                             int *doneflag));
-
-static int remote_get_threadlist PARAMS ((int startflag,
-                                         threadref *nextthread,
-                                         int result_limit,
-                                         int *done,
-                                         int *result_count,
-                                         threadref *threadlist));
-
-typedef int (*rmt_thread_action) (threadref *ref, void *context);
-
-static int remote_threadlist_iterator PARAMS ((rmt_thread_action stepfunction,
-                                              void *context, int looplimit));
-
-static int remote_newthread_step PARAMS ((threadref *ref, void *context));
-
 static int remote_current_thread PARAMS ((int oldpid));
 
-int remote_find_new_threads PARAMS ((void));
+static void remote_find_new_threads PARAMS ((void));
 
 static void record_currthread PARAMS ((int currthread));
 
-static void init_remote_threads PARAMS ((void));
-
 /* exported functions */
 
 extern int fromhex PARAMS ((int a));
@@ -415,8 +362,6 @@ static struct target_ops remote_ops;
 
 static struct target_ops extended_remote_ops;
 
-static struct target_thread_vector remote_thread_vec;
-
 /* This was 5 seconds, which is a long time to sit and wait.
    Unless this is going though some terminal server or multiplexer or
    other form of hairy serial connection, I would think 2 seconds would
@@ -438,6 +383,10 @@ static int remote_break;
    starts.  */
 static serial_t remote_desc = NULL;
 
+/* This is set by the target (thru the 'S' message)
+   to denote that the target is in kernel mode.  */
+static int cisco_kernel_mode = 0;
+
 /* This variable (available to the user via "set remotebinarydownload")
    dictates whether downloads are sent in binary (via the 'X' packet).
    We assume that the stub can, and attempt to do it. This will be cleared if
@@ -449,25 +398,19 @@ static int remote_binary_download = 1;
 /* Have we already checked whether binary downloads work? */
 static int remote_binary_checked;
 
+/* Maximum number of bytes to read/write at once.  The value here
+   is chosen to fill up a packet (the headers account for the 32).  */
+#define MAXBUFBYTES(N) (((N)-32)/2)
+
 /* Having this larger than 400 causes us to be incompatible with m68k-stub.c
    and i386-stub.c.  Normally, no one would notice because it only matters
    for writing large chunks of memory (e.g. in downloads).  Also, this needs
    to be more than 400 if required to hold the registers (see below, where
    we round it up based on REGISTER_BYTES).  */
-#define        PBUFSIZ 400
-
-/* Maximum number of bytes to read/write at once.  The value here
-   is chosen to fill up a packet (the headers account for the 32).  */
-#define MAXBUFBYTES ((PBUFSIZ-32)/2)
-
 /* Round up PBUFSIZ to hold all the registers, at least.  */
-/* The blank line after the #if seems to be required to work around a
-   bug in HP's PA compiler.  */
-#if REGISTER_BYTES > MAXBUFBYTES
-
-#undef PBUFSIZ
-#define        PBUFSIZ (REGISTER_BYTES * 2 + 32)
-#endif
+#define        PBUFSIZ ((REGISTER_BYTES > MAXBUFBYTES (400)) \
+                ? (REGISTER_BYTES * 2 + 32) \
+                : 400)
 
 
 /* This variable sets the number of bytes to be written to the target
@@ -475,7 +418,7 @@ static int remote_binary_checked;
    targets need smaller values (perhaps because the receiving end
    is slow).  */
 
-static int remote_write_size = PBUFSIZ;
+static int remote_write_size;
 
 /* This variable sets the number of bits in an address that are to be
    sent in a memory ("M" or "m") packet.  Normally, after stripping
@@ -512,7 +455,7 @@ void (*target_wait_loop_hook) PARAMS ((void));
 /* These are the threads which we last sent to the remote system.
    -1 for all or -2 for not sent yet.  */
 static int general_thread;
-static int cont_thread;
+static int continue_thread;
 
 /* Call this function as a result of
    1) A halt indication (T packet) containing a thread id
@@ -524,18 +467,15 @@ static void
 record_currthread (currthread)
      int currthread;
 {
-#if 0  /* target_wait must not modify inferior_pid! */
-  inferior_pid = currthread;
-#endif
   general_thread = currthread;
-#if 0  /* setting cont_thread has a different meaning 
-          from having the target report its thread id.  */
-  cont_thread = currthread;
-#endif
+
   /* If this is a new thread, add it to GDB's thread list.
      If we leave it up to WFI to do this, bad things will happen.  */
   if (!in_thread_list (currthread))
-    add_thread (currthread);
+    {
+      add_thread (currthread);
+      printf_filtered ("[New %s]\n", target_pid_to_str (currthread));
+    }
 }
 
 #define MAGIC_NULL_PID 42000
@@ -545,8 +485,8 @@ set_thread (th, gen)
      int th;
      int gen;
 {
-  char buf[PBUFSIZ];
-  int state = gen ? general_thread : cont_thread;
+  char *buf = alloca (PBUFSIZ);
+  int state = gen ? general_thread : continue_thread;
 
   if (state == th)
     return;
@@ -565,24 +505,23 @@ set_thread (th, gen)
   putpkt (buf);
   getpkt (buf, 0);
   if (gen)
-    general_thread = th;
+    general_thread  = th;
   else
-    cont_thread = th;
+    continue_thread = th;
 }
 \f
 /*  Return nonzero if the thread TH is still alive on the remote system.  */
 
 static int
-remote_thread_alive (th)
-     int th;
+remote_thread_alive (tid)
+     int tid;
 {
-  char buf[PBUFSIZ];
+  char buf[16];
 
-  buf[0] = 'T';
-  if (th < 0)
-    sprintf (&buf[1], "-%08x", -th);
+  if (tid < 0)
+    sprintf (buf, "T-%08x", -tid);
   else
-    sprintf (&buf[1], "%08x", th);
+    sprintf (buf, "T%08x", tid);
   putpkt (buf);
   getpkt (buf, 0);
   return (buf[0] == 'O' && buf[1] == 'K');
@@ -594,8 +533,114 @@ remote_thread_alive (th)
    remote protocol in general.  There is a matching unit test module
    in libstub.  */
 
+#define OPAQUETHREADBYTES 8
+
+/* a 64 bit opaque identifier */
+typedef unsigned char threadref[OPAQUETHREADBYTES];
+
+/* WARNING: This threadref data structure comes from the remote O.S., libstub
+   protocol encoding, and remote.c. it is not particularly changable */
+
+/* Right now, the internal structure is int. We want it to be bigger.
+   Plan to fix this.
+   */
+
+typedef int gdb_threadref; /* internal GDB thread reference */
+
+/*  gdb_ext_thread_info is an internal GDB data structure which is
+   equivalint to the reply of the remote threadinfo packet */
+
+struct gdb_ext_thread_info
+{
+  threadref threadid;    /* External form of thread reference */
+  int active;            /* Has state interesting to GDB? , regs, stack */
+  char display[256];     /* Brief state display, name, blocked/syspended */
+  char shortname[32];    /* To be used to name threads */
+  char more_display[256]; /* Long info, statistics, queue depth, whatever */
+};
+
+/* The volume of remote transfers can be limited by submitting
+   a mask containing bits specifying the desired information.
+   Use a union of these values as the 'selection' parameter to
+   get_thread_info. FIXME: Make these TAG names more thread specific.
+   */
+
+#define TAG_THREADID 1
+#define TAG_EXISTS 2
+#define TAG_DISPLAY 4
+#define TAG_THREADNAME 8
+#define TAG_MOREDISPLAY 16 
+
 #define BUF_THREAD_ID_SIZE (OPAQUETHREADBYTES*2)
 
+char *unpack_varlen_hex PARAMS ((char *buff, int *result));
+
+static char *unpack_nibble PARAMS ((char *buf, int *val));
+
+static char *pack_nibble PARAMS ((char *buf, int nibble));
+
+static char *pack_hex_byte PARAMS ((char *pkt, int/*unsigned char*/ byte));
+
+static char *unpack_byte PARAMS ((char *buf, int *value));
+
+static char *pack_int PARAMS ((char *buf, int value));
+
+static char *unpack_int PARAMS ((char *buf, int *value));
+
+static char *unpack_string PARAMS ((char *src, char *dest, int length));
+
+static char *pack_threadid PARAMS ((char *pkt, threadref *id));
+
+static char *unpack_threadid PARAMS ((char *inbuf, threadref *id));
+
+void int_to_threadref PARAMS ((threadref *id, int value));
+
+static int threadref_to_int PARAMS ((threadref *ref));
+
+static void copy_threadref PARAMS ((threadref *dest, threadref *src));
+
+static int threadmatch PARAMS ((threadref *dest, threadref *src));
+
+static char *pack_threadinfo_request PARAMS ((char *pkt, int mode,
+                                             threadref *id));
+
+static int remote_unpack_thread_info_response PARAMS ((char *pkt,
+                                                      threadref *expectedref,
+                                                      struct gdb_ext_thread_info *info));
+
+
+static int remote_get_threadinfo PARAMS ((threadref *threadid,
+                                         int fieldset, /*TAG mask */
+                                         struct gdb_ext_thread_info *info));
+
+static int adapt_remote_get_threadinfo PARAMS ((gdb_threadref *ref,
+                                               int selection,
+                                               struct gdb_ext_thread_info *info));
+
+static char *pack_threadlist_request PARAMS ((char *pkt, int startflag,
+                                             int threadcount,
+                                             threadref *nextthread));
+
+static int parse_threadlist_response PARAMS ((char *pkt,
+                                             int result_limit,
+                                             threadref *original_echo,
+                                             threadref *resultlist,
+                                             int *doneflag));
+
+static int remote_get_threadlist PARAMS ((int startflag,
+                                         threadref *nextthread,
+                                         int result_limit,
+                                         int *done,
+                                         int *result_count,
+                                         threadref *threadlist));
+
+typedef int (*rmt_thread_action) (threadref *ref, void *context);
+
+static int remote_threadlist_iterator PARAMS ((rmt_thread_action stepfunction,
+                                              void *context, int looplimit));
+
+static int remote_newthread_step PARAMS ((threadref *ref, void *context));
+
 /* encode 64 bits in 16 chars of hex */
 
 static const char hexchars[] = "0123456789abcdef";
@@ -1014,7 +1059,7 @@ remote_get_threadinfo (threadid, fieldset, info)
      struct gdb_ext_thread_info *info;
 {
   int result;
-  char threadinfo_pkt[PBUFSIZ];
+  char *threadinfo_pkt = alloca (PBUFSIZ);
 
   pack_threadinfo_request (threadinfo_pkt, fieldset, threadid);
   putpkt (threadinfo_pkt);
@@ -1101,8 +1146,8 @@ remote_get_threadlist (startflag, nextthread, result_limit,
 
 {
   static threadref echo_nextthread;
-  char threadlist_packet[PBUFSIZ];
-  char t_response[PBUFSIZ];
+  char *threadlist_packet = alloca (PBUFSIZ);
+  char *t_response = alloca (PBUFSIZ);
   int result = 1;
 
   /* Trancate result limit to be smaller than the packet size */
@@ -1222,7 +1267,7 @@ static int
 remote_current_thread (oldpid)
      int oldpid;
 {
-  char buf[PBUFSIZ];
+  char *buf = alloca (PBUFSIZ);
 
   putpkt ("qC");
   getpkt (buf, 0);
@@ -1232,26 +1277,45 @@ remote_current_thread (oldpid)
     return oldpid;
 }
 
-int
+/* Find new threads for info threads command.  */
+
+static void
 remote_find_new_threads ()
 {
-  int ret;
-
-  ret = remote_threadlist_iterator (remote_newthread_step, 0, 
+  remote_threadlist_iterator (remote_newthread_step, 0, 
                                    CRAZY_MAX_THREADS);
   if (inferior_pid == MAGIC_NULL_PID)  /* ack ack ack */
     inferior_pid = remote_current_thread (inferior_pid);
-  return ret;
 }
 
-/* Initialize the thread vector which is used by threads.c */
-/* The thread stub is a package, it has an initializer */
-
 static void
-init_remote_threads ()
+remote_threads_info (void)
 {
-  remote_thread_vec.find_new_threads = remote_find_new_threads;
-  remote_thread_vec.get_thread_info = adapt_remote_get_threadinfo;
+  char *buf = alloca (PBUFSIZ);
+  char *bufp;
+  int tid;
+
+  if (remote_desc == 0)                /* paranoia */
+    error ("Command can only be used when connected to the remote target.");
+
+  putpkt ("qfThreadInfo");
+  getpkt (bufp = buf, 0);
+  if (bufp[0] == '\0')         /* q packet not recognized! */
+    {                          /* try old jmetzler method  */
+      remote_find_new_threads ();
+      return;
+    }
+  else                         /* try new 'q' method */
+    while (*bufp++ == 'm')             /* reply contains one or more TID */
+      {
+       do {
+         tid = strtol(bufp, &bufp, 16);
+         if (tid != 0 && !in_thread_list (tid))
+           add_thread (tid);
+       } while (*bufp++ == ',');               /* comma-separated list */
+       putpkt ("qsThreadInfo");
+       getpkt (bufp = buf, 0);
+      }
 }
 
 \f
@@ -1260,7 +1324,7 @@ init_remote_threads ()
 static void
 extended_remote_restart ()
 {
-  char buf[PBUFSIZ];
+  char *buf = alloca (PBUFSIZ);
 
   /* Send the restart command; for reasons I don't understand the
      remote side really expects a number after the "R".  */
@@ -1291,7 +1355,8 @@ remote_close (quitting)
 static void
 get_offsets ()
 {
-  char buf[PBUFSIZ], *ptr;
+  char *buf = alloca (PBUFSIZ);
+  char *ptr;
   int lose;
   CORE_ADDR text_addr, data_addr, bss_addr;
   struct section_offsets *offs;
@@ -1351,7 +1416,7 @@ get_offsets ()
   if (symfile_objfile == NULL)
     return;
 
-  offs = (struct section_offsets *) alloca (sizeof (struct section_offsets)
+  offs = alloca (sizeof (struct section_offsets)
                                            + symfile_objfile->num_sections
                                            * sizeof (offs->offsets));
   memcpy (offs, symfile_objfile->section_offsets,
@@ -1371,8 +1436,141 @@ get_offsets ()
   objfile_relocate (symfile_objfile, offs);
 }
 
+/*
+ * Cisco version of section offsets:
+ *
+ * Instead of having GDB query the target for the section offsets,
+ * Cisco lets the target volunteer the information!  It's also in
+ * a different format, so here are the functions that will decode
+ * a section offset packet from a Cisco target.
+ */
+
+/* 
+ * Function: remote_cisco_section_offsets
+ *
+ * Returns:  zero for success, non-zero for failure 
+ */
+
+static int 
+remote_cisco_section_offsets (text_addr, data_addr, bss_addr, 
+                             text_offs, data_offs, bss_offs)
+     bfd_vma text_addr;
+     bfd_vma data_addr;
+     bfd_vma bss_addr;
+     bfd_signed_vma * text_offs;
+     bfd_signed_vma * data_offs;
+     bfd_signed_vma * bss_offs;
+{
+  bfd_vma text_base, data_base, bss_base;
+  struct minimal_symbol *start;
+  asection *sect;
+  bfd * abfd;
+  int len;
+  char *p;
+
+  if (symfile_objfile == NULL)
+    return -1;         /* no can do nothin' */
+
+  start = lookup_minimal_symbol ("_start", NULL, NULL);
+  if (start == NULL)
+    return -1;         /* Can't find "_start" symbol */
+
+  data_base = bss_base = 0;
+  text_base = SYMBOL_VALUE_ADDRESS (start);
+
+  abfd = symfile_objfile->obfd;
+    for (sect = abfd->sections; 
+       sect != 0;
+       sect = sect->next)
+    {
+      p   = (unsigned char *) bfd_get_section_name (abfd, sect);
+      len = strlen (p);
+      if (strcmp (p + len - 4, "data") == 0)   /* ends in "data" */
+       if (data_base == 0 ||
+           data_base > bfd_get_section_vma (abfd, sect))
+         data_base = bfd_get_section_vma (abfd, sect);
+      if (strcmp (p + len - 3, "bss") == 0)    /* ends in "bss" */
+       if (bss_base == 0 || 
+           bss_base > bfd_get_section_vma (abfd, sect))
+         bss_base = bfd_get_section_vma (abfd, sect);
+    }
+  *text_offs = text_addr - text_base;
+  *data_offs = data_addr - data_base;
+  *bss_offs  = bss_addr  - bss_base;
+  if (remote_debug)
+    {
+      char tmp[128];
+
+      sprintf (tmp, "VMA:          text = 0x");
+      sprintf_vma (tmp + strlen (tmp), text_addr);
+      sprintf     (tmp + strlen (tmp), " data = 0x");
+      sprintf_vma (tmp + strlen (tmp), data_addr);
+      sprintf     (tmp + strlen (tmp), " bss = 0x");
+      sprintf_vma (tmp + strlen (tmp), bss_addr);
+      fprintf_filtered (gdb_stdlog, tmp);
+      fprintf_filtered (gdb_stdlog,
+                       "Reloc offset: text = 0x%x data = 0x%x bss = 0x%x\n",
+                      (long) *text_offs, (long) *data_offs, (long) *bss_offs);
+    }
+
+  return 0;
+}
+
+/*
+ * Function: remote_cisco_objfile_relocate
+ *
+ * Relocate the symbol file for a remote target. 
+ */
+
+static void
+remote_cisco_objfile_relocate (text_off, data_off, bss_off)
+     bfd_signed_vma text_off;
+     bfd_signed_vma data_off;
+     bfd_signed_vma bss_off;
+{
+  struct section_offsets *offs;
+
+  if (text_off != 0 || data_off != 0 || bss_off  != 0)
+    {
+      /* FIXME: This code assumes gdb-stabs.h is being used; it's
+        broken for xcoff, dwarf, sdb-coff, etc.  But there is no
+        simple canonical representation for this stuff.  */
+
+      offs = ((struct section_offsets *)
+             alloca (sizeof (struct section_offsets)
+                     + (symfile_objfile->num_sections
+                        * sizeof (offs->offsets))));
+
+      memcpy (offs, symfile_objfile->section_offsets,
+             (sizeof (struct section_offsets)
+              + (symfile_objfile->num_sections
+                 * sizeof (offs->offsets))));
+
+      ANOFFSET (offs, SECT_OFF_TEXT) = text_off;
+      ANOFFSET (offs, SECT_OFF_DATA) = data_off;
+      ANOFFSET (offs, SECT_OFF_BSS)  = bss_off;
+
+      /* First call the standard objfile_relocate.  */
+      objfile_relocate (symfile_objfile, offs);
+
+      /* Now we need to fix up the section entries already attached to
+        the exec target.  These entries will control memory transfers
+        from the exec file.  */
+
+      exec_set_section_offsets (text_off, data_off, bss_off);
+    }
+}
+
 /* Stub for catch_errors.  */
 
+static int
+remote_start_remote_dummy (dummy)
+     char *dummy;
+{
+  start_remote ();             /* Initialize gdb process mechanisms */
+  return 1;
+}
+
 static int
 remote_start_remote (dummy)
      PTR dummy;
@@ -1392,8 +1590,7 @@ remote_start_remote (dummy)
   putpkt ("?");                        /* initiate a query from remote machine */
   immediate_quit = 0;
 
-  start_remote ();             /* Initialize gdb process mechanisms */
-  return 1;
+  return remote_start_remote_dummy (dummy);
 }
 
 /* Open a connection to a remote debugger.
@@ -1467,19 +1664,14 @@ serial device is attached to the remote system (e.g. /dev/ttya).");
     }
   push_target (target);        /* Switch to using remote target now */
 
-  /* The target vector does not have the thread functions in it yet,
-     so we use this function to call back into the thread module and
-     register the thread vector and its contained functions. */
-  bind_target_thread_vector (&remote_thread_vec);
-
   /* Start out by trying the 'P' request to set registers.  We set
      this each time that we open a new target so that if the user
      switches from one stub to another, we can (if the target is
      closed and reopened) cope.  */
   stub_supports_P = 1;
 
-  general_thread = -2;
-  cont_thread = -2;
+  general_thread  = -2;
+  continue_thread = -2;
 
   /* Force remote_write_bytes to check whether target supports
      binary downloading. */
@@ -1507,7 +1699,7 @@ serial device is attached to the remote system (e.g. /dev/ttya).");
   if (extended_p)
     {
       /* tell the remote that we're using the extended protocol.  */
-      char buf[PBUFSIZ];
+      char *buf = alloca (PBUFSIZ);
       putpkt ("!");
       getpkt (buf, 0);
     }
@@ -1523,7 +1715,7 @@ remote_detach (args, from_tty)
      char *args;
      int from_tty;
 {
-  char buf[PBUFSIZ];
+  char *buf = alloca (PBUFSIZ);
 
   if (args)
     error ("Argument given to \"detach\" when remotely debugging.");
@@ -1576,7 +1768,7 @@ remote_resume (pid, step, siggnal)
      int pid, step;
      enum target_signal siggnal;
 {
-  char buf[PBUFSIZ];
+  char *buf = alloca (PBUFSIZ);
 
   if (pid == -1)
     set_thread (0, 0);         /* run any thread */
@@ -1624,7 +1816,7 @@ remote_interrupt (signo)
   signal (signo, remote_interrupt_twice);
 
   if (remote_debug)
-    printf_unfiltered ("remote_interrupt called\n");
+    fprintf_unfiltered (gdb_stdlog, "remote_interrupt called\n");
 
   target_stop ();
 }
@@ -1648,7 +1840,7 @@ remote_stop ()
 {
   /* Send a break or a ^C, depending on user preference.  */
   if (remote_debug)
-    printf_unfiltered ("remote_stop called\n");
+    fprintf_unfiltered (gdb_stdlog, "remote_stop called\n");
 
   if (remote_break)
     SERIAL_SEND_BREAK (remote_desc);
@@ -1696,16 +1888,17 @@ remote_console_output (msg)
     }
 }
 
-/* Wait until the remote machine stops, then return, storing status in
-   STATUS just as `wait' would.  Returns "pid" (though it's not clear
-   what, if anything, that means in the case of this target).  */
+/* Wait until the remote machine stops, then return,
+   storing status in STATUS just as `wait' would.
+   Returns "pid", which in the case of a multi-threaded 
+   remote OS, is the thread-id.  */
 
 static int
 remote_wait (pid, status)
      int pid;
      struct target_waitstatus *status;
 {
-  unsigned char buf[PBUFSIZ];
+  unsigned char *buf = alloca (PBUFSIZ);
   int thread_num = -1;
 
   status->kind = TARGET_WAITKIND_EXITED;
@@ -1803,7 +1996,72 @@ Packet: '%s'\n",
          status->value.sig = (enum target_signal)
            (((fromhex (buf[1])) << 4) + (fromhex (buf[2])));
 
+         if (buf[3] == 'p')
+           {
+             /* Export Cisco kernel mode as a convenience variable
+                (so that it can be used in the GDB prompt if desired). */
+
+             if (cisco_kernel_mode == 1)
+               set_internalvar (lookup_internalvar ("cisco_kernel_mode"), 
+                                value_from_string ("PDEBUG-"));
+             cisco_kernel_mode = 0;
+             thread_num = strtol ((const char *) &buf[4], NULL, 16);
+             record_currthread (thread_num);
+           }
+         else if (buf[3] == 'k')
+           {
+             /* Export Cisco kernel mode as a convenience variable
+                (so that it can be used in the GDB prompt if desired). */
+
+             if (cisco_kernel_mode == 1)
+               set_internalvar (lookup_internalvar ("cisco_kernel_mode"), 
+                                value_from_string ("KDEBUG-"));
+             cisco_kernel_mode = 1;
+           }
          goto got_status;
+       case 'N':               /* Cisco special: status and offsets */
+         {
+           bfd_vma text_addr, data_addr, bss_addr;
+           bfd_signed_vma text_off, data_off, bss_off;
+           unsigned char *p1;
+
+           status->kind = TARGET_WAITKIND_STOPPED;
+           status->value.sig = (enum target_signal)
+             (((fromhex (buf[1])) << 4) + (fromhex (buf[2])));
+
+           if (symfile_objfile == NULL) 
+             {
+               warning ("Relocation packet recieved with no symbol file.  \
+Packet Dropped");
+               goto got_status;
+             }
+
+           /* Relocate object file.  Buffer format is NAATT;DD;BB
+            * where AA is the signal number, TT is the new text
+            * address, DD * is the new data address, and BB is the
+            * new bss address.  */
+
+           p = &buf[3];
+           text_addr = strtoul (p, (char **) &p1, 16);
+           if (p1 == p || *p1 != ';')
+             warning ("Malformed relocation packet: Packet '%s'", buf);
+           p = p1 + 1;
+           data_addr = strtoul (p, (char **) &p1, 16);
+           if (p1 == p || *p1 != ';')
+             warning ("Malformed relocation packet: Packet '%s'", buf);
+           p = p1 + 1;
+           bss_addr = strtoul (p, (char **) &p1, 16);
+           if (p1 == p) 
+             warning ("Malformed relocation packet: Packet '%s'", buf);
+
+           if (remote_cisco_section_offsets (text_addr, data_addr, bss_addr,
+                                             &text_off, &data_off, &bss_off)
+               == 0)
+             if (text_off != 0 || data_off != 0 || bss_off  != 0) 
+               remote_cisco_objfile_relocate (text_off, data_off, bss_off);
+
+           goto got_status;
+         }
        case 'W':               /* Target exited */
          {
            /* The remote process exited.  */
@@ -1846,15 +2104,6 @@ Packet: '%s'\n",
  got_status:
   if (thread_num != -1)
     {
-      /* Initial thread value can only be acquired via wait, so deal with
-        this marker which is used before the first thread value is
-        acquired.  */
-      if (inferior_pid == MAGIC_NULL_PID)
-       {
-         inferior_pid = thread_num;
-         if (!in_thread_list (inferior_pid))
-           add_thread (inferior_pid);
-       }
       return thread_num;
     }
   return inferior_pid;
@@ -1872,7 +2121,7 @@ static void
 remote_fetch_registers (regno)
      int regno;
 {
-  char buf[PBUFSIZ];
+  char *buf = alloca (PBUFSIZ);
   int i;
   char *p;
   char regs[REGISTER_BYTES];
@@ -1896,7 +2145,8 @@ remote_fetch_registers (regno)
         && buf[0] != 'x')      /* New: unavailable register value */
     {
       if (remote_debug)
-       printf_unfiltered ("Bad register packet; fetching a new packet\n");
+       fprintf_unfiltered (gdb_stdlog,
+                           "Bad register packet; fetching a new packet\n");
       getpkt (buf, 0);
     }
 
@@ -1959,7 +2209,7 @@ static void
 remote_store_registers (regno)
      int regno;
 {
-  char buf[PBUFSIZ];
+  char *buf = alloca (PBUFSIZ);
   int i;
   char *p;
 
@@ -2112,7 +2362,8 @@ check_binary_download (addr)
 {
   if (remote_binary_download && !remote_binary_checked)
     {
-      char buf[PBUFSIZ], *p;
+      char *buf = alloca (PBUFSIZ);
+      char *p;
       remote_binary_checked = 1;
 
       p = buf;
@@ -2133,9 +2384,11 @@ check_binary_download (addr)
   if (remote_debug)
     {
       if (remote_binary_download)
-       printf_unfiltered ("binary downloading suppported by target\n");
+       fprintf_unfiltered (gdb_stdlog,
+                           "binary downloading suppported by target\n");
       else
-       printf_unfiltered ("binary downloading NOT suppported by target\n");
+       fprintf_unfiltered (gdb_stdlog,
+                           "binary downloading NOT suppported by target\n");
     }
 }
 
@@ -2153,6 +2406,7 @@ remote_write_bytes (memaddr, myaddr, len)
      char *myaddr;
      int len;
 {
+  unsigned char *buf = alloca (PBUFSIZ);
   int max_buf_size;            /* Max size of packet output buffer */
   int origlen;
 
@@ -2171,7 +2425,6 @@ remote_write_bytes (memaddr, myaddr, len)
   origlen = len;
   while (len > 0)
     {
-      unsigned char buf[PBUFSIZ];
       unsigned char *p, *plen;
       int todo;
       int i;
@@ -2284,6 +2537,7 @@ remote_read_bytes (memaddr, myaddr, len)
      char *myaddr;
      int len;
 {
+  char *buf = alloca (PBUFSIZ);
   int max_buf_size;            /* Max size of packet output buffer */
   int origlen;
 
@@ -2296,7 +2550,6 @@ remote_read_bytes (memaddr, myaddr, len)
   origlen = len;
   while (len > 0)
     {
-      char buf[PBUFSIZ];
       char *p;
       int todo;
       int i;
@@ -2347,31 +2600,32 @@ remote_read_bytes (memaddr, myaddr, len)
 }
 \f
 /* Read or write LEN bytes from inferior memory at MEMADDR,
-   transferring to or from debugger address MYADDR.  Write to inferior
-   if SHOULD_WRITE is nonzero.  Returns length of data written or
-   read; 0 for error.  */
+   transferring to or from debugger address BUFFER.  Write to inferior if
+   SHOULD_WRITE is nonzero.  Returns length of data written or read; 0
+   for error.  */
+
+#ifndef REMOTE_TRANSLATE_XFER_ADDRESS
+#define REMOTE_TRANSLATE_XFER_ADDRESS(MEM_ADDR, MEM_LEN, TARG_ADDR, TARG_LEN) \
+   (*(TARG_ADDR) = (MEM_ADDR), *(TARG_LEN) = (MEM_LEN))
+#endif
 
 /* ARGSUSED */
 static int
-remote_xfer_memory (memaddr, myaddr, len, should_write, target)
-     CORE_ADDR memaddr;
-     char *myaddr;
-     int len;
+remote_xfer_memory (mem_addr, buffer, mem_len, should_write, target)
+     CORE_ADDR mem_addr;
+     char *buffer;
+     int mem_len;
      int should_write;
      struct target_ops *target;                        /* ignored */
 {
-#ifdef REMOTE_TRANSLATE_XFER_ADDRESS
-  CORE_ADDR targaddr;
-  int targlen;
-  REMOTE_TRANSLATE_XFER_ADDRESS (memaddr, len, targaddr, targlen);
-  if (targlen == 0)
+  CORE_ADDR targ_addr;
+  int targ_len;
+  REMOTE_TRANSLATE_XFER_ADDRESS (mem_addr, mem_len, &targ_addr, &targ_len);
+  if (targ_len <= 0)
     return 0;
-  memaddr = targaddr;
-  len = targlen;
-#endif
 
-  return dcache_xfer_memory (remote_dcache, memaddr, myaddr,
-                            len, should_write);
+  return dcache_xfer_memory (remote_dcache, targ_addr, buffer,
+                            targ_len, should_write);
 }
 
    
@@ -2396,7 +2650,7 @@ remote_search (len, data, mask, startaddr, increment, lorange, hirange
       long mask_long, data_long;
       long data_found_long;
       CORE_ADDR addr_we_found;
-      char buf[PBUFSIZ];
+      char *buf = alloca (PBUFSIZ);
       long returned_long[2];
       char *p;
 
@@ -2528,7 +2782,9 @@ putpkt_binary (buf, cnt)
 {
   int i;
   unsigned char csum = 0;
-  char buf2[PBUFSIZ];
+  char *buf2 = alloca (PBUFSIZ);
+  char *junkbuf = alloca (PBUFSIZ);
+
   int ch;
   int tcount = 0;
   char *p;
@@ -2560,8 +2816,8 @@ putpkt_binary (buf, cnt)
       if (remote_debug)
        {
          *p = '\0';
-         printf_unfiltered ("Sending packet: %s...", buf2);
-         gdb_flush (gdb_stdout);
+         fprintf_unfiltered (gdb_stdlog, "Sending packet: %s...", buf2);
+         gdb_flush (gdb_stdlog);
        }
       if (SERIAL_WRITE (remote_desc, buf2, p - buf2))
        perror_with_name ("putpkt: write failed");
@@ -2590,7 +2846,7 @@ putpkt_binary (buf, cnt)
            {
            case '+':
              if (remote_debug)
-               printf_unfiltered ("Ack\n");
+               fprintf_unfiltered (gdb_stdlog, "Ack\n");
              return 1;
            case SERIAL_TIMEOUT:
              tcount ++;
@@ -2599,8 +2855,6 @@ putpkt_binary (buf, cnt)
              break;            /* Retransmit buffer */
            case '$':
              {
-               char junkbuf[PBUFSIZ];
-
              /* It's probably an old response, and we're out of sync.
                 Just gobble up the packet and ignore it.  */
                getpkt (junkbuf, 0);
@@ -2612,9 +2866,9 @@ putpkt_binary (buf, cnt)
                  if (!started_error_output)
                    {
                      started_error_output = 1;
-                     printf_unfiltered ("putpkt: Junk: ");
+                     fprintf_unfiltered (gdb_stdlog, "putpkt: Junk: ");
                    }
-                 putchar_unfiltered (ch & 0177);
+                 fputc_unfiltered (ch & 0177, gdb_stdlog);
                }
              continue;
            }
@@ -2636,6 +2890,32 @@ putpkt_binary (buf, cnt)
     }
 }
 
+static int remote_cisco_mode;
+
+static void remote_cisco_expand (src, dest)
+     char *src;
+     char *dest;
+{
+  int i;
+  int repeat;
+
+  do {
+    if (*src == '*') 
+      {
+       repeat = (fromhex (src[1]) << 4) + fromhex (src[2]);
+       for (i = 0; i < repeat; i++) 
+         {
+           *dest++ = *(src-1);
+         }
+       src += 2;
+      }
+    else 
+      {
+       *dest++ = *src;
+      }
+  } while (*src++);
+}
+
 /* Come here after finding the start of the frame.  Collect the rest
    into BUF, verifying the checksum, length, and handling run-length
    compression.  Returns 0 on any error, 1 on success.  */
@@ -2659,11 +2939,12 @@ read_frame (buf)
        {
        case SERIAL_TIMEOUT:
          if (remote_debug)
-           puts_filtered ("Timeout in mid-packet, retrying\n");
+           fputs_filtered ("Timeout in mid-packet, retrying\n", gdb_stdlog);
          return 0;
        case '$':
          if (remote_debug)
-           puts_filtered ("Saw new packet start in middle of old one\n");
+           fputs_filtered ("Saw new packet start in middle of old one\n",
+                           gdb_stdlog);
          return 0;             /* Start a new packet, count retries */
        case '#':
          {
@@ -2675,37 +2956,49 @@ read_frame (buf)
            pktcsum |= fromhex (readchar (remote_timeout));
 
            if (csum == pktcsum)
-             return 1;
+             {
+               if (remote_cisco_mode)  /* variant run-length-encoding */
+                 {
+                   char *tmp_buf = alloca (PBUFSIZ);
+
+                   remote_cisco_expand (buf, tmp_buf);
+                   strcpy (buf, tmp_buf);
+                 }
+               return 1;
+             }
 
            if (remote_debug) 
              {
-               printf_filtered ("Bad checksum, sentsum=0x%x, csum=0x%x, buf=",
-                                pktcsum, csum);
-               puts_filtered (buf);
-               puts_filtered ("\n");
+               fprintf_filtered (gdb_stdlog,
+                                 "Bad checksum, sentsum=0x%x, csum=0x%x, buf=",
+                                 pktcsum, csum);
+               fputs_filtered (buf, gdb_stdlog);
+               fputs_filtered ("\n", gdb_stdlog);
              }
            return 0;
          }
        case '*':               /* Run length encoding */
-         csum += c;
-         c = readchar (remote_timeout);
-         csum += c;
-         c = c - ' ' + 3;      /* Compute repeat count */
-
-
-         if (c > 0 && c < 255 && bp + c - 1 < buf + PBUFSIZ - 1)
+         if (remote_cisco_mode == 0)   /* variant run-length-encoding */
            {
-             memset (bp, *(bp - 1), c);
-             bp += c;
-             continue;
-           }
+             csum += c;
+             c = readchar (remote_timeout);
+             csum += c;
+             c = c - ' ' + 3;  /* Compute repeat count */
 
-         *bp = '\0';
-         printf_filtered ("Repeat count %d too large for buffer: ", c);
-         puts_filtered (buf);
-         puts_filtered ("\n");
-         return 0;
+             if (c > 0 && c < 255 && bp + c - 1 < buf + PBUFSIZ - 1)
+               {
+                 memset (bp, *(bp - 1), c);
+                 bp += c;
+                 continue;
+               }
 
+             *bp = '\0';
+             printf_filtered ("Repeat count %d too large for buffer: ", c);
+             puts_filtered (buf);
+             puts_filtered ("\n");
+             return 0;
+           }
+         /* else fall thru to treat like default */
        default:
          if (bp < buf + PBUFSIZ - 1)
            {
@@ -2773,7 +3066,7 @@ getpkt (buf, forever)
                  error ("Watchdog has expired.  Target detached.\n");
                }
              if (remote_debug)
-               puts_filtered ("Timed out.\n");
+               fputs_filtered ("Timed out.\n", gdb_stdlog);
              goto retry;
            }
        }
@@ -2786,7 +3079,7 @@ getpkt (buf, forever)
       if (val == 1)
        {
          if (remote_debug)
-           fprintf_unfiltered (gdb_stdout, "Packet received: %s\n", buf);
+           fprintf_unfiltered (gdb_stdlog, "Packet received: %s\n", buf);
          SERIAL_WRITE (remote_desc, "+", 1);
          return;
        }
@@ -3039,7 +3332,10 @@ compare_sections_command (args, from_tty)
   unsigned long host_crc, target_crc;
   extern bfd *exec_bfd;
   struct cleanup *old_chain;
-  char *tmp, *sectdata, *sectname, buf[PBUFSIZ];
+  char *tmp;
+  char *sectdata;
+  char *sectname;
+  char *buf = alloca (PBUFSIZ);
   bfd_size_type size;
   bfd_vma lma;
   int matched = 0;
@@ -3113,14 +3409,14 @@ remote_query (query_type, buf, outbuf, bufsiz)
      int *bufsiz;
 {
   int i;
-  char buf2[PBUFSIZ];
+  char *buf2 = alloca (PBUFSIZ);
   char *p2 = &buf2[0];
   char *p = buf;
 
   if (! bufsiz)
     error ("null pointer to remote bufer size specified");
 
-  /* minimum outbuf size is PBUFSIZE - if bufsiz is not large enough let 
+  /* minimum outbuf size is PBUFSIZ - if bufsiz is not large enough let 
      the caller know and return what the minimum size is   */
   /* Note: a zero bufsiz can be used to query the minimum buffer size */
   if ( *bufsiz < PBUFSIZ )
@@ -3180,7 +3476,7 @@ packet_command (args, from_tty)
      char *args;
      int from_tty;
 {
-  char buf[PBUFSIZ];
+  char *buf = alloca (PBUFSIZ);
 
   if (! remote_desc)
     error ("command can only be used with remote target");
@@ -3384,6 +3680,7 @@ Specify the serial device it is connected to (e.g. /dev/ttya).";
   remote_ops.to_load = generic_load;           
   remote_ops.to_mourn_inferior = remote_mourn;
   remote_ops.to_thread_alive = remote_thread_alive;
+  remote_ops.to_find_new_threads = remote_threads_info;
   remote_ops.to_stop = remote_stop;
   remote_ops.to_query = remote_query;
   remote_ops.to_stratum = process_stratum;
@@ -3404,26 +3701,436 @@ init_extended_remote_ops ()
 {
   extended_remote_ops = remote_ops;
 
-  extended_remote_ops.to_shortname = "extended-remote";        
+  extended_remote_ops.to_shortname = "extended-remote";
   extended_remote_ops.to_longname = 
     "Extended remote serial target in gdb-specific protocol";
   extended_remote_ops.to_doc = 
     "Use a remote computer via a serial line, using a gdb-specific protocol.\n\
 Specify the serial device it is connected to (e.g. /dev/ttya).",
-  extended_remote_ops.to_open = extended_remote_open;  
+  extended_remote_ops.to_open = extended_remote_open;
   extended_remote_ops.to_create_inferior = extended_remote_create_inferior;
   extended_remote_ops.to_mourn_inferior = extended_remote_mourn;
-} 
+}
+
+/*
+ * Command: info remote-process
+ *
+ * This implements Cisco's version of the "info proc" command.
+ *
+ * This query allows the target stub to return an arbitrary string
+ * (or strings) giving arbitrary information about the target process.
+ * This is optional; the target stub isn't required to implement it.
+ *
+ * Syntax: qfProcessInfo        request first string
+ *         qsProcessInfo        request subsequent string
+ * reply:  'O'<hex-encoded-string>
+ *         'l'                  last reply (empty)
+ */
+
+static void
+remote_info_process (args, from_tty)
+     char *args;
+     int from_tty;
+{
+  char *buf = alloca (PBUFSIZ);
+
+  if (remote_desc == 0)
+    error ("Command can only be used when connected to the remote target.");
+
+  putpkt ("qfProcessInfo");
+  getpkt (buf, 0);
+  if (buf[0] == 0)
+    return;             /* Silently: target does not support this feature. */
+
+  if (buf[0] == 'E')
+    error ("info proc: target error.");
+
+  while (buf[0] == 'O') /* Capitol-O packet */
+    {
+      remote_console_output (&buf[1]);
+      putpkt ("qsProcessInfo");
+      getpkt (buf, 0);
+    }
+}
+
+/*
+ * Target Cisco 
+ */
+
+static void
+remote_cisco_open (name, from_tty)
+     char *name;
+     int from_tty;
+{
+  if (name == 0)
+    error (
+"To open a remote debug connection, you need to specify what \n\
+device is attached to the remote system (e.g. host:port).");
+
+  target_preopen (from_tty);
+
+  unpush_target (&remote_cisco_ops);
+
+  remote_dcache = dcache_init (remote_read_bytes, remote_write_bytes);
+
+  remote_desc = SERIAL_OPEN (name);
+  if (!remote_desc)
+    perror_with_name (name);
+
+  /*
+   * If a baud rate was specified on the gdb  command line it will
+   * be greater than the initial value of -1.  If it is, use it otherwise
+   * default to 9600
+   */
+
+  baud_rate = (baud_rate > 0) ? baud_rate : 9600;
+  if (SERIAL_SETBAUDRATE (remote_desc, baud_rate)) 
+    {
+      SERIAL_CLOSE (remote_desc);
+      perror_with_name (name);
+    }
+
+  SERIAL_RAW (remote_desc);
+
+  /* If there is something sitting in the buffer we might take it as a
+     response to a command, which would be bad.  */
+  SERIAL_FLUSH_INPUT (remote_desc);
+
+  if (from_tty)
+    {
+      puts_filtered ("Remote debugging using ");
+      puts_filtered (name);
+      puts_filtered ("\n");
+    }
+
+  remote_cisco_mode = 1;
+
+  push_target (&remote_cisco_ops);     /* Switch to using cisco target now */
+
+  /* Start out by trying the 'P' request to set registers.  We set this each
+     time that we open a new target so that if the user switches from one
+     stub to another, we can (if the target is closed and reopened) cope.  */
+  stub_supports_P = 1;
+
+  general_thread  = -2;
+  continue_thread = -2;
+
+  /* Force remote_write_bytes to check whether target supports
+     binary downloading. */
+  remote_binary_checked = 0;
+
+  /* Without this, some commands which require an active target (such
+     as kill) won't work.  This variable serves (at least) double duty
+     as both the pid of the target process (if it has such), and as a
+     flag indicating that a target is active.  These functions should
+     be split out into seperate variables, especially since GDB will
+     someday have a notion of debugging several processes.  */
+  inferior_pid = MAGIC_NULL_PID;
+
+  /* Start the remote connection; if error (0), discard this target. */
+
+  if (!catch_errors (remote_start_remote_dummy, (char *) 0, 
+                    "Couldn't establish connection to remote target\n", 
+                    RETURN_MASK_ALL))
+    {
+      pop_target ();
+      return;
+    }
+}
+
+static void
+remote_cisco_close (quitting)
+     int quitting;
+{
+  remote_cisco_mode = 0;
+  remote_close (quitting);
+}
+
+static void 
+remote_cisco_mourn PARAMS ((void))
+{
+  remote_mourn_1 (&remote_cisco_ops);
+}
+
+enum {
+  READ_MORE, 
+  FATAL_ERROR, 
+  ENTER_DEBUG, 
+  DISCONNECT_TELNET
+} minitelnet_return;
+
+/* shared between readsocket() and readtty()  */
+static char *tty_input;
+
+static int escape_count;
+static int echo_check;
+extern int quit_flag;
+
+static int
+readsocket ()
+{
+  int data;
+
+  /* Loop until the socket doesn't have any more data */
+
+  while ((data = readchar (0)) >= 0) 
+    {
+      /* Check for the escape sequence */
+      if (data == '|') 
+       {
+         /* If this is the fourth escape, get out */
+         if (++escape_count == 4) 
+           {
+             return ENTER_DEBUG;
+           }
+         else 
+           { /* This is a '|', but not the fourth in a row. 
+                Continue without echoing it.  If it isn't actually 
+                one of four in a row, it'll be echoed later.  */
+             continue;
+           }
+       }
+      else /* Not a '|' */
+       { 
+         /* Ensure any pending '|'s are flushed.  */
+
+         for ( ; escape_count > 0; escape_count--)
+           putchar('|');
+       }
+               
+      if (data == '\r')                        /* If this is a return character, */
+       continue;                       /*  - just supress it. */
+
+      if (echo_check != -1)            /* Check for echo of user input.  */
+       {
+         if (tty_input[echo_check] == data)
+           {
+             echo_check++;             /* Character matched user input: */
+             continue;                 /* Continue without echoing it.  */
+           }
+         else if ((data == '\n') && (tty_input[echo_check] == '\r')) 
+           { /* End of the line (and of echo checking).  */
+             echo_check = -1;          /* No more echo supression */
+             continue;                 /* Continue without echoing.  */
+           }
+         else
+           { /* Failed check for echo of user input.
+                We now have some suppressed output to flush!  */
+             int j;
+
+             for (j = 0; j < echo_check; j++) 
+               putchar (tty_input[j]);
+             echo_check = -1;
+           }
+       }
+      putchar (data);                  /* Default case: output the char.  */
+    }
+
+  if (data == SERIAL_TIMEOUT)          /* Timeout returned from readchar.  */
+    return READ_MORE;                  /* Try to read some more */
+  else 
+    return FATAL_ERROR;                        /* Trouble, bail out */
+}
+
+static int
+readtty ()
+{
+  int status;
+  int tty_bytecount;
+
+  /* First, read a buffer full from the terminal */
+  tty_bytecount = read (fileno (stdin), tty_input, sizeof (tty_input) - 1);
+  if (tty_bytecount == -1) 
+    {
+      perror ("readtty: read failed");
+      return FATAL_ERROR;
+    }
+
+  /* Remove a quoted newline.  */
+  if (tty_input[tty_bytecount - 1] == '\n' &&
+      tty_input[tty_bytecount - 2] == '\\')    /* line ending in backslash */
+    {
+      tty_input[--tty_bytecount] = 0;          /* remove newline */
+      tty_input[--tty_bytecount] = 0;          /* remove backslash */
+    }
+
+  /* Turn trailing newlines into returns */
+  if (tty_input[tty_bytecount - 1] == '\n')
+    tty_input[tty_bytecount - 1]   =  '\r';
+
+  /* If the line consists of a ~, enter debugging mode.  */
+  if ((tty_input[0] == '~') && (tty_bytecount == 2))
+    return ENTER_DEBUG;
+
+  /* Make this a zero terminated string and write it out */
+  tty_input[tty_bytecount] = 0;
+  if (SERIAL_WRITE (remote_desc, tty_input, tty_bytecount)) 
+    {
+      perror_with_name ("readtty: write failed");
+      return FATAL_ERROR;
+    }
+
+  return READ_MORE;
+}
+
+static int
+minitelnet ()
+{
+  fd_set input;                        /* file descriptors for select */
+  int    tablesize;            /* max number of FDs for select */
+  int    status;
+  int    quit_count = 0;
+
+  extern int escape_count;     /* global shared by readsocket */
+  extern int echo_check;       /* ditto */
+
+  escape_count = 0;
+  echo_check   = -1;
+
+  tablesize = 8 * sizeof (input);
+
+  for (;;) 
+    {
+      /* Check for anything from our socket - doesn't block. Note that
+        this must be done *before* the select as there may be
+        buffered I/O waiting to be processed.  */
+
+      if ((status = readsocket ()) == FATAL_ERROR) 
+       {
+         error ("Debugging terminated by communications error");
+       }
+      else if (status != READ_MORE) 
+       {
+         return (status);
+       }
+
+      fflush(stdout);                  /* Flush output before blocking */
+
+      /* Now block on more socket input or TTY input */
+    
+      FD_ZERO (&input);
+      FD_SET (fileno(stdin), &input);
+      FD_SET (remote_desc->fd, &input);
+
+      status = select (tablesize, &input, 0, 0, 0);
+      if ((status == -1) && (errno != EINTR)) 
+       {
+         error ("Communications error on select %d", errno);
+       }
+
+      /* Handle Control-C typed */
+
+      if (quit_flag) 
+       {
+         if ((++quit_count) == 2)
+           {
+             if (query ("Interrupt GDB? "))
+               {
+                 printf_filtered ("Interrupted by user.\n");
+                 return_to_top_level (RETURN_QUIT);
+               }
+             quit_count = 0;
+           }
+         quit_flag = 0;
+
+         if (remote_break)
+           SERIAL_SEND_BREAK (remote_desc);
+         else
+           SERIAL_WRITE (remote_desc, "\003", 1);
+
+         continue;
+       }
+
+      /* Handle console input */
+
+      if (FD_ISSET (fileno (stdin), &input)) 
+       {
+         quit_count = 0;
+         echo_check = 0;
+         status = readtty ();
+         if (status == READ_MORE)
+           continue;
+
+         return status;        /* telnet session ended */
+       }
+    }
+}
+
+static int
+remote_cisco_wait (pid, status)
+     int pid;
+     struct target_waitstatus *status;
+{
+  if (minitelnet() != ENTER_DEBUG) 
+    {
+      error ("Debugging session terminated by protocol error");
+    }
+  putpkt ("?");
+  return remote_wait (pid, status);
+}
+
+static void
+init_remote_cisco_ops ()
+{
+  remote_cisco_ops.to_shortname = "cisco";
+  remote_cisco_ops.to_longname  = "Remote serial target in cisco-specific protocol";
+  remote_cisco_ops.to_doc       = 
+    "Use a remote machine via TCP, using a cisco-specific protocol.\n\
+Specify the serial device it is connected to (e.g. host:2020).";
+  remote_cisco_ops.to_open              = remote_cisco_open;
+  remote_cisco_ops.to_close             = remote_cisco_close;
+  remote_cisco_ops.to_detach            = remote_detach;
+  remote_cisco_ops.to_resume            = remote_resume;
+  remote_cisco_ops.to_wait              = remote_cisco_wait;
+  remote_cisco_ops.to_fetch_registers   = remote_fetch_registers;
+  remote_cisco_ops.to_store_registers   = remote_store_registers;
+  remote_cisco_ops.to_prepare_to_store  = remote_prepare_to_store;
+  remote_cisco_ops.to_xfer_memory       = remote_xfer_memory;
+  remote_cisco_ops.to_files_info        = remote_files_info;
+  remote_cisco_ops.to_insert_breakpoint = remote_insert_breakpoint;
+  remote_cisco_ops.to_remove_breakpoint = remote_remove_breakpoint;
+  remote_cisco_ops.to_kill              = remote_kill;
+  remote_cisco_ops.to_load              = generic_load;
+  remote_cisco_ops.to_mourn_inferior    = remote_cisco_mourn;
+  remote_cisco_ops.to_thread_alive      = remote_thread_alive;
+  remote_cisco_ops.to_find_new_threads  = remote_threads_info;
+  remote_cisco_ops.to_stratum           = process_stratum;
+  remote_cisco_ops.to_has_all_memory    = 1;
+  remote_cisco_ops.to_has_memory        = 1;
+  remote_cisco_ops.to_has_stack         = 1;
+  remote_cisco_ops.to_has_registers     = 1;
+  remote_cisco_ops.to_has_execution     = 1;
+  remote_cisco_ops.to_magic             = OPS_MAGIC;
+}
+
+static void
+build_remote_gdbarch_data ()
+{
+  tty_input = xmalloc (PBUFSIZ);
+}
+
 
 void
 _initialize_remote ()
 {
+  /* architecture specific data */
+  build_remote_gdbarch_data ();
+  register_gdbarch_swap (&tty_input, sizeof (&tty_input), NULL);
+  register_gdbarch_swap (NULL, 0, build_remote_gdbarch_data);
+
+  /* runtime constants - we retain the value of remote_write_size
+     across architecture swaps. */
+  remote_write_size = PBUFSIZ;
+
   init_remote_ops ();
   add_target (&remote_ops);
 
   init_extended_remote_ops ();
   add_target (&extended_remote_ops);
-  init_remote_threads ();
+
+  init_remote_cisco_ops ();
+  add_target (&remote_cisco_ops);
+
 #if 0
   init_remote_threadtests ();
 #endif
@@ -3472,8 +4179,13 @@ in a memory packet.\n",
                  &setlist),
      &showlist);  
 
-  add_show_from_set (add_set_cmd ("remotebinarydownload", no_class,
-                                 var_boolean, (char *) &remote_binary_download,
-                                 "Set binary downloads.\n", &setlist),
-                    &showlist);
+  add_show_from_set 
+    (add_set_cmd ("remotebinarydownload", no_class,
+                 var_boolean, (char *) &remote_binary_download,
+                 "Set binary downloads.\n", &setlist),
+     &showlist);
+
+  add_info ("remote-process", remote_info_process,
+           "Query the remote system for process info.");
+
 }
This page took 0.058636 seconds and 4 git commands to generate.