Thu May 21 13:14:25 1998 John Metzler <jmetzler@cygnus.com>
[deliverable/binutils-gdb.git] / gdb / remote.c
index 25c873427c9f37cc640fb09fc61c2579186bc8f1..8f94e161d1df05261882e6d05d2bb34926a09f3a 100644 (file)
@@ -1,5 +1,5 @@
 /* Remote target communications for serial-line targets in custom GDB protocol
-   Copyright 1988, 1991, 1992, 1993, 1994, 1995, 1996 Free Software Foundation, Inc.
+   Copyright 1988, 1991, 1992, 1993, 1994, 1995, 1996, 1997 Free Software Foundation, Inc.
 
 This file is part of GDB.
 
@@ -97,10 +97,11 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
                                        If AA..AA is omitted,
                                        resume at same address.
 
-       continue with   Csig;AA         Continue with signal sig (hex signal
-       signal                          number).
+       continue with   Csig;AA..AA     Continue with signal sig (hex signal
+       signal                          number).  If ;AA..AA is omitted, resume
+                                       at same address.
 
-       step with       Ssig;AA         Like 'C' but step not continue.
+       step with       Ssig;AA..AA     Like 'C' but step not continue.
        signal
 
        last signal     ?               Reply the current reason for stopping.
@@ -188,7 +189,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
 #include "gdbcmd.h"
 #include "objfiles.h"
 #include "gdb-stabs.h"
-#include "thread.h"
+#include "gdbthread.h"
 
 #include "dcache.h"
 
@@ -226,7 +227,7 @@ static void remote_open PARAMS ((char *name, int from_tty));
 
 static void extended_remote_open PARAMS ((char *name, int from_tty));
 
-static void remote_open_1 PARAMS ((char *, int, struct target_ops *));
+static void remote_open_1 PARAMS ((char *, int, struct target_ops *, int extended_p));
 
 static void remote_close PARAMS ((int quitting));
 
@@ -242,10 +243,6 @@ static void extended_remote_create_inferior PARAMS ((char *, char *, char **));
 
 static void remote_mourn_1 PARAMS ((struct target_ops *));
 
-static void getpkt PARAMS ((char *buf, int forever));
-
-static int putpkt PARAMS ((char *buf));
-
 static void remote_send PARAMS ((char *buf));
 
 static int readchar PARAMS ((int timeout));
@@ -256,8 +253,6 @@ static void remote_kill PARAMS ((void));
 
 static int tohex PARAMS ((int nib));
 
-static int fromhex PARAMS ((int a));
-
 static void remote_detach PARAMS ((char *args, int from_tty));
 
 static void remote_interrupt PARAMS ((int signo));
@@ -266,15 +261,131 @@ static void remote_interrupt_twice PARAMS ((int signo));
 
 static void interrupt_query PARAMS ((void));
 
-extern struct target_ops remote_ops;   /* Forward decl */
-extern struct target_ops extended_remote_ops;  /* Forward decl */
+static void set_thread PARAMS ((int, int));
+
+static int remote_thread_alive PARAMS ((int));
+
+static void get_offsets PARAMS ((void));
+
+static int read_frame PARAMS ((char *));
+
+static int remote_insert_breakpoint PARAMS ((CORE_ADDR, char *));
+
+static int remote_remove_breakpoint PARAMS ((CORE_ADDR, char *));
+
+static int hexnumlen PARAMS ((ULONGEST num));
+
+/* exported functions */
+
+extern int fromhex PARAMS ((int a));
+extern void getpkt PARAMS ((char *buf, int forever));
+extern int putpkt PARAMS ((char *buf));
+
+/* Define the target subroutine names */
+
+static struct target_ops remote_ops ;
+
+static void init_remote_ops(void)
+{
+  remote_ops.to_shortname =   "remote";                
+  remote_ops.to_longname =   "Remote serial target in gdb-specific protocol";
+  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)." ;  
+  remote_ops.to_open =   remote_open;          
+  remote_ops.to_close =   remote_close;                
+  remote_ops.to_attach =   NULL;               
+  remote_ops.to_detach =   remote_detach;      
+  remote_ops.to_resume =   remote_resume;      
+  remote_ops.to_wait  =   remote_wait;         
+  remote_ops.to_fetch_registers  =   remote_fetch_registers;
+  remote_ops.to_store_registers  =   remote_store_registers;
+  remote_ops.to_prepare_to_store =   remote_prepare_to_store;
+  remote_ops.to_xfer_memory  =   remote_xfer_memory;   
+  remote_ops.to_files_info  =   remote_files_info;     
+  remote_ops.to_insert_breakpoint =   remote_insert_breakpoint;
+  remote_ops.to_remove_breakpoint =   remote_remove_breakpoint;
+  remote_ops.to_terminal_init  =   NULL;               
+  remote_ops.to_terminal_inferior =   NULL;            
+  remote_ops.to_terminal_ours_for_output =   NULL;
+  remote_ops.to_terminal_ours  =   NULL;       
+  remote_ops.to_terminal_info  =   NULL;       
+  remote_ops.to_kill  =   remote_kill;         
+  remote_ops.to_load  =   generic_load;                
+  remote_ops.to_lookup_symbol =   NULL;                
+  remote_ops.to_create_inferior =   NULL;      
+  remote_ops.to_mourn_inferior =   remote_mourn;
+  remote_ops.to_can_run  =   0;                        
+  remote_ops.to_notice_signals =   0;          
+  remote_ops.to_thread_alive  =   remote_thread_alive;
+  remote_ops.to_stop  =   0;           
+  remote_ops.to_stratum =   process_stratum;
+  remote_ops.DONT_USE =   NULL;                
+  remote_ops.to_has_all_memory =   1;  
+  remote_ops.to_has_memory =   1;      
+  remote_ops.to_has_stack =   1;       
+  remote_ops.to_has_registers =   1;   
+  remote_ops.to_has_execution =   1;   
+  remote_ops.to_sections =   NULL;     
+  remote_ops.to_sections_end =   NULL; 
+  remote_ops.to_magic =   OPS_MAGIC ;  
+} /* init_remote_ops */
+
+static struct target_ops extended_remote_ops ;
+
+static void init_extended_remote_ops(void) 
+{
+  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_close =   remote_close;       
+  extended_remote_ops.to_attach =   NULL;              
+  extended_remote_ops.to_detach =   remote_detach;     
+  extended_remote_ops.to_resume =   remote_resume;     
+  extended_remote_ops.to_wait  =   remote_wait;                
+  extended_remote_ops.to_fetch_registers  =   remote_fetch_registers;
+  extended_remote_ops.to_store_registers  =   remote_store_registers;  
+  extended_remote_ops.to_prepare_to_store =   remote_prepare_to_store;
+  extended_remote_ops.to_xfer_memory  =   remote_xfer_memory;  
+  extended_remote_ops.to_files_info  =   remote_files_info;    
+  extended_remote_ops.to_insert_breakpoint =   remote_insert_breakpoint;
+  extended_remote_ops.to_remove_breakpoint =   remote_remove_breakpoint;
+  extended_remote_ops.to_terminal_init  =   NULL;              
+  extended_remote_ops.to_terminal_inferior =   NULL;           
+  extended_remote_ops.to_terminal_ours_for_output =   NULL;
+  extended_remote_ops.to_terminal_ours  =   NULL;      
+  extended_remote_ops.to_terminal_info  =   NULL;      
+  extended_remote_ops.to_kill  =   remote_kill;                
+  extended_remote_ops.to_load  =   generic_load;       
+  extended_remote_ops.to_lookup_symbol =   NULL;       
+  extended_remote_ops.to_create_inferior =   extended_remote_create_inferior;
+  extended_remote_ops.to_mourn_inferior =   extended_remote_mourn;
+  extended_remote_ops.to_can_run  =   0;                       
+  extended_remote_ops.to_notice_signals =   0;                 
+  extended_remote_ops.to_thread_alive  =   remote_thread_alive;
+  extended_remote_ops.to_stop  =   0;                  
+  extended_remote_ops.to_stratum =   process_stratum;
+  extended_remote_ops.DONT_USE =   NULL;       
+  extended_remote_ops.to_has_all_memory =   1; 
+  extended_remote_ops.to_has_memory =   1;     
+  extended_remote_ops.to_has_stack =   1;      
+  extended_remote_ops.to_has_registers =   1;  
+  extended_remote_ops.to_has_execution =   1;  
+  extended_remote_ops.to_sections =   NULL;    
+  extended_remote_ops.to_sections_end =   NULL;
+  extended_remote_ops.to_magic =   OPS_MAGIC ;
+} 
+
 
 /* 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
    be plenty.  */
 
-static int remote_timeout = 2;
+/* Changed to allow option to set timeout value.
+   was static int remote_timeout = 2; */
+extern int remote_timeout;
 
 /* This variable chooses whether to send a ^C or a break when the user
    requests program interruption.  Although ^C is usually what remote
@@ -286,7 +397,7 @@ static int remote_break;
 /* Descriptor for I/O to remote machine.  Initialize it to NULL so that
    remote_open knows that we don't have a file open when the program
    starts.  */
-serial_t remote_desc = NULL;
+static serial_t remote_desc = NULL;
 
 /* 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
@@ -315,10 +426,23 @@ serial_t remote_desc = NULL;
 
 static int remote_write_size = PBUFSIZ;
 
+/* This is the size (in chars) of the first response to the `g' command.  This
+   is used to limit the size of the memory read and write commands to prevent
+   stub buffers from overflowing.  The size does not include headers and
+   trailers, it is only the payload size. */
+
+static int remote_register_buf_size = 0;
+
 /* Should we try the 'P' request?  If this is set to one when the stub
    doesn't support 'P', the only consequence is some unnecessary traffic.  */
 static int stub_supports_P = 1;
 
+/* These are pointers to hook functions that may be set in order to
+   modify resume/wait behavior for a particular architecture.  */
+
+void (*target_resume_hook) PARAMS ((void));
+void (*target_wait_loop_hook) PARAMS ((void));
+
 \f
 /* These are the threads which we last sent to the remote system.  -1 for all
    or -2 for not sent yet.  */
@@ -407,8 +531,8 @@ remote_close (quitting)
 static void
 get_offsets ()
 {
-  char buf[PBUFSIZ];
-  int nvals;
+  char buf[PBUFSIZ], *ptr;
+  int lose;
   CORE_ADDR text_addr, data_addr, bss_addr;
   struct section_offsets *offs;
 
@@ -425,9 +549,43 @@ get_offsets ()
       return;
     }
 
-  nvals = sscanf (buf, "Text=%lx;Data=%lx;Bss=%lx", &text_addr, &data_addr,
-                 &bss_addr);
-  if (nvals != 3)
+  /* Pick up each field in turn.  This used to be done with scanf, but
+     scanf will make trouble if CORE_ADDR size doesn't match
+     conversion directives correctly.  The following code will work
+     with any size of CORE_ADDR.  */
+  text_addr = data_addr = bss_addr = 0;
+  ptr = buf;
+  lose = 0;
+
+  if (strncmp (ptr, "Text=", 5) == 0)
+    {
+      ptr += 5;
+      /* Don't use strtol, could lose on big values.  */
+      while (*ptr && *ptr != ';')
+       text_addr = (text_addr << 4) + fromhex (*ptr++);
+    }
+  else
+    lose = 1;
+
+  if (!lose && strncmp (ptr, ";Data=", 6) == 0)
+    {
+      ptr += 6;
+      while (*ptr && *ptr != ';')
+       data_addr = (data_addr << 4) + fromhex (*ptr++);
+    }
+  else
+    lose = 1;
+
+  if (!lose && strncmp (ptr, ";Bss=", 5) == 0)
+    {
+      ptr += 5;
+      while (*ptr && *ptr != ';')
+       bss_addr = (bss_addr << 4) + fromhex (*ptr++);
+    }
+  else
+    lose = 1;
+
+  if (lose)
     error ("Malformed response to offset query, %s", buf);
 
   if (symfile_objfile == NULL)
@@ -484,7 +642,7 @@ remote_open (name, from_tty)
      char *name;
      int from_tty;
 {
-  remote_open_1 (name, from_tty, &remote_ops);
+  remote_open_1 (name, from_tty, &remote_ops, 0);
 }
 
 /* Open a connection to a remote debugger using the extended
@@ -495,25 +653,18 @@ extended_remote_open (name, from_tty)
      char *name;
      int from_tty;
 {
-  char buf[PBUFSIZ];
-
-  /* Do the basic remote open stuff.  */
-  remote_open_1 (name, from_tty, &extended_remote_ops);
-
-  /* Now tell the remote that we're using the extended protocol.  */
-  putpkt ("!");
-  getpkt (buf, 0);
-
+  remote_open_1 (name, from_tty, &extended_remote_ops, 1/*extended_p*/);
 }
 
 /* Generic code for opening a connection to a remote target.  */
 static DCACHE *remote_dcache;
 
 static void
-remote_open_1 (name, from_tty, target)
+remote_open_1 (name, from_tty, target, extended_p)
      char *name;
      int from_tty;
      struct target_ops *target;
+     int extended_p;
 {
   if (name == 0)
     error ("To open a remote debug connection, you need to specify what serial\n\
@@ -575,6 +726,15 @@ device is attached to the remote system (e.g. /dev/ttya).");
   if (!catch_errors (remote_start_remote, (char *)0, 
                     "Couldn't establish connection to remote target\n", RETURN_MASK_ALL))
     pop_target();
+
+
+  if (extended_p)
+    {
+      /* tell the remote that we're using the extended protocol.  */
+      char buf[PBUFSIZ];
+      putpkt ("!");
+      getpkt (buf, 0);
+    }
 }
 
 /* This takes a program previously attached to and detaches it.  After
@@ -603,7 +763,7 @@ remote_detach (args, from_tty)
 
 /* Convert hex digit A to a number.  */
 
-static int
+int
 fromhex (a)
      int a;
 {
@@ -611,6 +771,8 @@ fromhex (a)
     return a - '0';
   else if (a >= 'a' && a <= 'f')
     return a - 'a' + 10;
+  else if (a >= 'A' && a <= 'F')
+    return a - 'A' + 10;
   else 
     error ("Reply contains invalid hex digit %d", a);
 }
@@ -649,6 +811,11 @@ remote_resume (pid, step, siggnal)
   last_sent_signal = siggnal;
   last_sent_step = step;
 
+  /* A hook for when we need to do something at the last moment before
+     resumption.  */
+  if (target_resume_hook)
+    (*target_resume_hook) ();
+
   if (siggnal != TARGET_SIGNAL_0)
     {
       buf[0] = step ? 'S' : 'C';
@@ -716,6 +883,25 @@ Give up (and stop debugging it)? "))
 /* If nonzero, ignore the next kill.  */
 int kill_kludge;
 
+void
+remote_console_output (msg)
+     char *msg;
+{
+  char *p;
+
+  for (p = msg; *p; p +=2) 
+    {
+      char tb[2];
+      char c = fromhex (p[0]) * 16 + fromhex (p[1]);
+      tb[0] = c;
+      tb[1] = 0;
+      if (target_output_hook)
+       target_output_hook (tb);
+      else 
+       fputs_filtered (tb, gdb_stdout);
+    }
+}
+
 /* 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
@@ -740,6 +926,11 @@ remote_wait (pid, status)
       getpkt ((char *) buf, 1);
       signal (SIGINT, ofunc);
 
+      /* This is a hook for when we need to do something (perhaps the
+        collection of trace data) every time the target stops.  */
+      if (target_wait_loop_hook)
+       (*target_wait_loop_hook) ();
+
       switch (buf[0])
        {
        case 'E':               /* Error of some sort */
@@ -757,7 +948,6 @@ remote_wait (pid, status)
                n... = register number
                r... = register contents
                */
-
            p = &buf[3];        /* after Txx */
 
            while (*p)
@@ -831,17 +1021,7 @@ Packet: '%s'\n",
 
          goto got_status;
        case 'O':               /* Console output */
-         for (p = buf + 1; *p; p +=2) 
-           {
-             char tb[2];
-             char c = fromhex (p[0]) * 16 + fromhex (p[1]);
-             tb[0] = c;
-             tb[1] = 0;
-             if (target_output_hook)
-               target_output_hook (tb);
-             else 
-               fputs_filtered (tb, gdb_stdout);
-           }
+         remote_console_output (buf + 1);
          continue;
        case '\0':
          if (last_sent_signal != TARGET_SIGNAL_0)
@@ -901,6 +1081,9 @@ remote_fetch_registers (regno)
   sprintf (buf, "g");
   remote_send (buf);
 
+  if (remote_register_buf_size == 0)
+    remote_register_buf_size = strlen (buf);
+
   /* Unimplemented registers read as all bits zero.  */
   memset (regs, 0, REGISTER_BYTES);
 
@@ -1054,6 +1237,21 @@ remote_store_word (addr, word)
 #endif /* 0 (unused?) */
 
 \f
+
+/* Return the number of hex digits in num.  */
+
+static int
+hexnumlen (num)
+     ULONGEST num;
+{
+  int i;
+
+  for (i = 0; num != 0; i++)
+    num >>= 4;
+
+  return max (i, 1);
+}
+
 /* Write memory data directly to the remote machine.
    This does not inform the data cache; the data cache uses this.
    MEMADDR is the address in the remote memory space.
@@ -1068,24 +1266,31 @@ remote_write_bytes (memaddr, myaddr, len)
      char *myaddr;
      int len;
 {
-  char buf[PBUFSIZ];
-  int i;
-  char *p;
-  int done;
+  int max_buf_size;            /* Max size of packet output buffer */
+  int origlen;
+
   /* Chop the transfer down if necessary */
 
-  done = 0;
-  while (done < len)
+  max_buf_size = min (remote_write_size, PBUFSIZ);
+  if (remote_register_buf_size != 0)
+    max_buf_size = min (max_buf_size, remote_register_buf_size);
+
+  /* Subtract header overhead from max payload size -  $M<memaddr>,<len>:#nn */
+  max_buf_size -= 2 + hexnumlen (memaddr + len - 1) + 1 + hexnumlen (len) + 4;
+
+  origlen = len;
+  while (len > 0)
     {
-      int todo = len - done;
-      int cando = min(remote_write_size, PBUFSIZ) / 2 - 32; /* num bytes that will fit */
+      char buf[PBUFSIZ];
+      char *p;
+      int todo;
+      int i;
 
-      if (todo > cando)
-       todo = cando;
+      todo = min (len, max_buf_size / 2); /* num bytes that will fit */
 
       /* FIXME-32x64: Need a version of print_address_numeric which puts the
         result in a buffer like sprintf.  */
-      sprintf (buf, "M%lx,%x:", (unsigned long) memaddr + done, todo);
+      sprintf (buf, "M%lx,%x:", (unsigned long) memaddr, todo);
 
       /* We send target system values byte by byte, in increasing byte addresses,
         each byte encoded as two hex characters.  */
@@ -1093,8 +1298,8 @@ remote_write_bytes (memaddr, myaddr, len)
       p = buf + strlen (buf);
       for (i = 0; i < todo; i++)
        {
-         *p++ = tohex ((myaddr[i + done] >> 4) & 0xf);
-         *p++ = tohex (myaddr[i + done] & 0xf);
+         *p++ = tohex ((myaddr[i] >> 4) & 0xf);
+         *p++ = tohex (myaddr[i] & 0xf);
        }
       *p = '\0';
 
@@ -1110,9 +1315,11 @@ remote_write_bytes (memaddr, myaddr, len)
          errno = EIO;
          return 0;
        }
-      done += todo;
+      myaddr += todo;
+      memaddr += todo;
+      len -= todo;
     }
-  return len;
+  return origlen;
 }
 
 /* Read memory data directly from the remote machine.
@@ -1129,28 +1336,28 @@ remote_read_bytes (memaddr, myaddr, len)
      char *myaddr;
      int len;
 {
-  char buf[PBUFSIZ];
-  int i;
-  char *p;
-  int done;
-  /* Chop transfer down if neccessary */
+  int max_buf_size;            /* Max size of packet output buffer */
+  int origlen;
 
-#if 0
-  /* FIXME: This is wrong for larger packets */
-  if (len > PBUFSIZ / 2 - 1)
-    abort ();
-#endif
-  done = 0;
-  while (done < len)
+  /* Chop the transfer down if necessary */
+
+  max_buf_size = min (remote_write_size, PBUFSIZ);
+  if (remote_register_buf_size != 0)
+    max_buf_size = min (max_buf_size, remote_register_buf_size);
+
+  origlen = len;
+  while (len > 0)
     {
-      int todo = len - done;
-      int cando = PBUFSIZ / 2 - 32; /* number of bytes that will fit. */
-      if (todo > cando)
-       todo = cando;
+      char buf[PBUFSIZ];
+      char *p;
+      int todo;
+      int i;
+
+      todo = min (len, max_buf_size / 2); /* num bytes that will fit */
 
       /* FIXME-32x64: Need a version of print_address_numeric which puts the
         result in a buffer like sprintf.  */
-      sprintf (buf, "m%lx,%x", (unsigned long) memaddr + done, todo);
+      sprintf (buf, "m%lx,%x", (unsigned long) memaddr, todo);
       putpkt (buf);
       getpkt (buf, 0);
 
@@ -1173,13 +1380,15 @@ remote_read_bytes (memaddr, myaddr, len)
          if (p[0] == 0 || p[1] == 0)
            /* Reply is short.  This means that we were able to read only part
               of what we wanted to.  */
-           return i + done;
-         myaddr[i + done] = fromhex (p[0]) * 16 + fromhex (p[1]);
+           return i + (origlen - len);
+         myaddr[i] = fromhex (p[0]) * 16 + fromhex (p[1]);
          p += 2;
        }
-      done += todo;
+      myaddr += todo;
+      memaddr += todo;
+      len -= todo;
     }
-  return len;
+  return origlen;
 }
 \f
 /* Read or write LEN bytes from inferior memory at MEMADDR, transferring
@@ -1195,6 +1404,16 @@ remote_xfer_memory(memaddr, myaddr, len, should_write, target)
      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)
+    return 0;
+  memaddr = targaddr;
+  len = targlen;
+#endif
+
   return dcache_xfer_memory (remote_dcache, memaddr, myaddr, len, should_write);
 }
 
@@ -1324,7 +1543,7 @@ remote_send (buf)
 /* Send a packet to the remote machine, with error checking.
    The data of the packet is in BUF.  */
 
-static int
+int
 putpkt (buf)
      char *buf;
 {
@@ -1532,7 +1751,7 @@ read_frame (buf)
    If FOREVER, wait forever rather than timing out; this is used
    while the target is executing user code.  */
 
-static void
+void
 getpkt (buf, forever)
      char *buf;
      int forever;
@@ -1595,7 +1814,7 @@ getpkt (buf, forever)
       if (val == 1)
        {
          if (remote_debug)
-           fprintf_unfiltered (gdb_stderr, "Packet received: %s\n", buf);
+           fprintf_unfiltered (gdb_stdout, "Packet received: %s\n", buf);
          SERIAL_WRITE (remote_desc, "+", 1);
          return;
        }
@@ -1765,102 +1984,48 @@ remote_remove_breakpoint (addr, contents_cache)
   return memory_remove_breakpoint (addr, contents_cache);
 #endif /* REMOTE_BREAKPOINT */
 }
-\f
-/* Define the target subroutine names */
 
-struct target_ops remote_ops = {
-  "remote",                    /* to_shortname */
-  "Remote serial target in gdb-specific protocol",     /* to_longname */
-  "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).",  /* to_doc */
-  remote_open,                 /* to_open */
-  remote_close,                        /* to_close */
-  NULL,                                /* to_attach */
-  remote_detach,               /* to_detach */
-  remote_resume,               /* to_resume */
-  remote_wait,                 /* to_wait */
-  remote_fetch_registers,      /* to_fetch_registers */
-  remote_store_registers,      /* to_store_registers */
-  remote_prepare_to_store,     /* to_prepare_to_store */
-  remote_xfer_memory,          /* to_xfer_memory */
-  remote_files_info,           /* to_files_info */
-  remote_insert_breakpoint,    /* to_insert_breakpoint */
-  remote_remove_breakpoint,    /* to_remove_breakpoint */
-  NULL,                                /* to_terminal_init */
-  NULL,                                /* to_terminal_inferior */
-  NULL,                                /* to_terminal_ours_for_output */
-  NULL,                                /* to_terminal_ours */
-  NULL,                                /* to_terminal_info */
-  remote_kill,                 /* to_kill */
-  generic_load,                        /* to_load */
-  NULL,                                /* to_lookup_symbol */
-  NULL,                                /* to_create_inferior */
-  remote_mourn,                        /* to_mourn_inferior */
-  0,                           /* to_can_run */
-  0,                           /* to_notice_signals */
-  remote_thread_alive,         /* to_thread_alive */
-  0,                           /* to_stop */
-  process_stratum,             /* to_stratum */
-  NULL,                                /* to_next */
-  1,                           /* to_has_all_memory */
-  1,                           /* to_has_memory */
-  1,                           /* to_has_stack */
-  1,                           /* to_has_registers */
-  1,                           /* to_has_execution */
-  NULL,                                /* sections */
-  NULL,                                /* sections_end */
-  OPS_MAGIC                    /* to_magic */
-};
-
-struct target_ops extended_remote_ops = {
-  "extended-remote",                   /* to_shortname */
-  "Extended remote serial target in gdb-specific protocol",/* to_longname */
-  "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).",  /* to_doc */
-  extended_remote_open,                        /* to_open */
-  remote_close,                        /* to_close */
-  NULL,                                /* to_attach */
-  remote_detach,               /* to_detach */
-  remote_resume,               /* to_resume */
-  remote_wait,                 /* to_wait */
-  remote_fetch_registers,      /* to_fetch_registers */
-  remote_store_registers,      /* to_store_registers */
-  remote_prepare_to_store,     /* to_prepare_to_store */
-  remote_xfer_memory,          /* to_xfer_memory */
-  remote_files_info,           /* to_files_info */
-
-  remote_insert_breakpoint,    /* to_insert_breakpoint */
-  remote_remove_breakpoint,    /* to_remove_breakpoint */
-
-  NULL,                                /* to_terminal_init */
-  NULL,                                /* to_terminal_inferior */
-  NULL,                                /* to_terminal_ours_for_output */
-  NULL,                                /* to_terminal_ours */
-  NULL,                                /* to_terminal_info */
-  remote_kill,                 /* to_kill */
-  generic_load,                        /* to_load */
-  NULL,                                /* to_lookup_symbol */
-  extended_remote_create_inferior,/* to_create_inferior */
-  extended_remote_mourn,       /* to_mourn_inferior */
-  0,                           /* to_can_run */
-  0,                           /* to_notice_signals */
-  remote_thread_alive,         /* to_thread_alive */
-  0,                           /* to_stop */
-  process_stratum,             /* to_stratum */
-  NULL,                                /* to_next */
-  1,                           /* to_has_all_memory */
-  1,                           /* to_has_memory */
-  1,                           /* to_has_stack */
-  1,                           /* to_has_registers */
-  1,                           /* to_has_execution */
-  NULL,                                /* sections */
-  NULL,                                /* sections_end */
-  OPS_MAGIC                    /* to_magic */
-};
+/* Some targets are only capable of doing downloads, and afterwards they switch
+   to the remote serial protocol.  This function provides a clean way to get
+   from the download target to the remote target.  It's basically just a
+   wrapper so that we don't have to expose any of the internal workings of
+   remote.c.
+
+   Prior to calling this routine, you should shutdown the current target code,
+   else you will get the "A program is being debugged already..." message.
+   Usually a call to pop_target() suffices.
+*/
+
+void
+push_remote_target (name, from_tty)
+     char *name;
+     int from_tty;
+{
+  printf_filtered ("Switching to remote protocol\n");
+  remote_open (name, from_tty);
+}
+
+/* Other targets want to use the entire remote serial module but with
+   certain remote_ops overridden. */
+
+void
+open_remote_target (name, from_tty, target, extended_p)
+     char *name;
+     int from_tty;
+     struct target_ops *target;
+     int extended_p;
+{
+  printf_filtered ("Selecting the %sremote protocol\n",
+                  (extended_p ? "extended-" : ""));
+  remote_open_1 (name, from_tty, target, extended_p);
+}
+
 
 void
 _initialize_remote ()
 {
+  init_remote_ops() ;
+  init_extended__remote_ops() ;
   add_target (&remote_ops);
   add_target (&extended_remote_ops);
 
This page took 0.031502 seconds and 4 git commands to generate.