1999-02-10 Jason Molenda (jsm@bugshack.cygnus.com)
[deliverable/binutils-gdb.git] / gdb / remote.c
index e6a2252d93b0263b05bbdbc5d4bfc6b4444becac..bcdc48f0288eba2a6f986deb6cfcc0d9b261eef1 100644 (file)
@@ -223,7 +223,7 @@ static void remote_fetch_registers PARAMS ((int regno));
 static void remote_resume PARAMS ((int pid, int step,
                                   enum target_signal siggnal));
 
-static int remote_start_remote PARAMS ((char *dummy));
+static int remote_start_remote PARAMS ((PTR));
 
 static void remote_open PARAMS ((char *name, int from_tty));
 
@@ -286,6 +286,8 @@ static int ishex PARAMS ((int ch, int *val));
 
 static int stubhex PARAMS ((int ch));
 
+static int remote_query PARAMS ((char, char *, char *, int *));
+
 static int hexnumstr PARAMS ((char *, ULONGEST));
 
 static CORE_ADDR remote_address_masked PARAMS ((CORE_ADDR));
@@ -1352,7 +1354,7 @@ get_offsets ()
 
 static int
 remote_start_remote (dummy)
-     char *dummy;
+     PTR dummy;
 {
   immediate_quit = 1;          /* Allow user to interrupt it */
 
@@ -1469,7 +1471,7 @@ serial device is attached to the remote system (e.g. /dev/ttya).");
   /* Start the remote connection; if error (0), discard this target.
      In particular, if the user quits, be sure to discard it
      (we'd be in an inconsistent state otherwise).  */
-  if (!catch_errors (remote_start_remote, (char *)0
+  if (!catch_errors (remote_start_remote, NULL
                     "Couldn't establish connection to remote target\n", 
                     RETURN_MASK_ALL))
     {
@@ -2377,7 +2379,9 @@ print_packet (buf)
 
 
 /* Send a packet to the remote machine, with error checking.  The data
-   of the packet is in BUF.  */
+   of the packet is in BUF.  The string in BUF can be at most  PBUFSIZ - 5
+   to account for the $, # and checksum, and for a possible /0 if we are
+   debugging (remote_debug) and want to print the sent packet as a string */
 
 int
 putpkt (buf)
@@ -2680,7 +2684,7 @@ remote_kill ()
 
   /* Use catch_errors so the user can quit from gdb even when we aren't on
      speaking terms with the remote system.  */
-  catch_errors (putpkt, "k", "", RETURN_MASK_ERROR);
+  catch_errors ((catch_errors_ftype*) putpkt, "k", "", RETURN_MASK_ERROR);
 
   /* Don't wait for it to die.  I'm not really sure it matters whether
      we do or not.  For the existing stubs, kill is a noop.  */
@@ -2969,6 +2973,76 @@ the loaded file\n");
     printf_filtered ("No loaded section named '%s'.\n", args);
 }
 
+static int
+remote_query (query_type, buf, outbuf, bufsiz)
+     char query_type;
+     char *buf;
+     char *outbuf;
+     int *bufsiz;
+{
+  int i;
+  char buf2[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 
+     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 )
+    {
+      *bufsiz = PBUFSIZ;
+      return -1;
+    }
+
+  /* except for querying the minimum buffer size, target must be open */
+  if (! remote_desc)
+    error ("remote query is only available after target open");
+
+  /* we only take uppercase letters as query types, at least for now */
+  if ( (query_type < 'A') || (query_type > 'Z') )
+    error ("invalid remote query type");
+
+  if (! buf)
+    error ("null remote query specified");
+
+  if (! outbuf)
+    error ("remote query requires a buffer to receive data");
+
+  outbuf[0] = '\0';
+
+  *p2++ = 'q';
+  *p2++ = query_type;
+
+  /* we used one buffer char for the remote protocol q command and another
+     for the query type.  As the remote protocol encapsulation uses 4 chars
+     plus one extra in case we are debugging (remote_debug),
+     we have PBUFZIZ - 7 left to pack the query string */
+  i = 0;
+  while ( buf[i] && (i < (PBUFSIZ - 8)) )
+    {
+      /* bad caller may have sent forbidden characters */
+      if ( (!isprint(buf[i])) || (buf[i] == '$') || (buf[i] == '#') )
+        error ("illegal characters in query string");
+
+      *p2++ = buf[i];
+      i++;
+    }
+  *p2 = buf[i];
+
+  if ( buf[i] )
+    error ("query larger than available buffer");
+
+  i = putpkt (buf2);
+  if ( i < 0 ) return i;
+
+  getpkt (outbuf, 0);
+
+  return 0;
+}
+
 static void
 packet_command (args, from_tty)
      char *args;
@@ -3179,12 +3253,14 @@ Specify the serial device it is connected to (e.g. /dev/ttya).";
   remote_ops.to_mourn_inferior = remote_mourn;
   remote_ops.to_thread_alive = remote_thread_alive;
   remote_ops.to_stop = remote_stop;
+  remote_ops.to_query = remote_query;
   remote_ops.to_stratum = process_stratum;
   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_has_thread_control = tc_schedlock; /* can lock scheduler */
   remote_ops.to_magic = OPS_MAGIC;     
 }
 
This page took 0.026762 seconds and 4 git commands to generate.