import gdb-1999-08-09 snapshot
[deliverable/binutils-gdb.git] / gdb / remote-rdi.c
index 6bfcb8bed50969e8de16e485065d12ef226f75f7..49ed2c71623f6356c1d28d4efb37977db7bb2b5c 100644 (file)
@@ -1,22 +1,22 @@
 /* GDB interface to ARM RDI library.
-   Copyright 1997 Free Software Foundation, Inc.
+   Copyright 1997, 1998 Free Software Foundation, Inc.
 
-This file is part of GDB.
+   This file is part of GDB.
 
-This program is free software; you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 2 of the License, or
-(at your option) any later version.
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 2 of the License, or
+   (at your option) any later version.
 
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with this program; if not, write to the Free Software
-Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
 
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 59 Temple Place - Suite 330,
+   Boston, MA 02111-1307, USA.  */
 
 #include "defs.h"
 #include "gdb_string.h"
@@ -43,20 +43,22 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
 #include "rdi-share/adp.h"
 #include "rdi-share/hsys.h"
 
+extern int isascii PARAMS ((int));
+
 /* Prototypes for local functions */
 
-static void arm_rdi_files_info PARAMS ((struct target_ops *ignore));
+static void arm_rdi_files_info PARAMS ((struct target_ops * ignore));
 
 static int arm_rdi_xfer_memory PARAMS ((CORE_ADDR memaddr, char *myaddr,
-                                      int len, int should_write,
-                                      struct target_ops *target));
+                                       int len, int should_write,
+                                       struct target_ops * target));
 
 static void arm_rdi_prepare_to_store PARAMS ((void));
 
 static void arm_rdi_fetch_registers PARAMS ((int regno));
 
 static void arm_rdi_resume PARAMS ((int pid, int step,
-                                  enum target_signal siggnal));
+                                   enum target_signal siggnal));
 
 static int arm_rdi_start_remote PARAMS ((char *dummy));
 
@@ -73,7 +75,7 @@ static void arm_rdi_mourn PARAMS ((void));
 
 static void arm_rdi_send PARAMS ((char *buf));
 
-static int arm_rdi_wait PARAMS ((int pid, struct target_waitstatus *status));
+static int arm_rdi_wait PARAMS ((int pid, struct target_waitstatus * status));
 
 static void arm_rdi_kill PARAMS ((void));
 
@@ -93,7 +95,9 @@ static char *rdi_error_message PARAMS ((int err));
 
 static enum target_signal rdi_error_signal PARAMS ((int err));
 
-extern struct target_ops arm_rdi_ops;  /* Forward decl */
+/* Global variables.  */
+
+struct target_ops arm_rdi_ops;
 
 static struct Dbg_ConfigBlock gdb_config;
 
@@ -105,13 +109,15 @@ static int execute_status;
 
 /* A little list of breakpoints that have been set.  */
 
-static struct local_bp_list_entry {
-  CORE_ADDR addr;
-  PointHandle point;
-  struct local_bp_list_entry *next;
-} *local_bp_list;
-
+static struct local_bp_list_entry
+  {
+    CORE_ADDR addr;
+    PointHandle point;
+    struct local_bp_list_entry *next;
+  }
+ *local_bp_list;
 \f
+
 /* Stub for catch_errors.  */
 
 static int
@@ -125,9 +131,9 @@ arm_rdi_start_remote (dummy)
    these to forward output from the target system and so forth.  */
 
 void
-voiddummy()
+voiddummy ()
 {
-  printf("void dummy\n");
+  fprintf_unfiltered (gdb_stdout, "void dummy\n");
 }
 
 static void
@@ -136,7 +142,7 @@ myprint (arg, format, ap)
      const char *format;
      va_list ap;
 {
-  vfprintf (stdout, format, ap);
+  vfprintf_unfiltered (gdb_stdout, format, ap);
 }
 
 static void
@@ -144,7 +150,8 @@ mywritec (arg, c)
      PTR arg;
      int c;
 {
-  fputc (c, (FILE *) arg);
+  if (isascii (c))
+    fputc_unfiltered (c, gdb_stdout);
 }
 
 static int
@@ -153,7 +160,20 @@ mywrite (arg, buffer, len)
      char const *buffer;
      int len;
 {
-  return fwrite (buffer, 1, len, stdout);
+  int i;
+  char *e;
+
+  e = (char *) buffer;
+  for (i = 0; i < len; i++)
+    {
+      if (isascii ((int) *e))
+       {
+         fputc_unfiltered ((int) *e, gdb_stdout);
+         e++;
+       }
+    }
+
+  return len;
 }
 
 static void
@@ -168,7 +188,7 @@ mypause (arg)
 static int
 myreadc (arg)
      PTR arg;
-{ 
+{
   return fgetc (stdin);
 }
 
@@ -178,7 +198,7 @@ mygets (arg, buffer, len)
      char *buffer;
      int len;
 {
-  return fgets(buffer, len, stdin);
+  return fgets (buffer, len, stdin);
 }
 
 /* Prevent multiple calls to angel_RDI_close().  */
@@ -206,7 +226,7 @@ device is attached to the remote system (e.g. /dev/ttya).");
   if (rslt != adp_ok)
     error ("Could not open device \"%s\"", name);
 
-  gdb_config.bytesex = 2 | (target_byte_order == BIG_ENDIAN ? 1 : 0);
+  gdb_config.bytesex = 2 | (TARGET_BYTE_ORDER == BIG_ENDIAN ? 1 : 0);
   gdb_config.fpe = 1;
   gdb_config.rditype = 2;
   gdb_config.heartbeat_on = 1;
@@ -214,17 +234,17 @@ device is attached to the remote system (e.g. /dev/ttya).");
 
   gdb_hostif.dbgprint = myprint;
   gdb_hostif.dbgpause = mypause;
-  gdb_hostif.dbgarg = stdout;
+  gdb_hostif.dbgarg = NULL;
   gdb_hostif.writec = mywritec;
   gdb_hostif.readc = myreadc;
   gdb_hostif.write = mywrite;
   gdb_hostif.gets = mygets;
-  gdb_hostif.hostosarg = stdout;
+  gdb_hostif.hostosarg = NULL;
   gdb_hostif.reset = voiddummy;
 
   rslt = angel_RDI_open (10, &gdb_config, &gdb_hostif, NULL);
   if (rslt == RDIError_BigEndian || rslt == RDIError_LittleEndian)
-    ;  /* do nothing, this is the expected return */
+    ;                          /* do nothing, this is the expected return */
   else if (rslt)
     {
       printf_filtered ("RDI_open: %s\n", rdi_error_message (rslt));
@@ -256,28 +276,6 @@ device is attached to the remote system (e.g. /dev/ttya).");
       printf_filtered ("RDI_info: %s\n", rdi_error_message (rslt));
     }
 
-  /*
-  ** There's no point asking if the target's an ICEBreaker, unless
-  ** you're going to do something with the answer. All it does is provoke
-  ** an error message on non-ICE targets
-  rslt = angel_RDI_info (RDIInfo_Icebreaker, & arg1, & arg2);
-  if (rslt)
-    {
-      printf_filtered ("RDI_info: %s\n", rdi_error_message (rslt));
-    }
-    */
-
-  /*
-  ** There's no point asking if the target can accept a configuration download,
-  ** unless you're going to do something with the answer. All it does is
-  ** provoke an error message on non-ICE targets
-  rslt = angel_RDI_info (RDIInfo_DownLoad, & arg1, & arg2);
-  if (rslt)
-    {
-      printf_filtered ("RDI_info: %s\n", rdi_error_message (rslt));
-    }
-    */
-
   rslt = angel_RDI_info (RDIInfo_GetLoadSize, &arg1, &arg2);
   if (rslt)
     {
@@ -321,8 +319,8 @@ device is attached to the remote system (e.g. /dev/ttya).");
   }
 
   printf_filtered ("Connected to ARM RDI target.\n");
-
   closed_already = 0;
+  inferior_pid = 42;
 }
 
 /* Start an inferior process and set inferior_pid to its pid.
@@ -345,15 +343,15 @@ arm_rdi_create_inferior (exec_file, args, env)
   CORE_ADDR entry_point;
 
   if (exec_file == 0 || exec_bfd == 0)
-   error ("No exec file specified.");
+    error ("No executable file specified.");
 
   entry_point = (CORE_ADDR) bfd_get_start_address (exec_bfd);
 
-  arm_rdi_kill ();      
+  arm_rdi_kill ();
   remove_breakpoints ();
   init_wait_for_inferior ();
 
-  len = strlen (exec_file) + 1 + strlen (args) + 1 + /*slop*/ 10;
+  len = strlen (exec_file) + 1 + strlen (args) + 1 + /*slop */ 10;
   arg_buf = (char *) alloca (len);
   arg_buf[0] = '\0';
   strcat (arg_buf, exec_file);
@@ -361,24 +359,24 @@ arm_rdi_create_inferior (exec_file, args, env)
   strcat (arg_buf, args);
 
   inferior_pid = 42;
-  insert_breakpoints ();  /* Needed to get correct instruction in cache */
+  insert_breakpoints ();       /* Needed to get correct instruction in cache */
 
-  if ( env != NULL)
+  if (env != NULL)
     {
       while (*env)
        {
-         if (strncmp(*env, "MEMSIZE=", sizeof("MEMSIZE=")-1)==0)
+         if (strncmp (*env, "MEMSIZE=", sizeof ("MEMSIZE=") - 1) == 0)
            {
              unsigned long top_of_memory;
              char *end_of_num;
 
              /* Set up memory limit */
-             top_of_memory = strtoul(*env + sizeof("MEMSIZE=")-1,
-                                     &end_of_num, 0);
+             top_of_memory = strtoul (*env + sizeof ("MEMSIZE=") - 1,
+                                      &end_of_num, 0);
              printf_filtered ("Setting top-of-memory to 0x%x\n",
                               top_of_memory);
-         
-             rslt=angel_RDI_info (RDIInfo_SetTopMem, &top_of_memory, &arg2);
+
+             rslt = angel_RDI_info (RDIInfo_SetTopMem, &top_of_memory, &arg2);
              if (rslt)
                {
                  printf_filtered ("RDI_info: %s\n", rdi_error_message (rslt));
@@ -389,7 +387,7 @@ arm_rdi_create_inferior (exec_file, args, env)
     }
 
   arg1 = (unsigned long) arg_buf;
-  rslt = angel_RDI_info (RDISet_Cmdline, /* &arg1 */ (unsigned long *)arg_buf, &arg2);
+  rslt = angel_RDI_info (RDISet_Cmdline, /* &arg1 */ (unsigned long *) arg_buf, &arg2);
   if (rslt)
     {
       printf_filtered ("RDI_info: %s\n", rdi_error_message (rslt));
@@ -408,7 +406,7 @@ arm_rdi_detach (args, from_tty)
      char *args;
      int from_tty;
 {
-  /* (anything to do?) */
+  pop_target ();
 }
 
 /* Clean up connection to a remote debugger.  */
@@ -419,7 +417,7 @@ arm_rdi_close (quitting)
 {
   int rslt;
 
-  if (! closed_already)
+  if (!closed_already)
     {
       rslt = angel_RDI_close ();
       if (rslt)
@@ -427,6 +425,8 @@ arm_rdi_close (quitting)
          printf_filtered ("RDI_close: %s\n", rdi_error_message (rslt));
        }
       closed_already = 1;
+      inferior_pid = 0;
+      Adp_CloseDevice ();
     }
 }
 \f
@@ -440,7 +440,7 @@ arm_rdi_resume (pid, step, siggnal)
   int rslt;
   PointHandle point;
 
-  if (0 /* turn on when hardware supports single-stepping */)
+  if (0 /* turn on when hardware supports single-stepping */ )
     {
       rslt = angel_RDI_step (1, &point);
       if (rslt)
@@ -482,7 +482,7 @@ arm_rdi_interrupt (signo)
 {
 }
 
-static void (*ofunc)();
+static void (*ofunc) ();
 
 /* The user typed ^C twice.  */
 static void
@@ -507,11 +507,11 @@ arm_rdi_wait (pid, status)
      int pid;
      struct target_waitstatus *status;
 {
-  status->kind = execute_status == RDIError_NoError ?
-    TARGET_WAITKIND_EXITED : TARGET_WAITKIND_STOPPED;
+  status->kind = (execute_status == RDIError_NoError ?
+                 TARGET_WAITKIND_EXITED : TARGET_WAITKIND_STOPPED);
 
   /* convert stopped code from target into right signal */
-  status->value.sig = rdi_error_signal ( execute_status );
+  status->value.sig = rdi_error_signal (execute_status);
 
   return inferior_pid;
 }
@@ -527,7 +527,7 @@ arm_rdi_fetch_registers (regno)
   unsigned long rawreg, rawregs[32];
   char cookedreg[4];
 
-  if (regno == -1) 
+  if (regno == -1)
     {
       rslt = angel_RDI_CPUread (255, 0x27fff, rawregs);
       if (rslt)
@@ -569,7 +569,7 @@ arm_rdi_fetch_registers (regno)
     }
 }
 
-static void 
+static void
 arm_rdi_prepare_to_store ()
 {
   /* Nothing to do.  */
@@ -587,7 +587,7 @@ arm_rdi_store_registers (regno)
   /* These need to be able to take 'floating point register' contents */
   unsigned long rawreg[3], rawerreg[3];
 
-  if (regno  == -1) 
+  if (regno == -1)
     {
       for (regno = 0; regno < NUM_REGS; regno++)
        arm_rdi_store_registers (regno);
@@ -622,12 +622,12 @@ arm_rdi_store_registers (regno)
 
 /* ARGSUSED */
 static int
-arm_rdi_xfer_memory(memaddr, myaddr, len, should_write, target)
+arm_rdi_xfer_memory (memaddr, myaddr, len, should_write, target)
      CORE_ADDR memaddr;
      char *myaddr;
      int len;
      int should_write;
-     struct target_ops *target;                        /* ignored */
+     struct target_ops *target;        /* ignored */
 {
   int rslt, i;
 
@@ -639,7 +639,7 @@ arm_rdi_xfer_memory(memaddr, myaddr, len, should_write, target)
          printf_filtered ("RDI_write: %s\n", rdi_error_message (rslt));
        }
     }
-  else 
+  else
     {
       rslt = angel_RDI_read (memaddr, myaddr, &len);
       if (rslt)
@@ -672,7 +672,7 @@ arm_rdi_files_info (ignore)
     printf_filtered ("Target can do profiling.\n");
   if (arg1 & (1 << 4))
     printf_filtered ("Target is real hardware.\n");
-  
+
   rslt = angel_RDI_info (RDIInfo_Step, &arg1, &arg2);
   if (rslt)
     {
@@ -783,7 +783,7 @@ rdi_error_message (err)
 {
   switch (err)
     {
-    case RDIError_NoError: 
+    case RDIError_NoError:
       return "no error";
     case RDIError_Reset:
       return "debuggee reset";
@@ -862,7 +862,7 @@ rdi_error_message (err)
     case RDIError_UndefinedMessage:
       return "internal error, undefined message";
     default:
-      return "undefined error message, should reset target"; 
+      return "undefined error message, should reset target";
     }
 }
 
@@ -877,7 +877,7 @@ rdi_error_signal (err)
     case RDIError_NoError:
       return 0;
     case RDIError_Reset:
-      return TARGET_SIGNAL_TERM; /* ??? */
+      return TARGET_SIGNAL_TERM;       /* ??? */
     case RDIError_UndefinedInstruction:
       return TARGET_SIGNAL_ILL;
     case RDIError_SoftwareInterrupt:
@@ -927,66 +927,55 @@ rdi_error_signal (err)
     case RDIError_UnimplementedMessage:
     case RDIError_UndefinedMessage:
     default:
-      return TARGET_SIGNAL_UNKNOWN; 
+      return TARGET_SIGNAL_UNKNOWN;
     }
 }
 \f
 /* Define the target operations structure.  */
 
-struct target_ops arm_rdi_ops ;
-
-static void init_rdi_ops(void)
+static void
+init_rdi_ops ()
 {
-  arm_rdi_ops.to_shortname =   "rdi";  
-  arm_rdi_ops.to_longname =   "ARM RDI";
-  arm_rdi_ops.to_doc =   "Use a remote ARM-based computer; via the RDI library.\n\
-Specify the serial device it is connected to (e.g. /dev/ttya)." ; 
-  arm_rdi_ops.to_open =   arm_rdi_open;                
-  arm_rdi_ops.to_close =   arm_rdi_close;      
-  arm_rdi_ops.to_attach =   NULL;              
-  arm_rdi_ops.to_detach =   arm_rdi_detach;    
-  arm_rdi_ops.to_resume =   arm_rdi_resume;    
-  arm_rdi_ops.to_wait  =   arm_rdi_wait;       
-  arm_rdi_ops.to_fetch_registers  =   arm_rdi_fetch_registers;
-  arm_rdi_ops.to_store_registers  =   arm_rdi_store_registers;
-  arm_rdi_ops.to_prepare_to_store =   arm_rdi_prepare_to_store;
-  arm_rdi_ops.to_xfer_memory  =   arm_rdi_xfer_memory;
-  arm_rdi_ops.to_files_info  =   arm_rdi_files_info;
-  arm_rdi_ops.to_insert_breakpoint =   arm_rdi_insert_breakpoint;
-  arm_rdi_ops.to_remove_breakpoint =   arm_rdi_remove_breakpoint;      
-  arm_rdi_ops.to_terminal_init  =   NULL;              
-  arm_rdi_ops.to_terminal_inferior =   NULL;           
-  arm_rdi_ops.to_terminal_ours_for_output =   NULL;    
-  arm_rdi_ops.to_terminal_ours  =   NULL;              
-  arm_rdi_ops.to_terminal_info  =   NULL;              
-  arm_rdi_ops.to_kill  =   arm_rdi_kill;               
-  arm_rdi_ops.to_load  =   generic_load;               
-  arm_rdi_ops.to_lookup_symbol =   NULL;                       
-  arm_rdi_ops.to_create_inferior =   arm_rdi_create_inferior;
-  arm_rdi_ops.to_mourn_inferior =   arm_rdi_mourn_inferior;
-  arm_rdi_ops.to_can_run  =   0;               
-  arm_rdi_ops.to_notice_signals =   0;         
-  arm_rdi_ops.to_thread_alive  =   0;          
-  arm_rdi_ops.to_stop  =   0;                  
-  arm_rdi_ops.to_stratum =   process_stratum;
-  arm_rdi_ops.DONT_USE =   NULL;       
-  arm_rdi_ops.to_has_all_memory =   1; 
-  arm_rdi_ops.to_has_memory =   1;     
-  arm_rdi_ops.to_has_stack =   1;      
-  arm_rdi_ops.to_has_registers =   1;  
-  arm_rdi_ops.to_has_execution =   1;  
-  arm_rdi_ops.to_sections =   NULL;    
-  arm_rdi_ops.to_sections_end =   NULL;        
-  arm_rdi_ops.to_magic =   OPS_MAGIC ; 
+  arm_rdi_ops.to_shortname = "rdi";
+  arm_rdi_ops.to_longname = "ARM RDI";
+  arm_rdi_ops.to_doc = "Use a remote ARM-based computer; via the RDI library.\n\
+Specify the serial device it is connected to (e.g. /dev/ttya).";
+  arm_rdi_ops.to_open = arm_rdi_open;
+  arm_rdi_ops.to_close = arm_rdi_close;
+  arm_rdi_ops.to_detach = arm_rdi_detach;
+  arm_rdi_ops.to_resume = arm_rdi_resume;
+  arm_rdi_ops.to_wait = arm_rdi_wait;
+  arm_rdi_ops.to_fetch_registers = arm_rdi_fetch_registers;
+  arm_rdi_ops.to_store_registers = arm_rdi_store_registers;
+  arm_rdi_ops.to_prepare_to_store = arm_rdi_prepare_to_store;
+  arm_rdi_ops.to_xfer_memory = arm_rdi_xfer_memory;
+  arm_rdi_ops.to_files_info = arm_rdi_files_info;
+  arm_rdi_ops.to_insert_breakpoint = arm_rdi_insert_breakpoint;
+  arm_rdi_ops.to_remove_breakpoint = arm_rdi_remove_breakpoint;
+  arm_rdi_ops.to_kill = arm_rdi_kill;
+  arm_rdi_ops.to_load = generic_load;
+  arm_rdi_ops.to_create_inferior = arm_rdi_create_inferior;
+  arm_rdi_ops.to_mourn_inferior = arm_rdi_mourn_inferior;
+  arm_rdi_ops.to_stratum = process_stratum;
+  arm_rdi_ops.to_has_all_memory = 1;
+  arm_rdi_ops.to_has_memory = 1;
+  arm_rdi_ops.to_has_stack = 1;
+  arm_rdi_ops.to_has_registers = 1;
+  arm_rdi_ops.to_has_execution = 1;
+  arm_rdi_ops.to_magic = OPS_MAGIC;
 }
 
 void
 _initialize_remote_rdi ()
 {
-  init_rdi_ops() ;
+  init_rdi_ops ();
   add_target (&arm_rdi_ops);
 }
 
 /* A little dummy to make linking with the library succeed. */
 
-Fail() {}
+int
+Fail ()
+{
+  return 0;
+}
This page took 0.032105 seconds and 4 git commands to generate.