Allow for the possibility that the local labels won't be in the objdump output.
[deliverable/binutils-gdb.git] / gdb / remote-rdi.c
index 69addf6ed35d22dbc68a5d3ffd108d7319d09896..fbd176fa83eea927a8b2ddb8271a59a071cc0a68 100644 (file)
@@ -1,5 +1,5 @@
 /* GDB interface to ARM RDI library.
-   Copyright 1997, 1998 Free Software Foundation, Inc.
+   Copyright 1997, 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
 
    This file is part of GDB.
 
 #include "bfd.h"
 #include "symfile.h"
 #include "target.h"
-#include "wait.h"
 #include "gdbcmd.h"
 #include "objfiles.h"
 #include "gdb-stabs.h"
 #include "gdbthread.h"
 #include "gdbcore.h"
+#include "breakpoint.h"
+#include "completer.h"
+#include "regcache.h"
 
 #ifdef USG
 #include <sys/types.h>
 #include "rdi-share/adp.h"
 #include "rdi-share/hsys.h"
 
-extern int isascii PARAMS ((int));
+extern int isascii (int);
 
 /* Prototypes for local functions */
 
-static void arm_rdi_files_info PARAMS ((struct target_ops * ignore));
+static void arm_rdi_files_info (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));
+static int arm_rdi_xfer_memory (CORE_ADDR memaddr, char *myaddr,
+                               int len, int should_write,
+                               struct mem_attrib *attrib,
+                               struct target_ops *target);
 
-static void arm_rdi_prepare_to_store PARAMS ((void));
+static void arm_rdi_prepare_to_store (void);
 
-static void arm_rdi_fetch_registers PARAMS ((int regno));
+static void arm_rdi_fetch_registers (int regno);
 
-static void arm_rdi_resume PARAMS ((int pid, int step,
-                                   enum target_signal siggnal));
+static void arm_rdi_resume (int pid, int step, enum target_signal siggnal);
 
-static int arm_rdi_start_remote PARAMS ((char *dummy));
+static int arm_rdi_start_remote (char *dummy);
 
-static void arm_rdi_open PARAMS ((char *name, int from_tty));
+static void arm_rdi_open (char *name, int from_tty);
 
-static void arm_rdi_create_inferior PARAMS ((char *exec_file, char *args,
-                                            char **env));
+static void arm_rdi_create_inferior (char *exec_file, char *args, char **env);
 
-static void arm_rdi_close PARAMS ((int quitting));
+static void arm_rdi_close (int quitting);
 
-static void arm_rdi_store_registers PARAMS ((int regno));
+static void arm_rdi_store_registers (int regno);
 
-static void arm_rdi_mourn PARAMS ((void));
+static void arm_rdi_mourn (void);
 
-static void arm_rdi_send PARAMS ((char *buf));
+static void arm_rdi_send (char *buf);
 
-static int arm_rdi_wait PARAMS ((int pid, struct target_waitstatus * status));
+static int arm_rdi_wait (int pid, struct target_waitstatus *status);
 
-static void arm_rdi_kill PARAMS ((void));
+static void arm_rdi_kill (void);
 
-static void arm_rdi_detach PARAMS ((char *args, int from_tty));
+static void arm_rdi_detach (char *args, int from_tty);
 
-static void arm_rdi_interrupt PARAMS ((int signo));
+static void arm_rdi_interrupt (int signo);
 
-static void arm_rdi_interrupt_twice PARAMS ((int signo));
+static void arm_rdi_interrupt_twice (int signo);
 
-static void interrupt_query PARAMS ((void));
+static void interrupt_query (void);
 
-static int arm_rdi_insert_breakpoint PARAMS ((CORE_ADDR, char *));
+static int arm_rdi_insert_breakpoint (CORE_ADDR, char *);
 
-static int arm_rdi_remove_breakpoint PARAMS ((CORE_ADDR, char *));
+static int arm_rdi_remove_breakpoint (CORE_ADDR, char *);
 
-static char *rdi_error_message PARAMS ((int err));
+static char *rdi_error_message (int err);
 
-static enum target_signal rdi_error_signal PARAMS ((int err));
+static enum target_signal rdi_error_signal (int err);
 
 /* Global variables.  */
 
@@ -108,13 +109,13 @@ static int max_load_size;
 static int execute_status;
 
 /* Send heatbeat packets? */
-static int   rdi_heartbeat = 0;
+static int rdi_heartbeat = 0;
 
 /* Target has ROM at address 0. */
 static int rom_at_zero = 0;
 
 /* Enable logging? */
-static int   log_enable = 0;
+static int log_enable = 0;
 
 /* Name of the log file. Default is "rdi.log". */
 static char *log_filename;
@@ -133,8 +134,7 @@ static struct local_bp_list_entry
 /* Stub for catch_errors.  */
 
 static int
-arm_rdi_start_remote (dummy)
-     char *dummy;
+arm_rdi_start_remote (char *dummy)
 {
   return 1;
 }
@@ -143,34 +143,26 @@ arm_rdi_start_remote (dummy)
    these to forward output from the target system and so forth.  */
 
 void
-voiddummy ()
+voiddummy (void *dummy)
 {
   fprintf_unfiltered (gdb_stdout, "void dummy\n");
 }
 
 static void
-myprint (arg, format, ap)
-     PTR arg;
-     const char *format;
-     va_list ap;
+myprint (PTR arg, const char *format, va_list ap)
 {
   vfprintf_unfiltered (gdb_stdout, format, ap);
 }
 
 static void
-mywritec (arg, c)
-     PTR arg;
-     int c;
+mywritec (PTR arg, int c)
 {
   if (isascii (c))
     fputc_unfiltered (c, gdb_stdout);
 }
 
 static int
-mywrite (arg, buffer, len)
-     PTR arg;
-     char const *buffer;
-     int len;
+mywrite (PTR arg, char const *buffer, int len)
 {
   int i;
   char *e;
@@ -189,8 +181,7 @@ mywrite (arg, buffer, len)
 }
 
 static void
-mypause (arg)
-     PTR arg;
+mypause (PTR arg)
 {
 }
 
@@ -198,17 +189,13 @@ mypause (arg)
    being interrupted more carefully */
 
 static int
-myreadc (arg)
-     PTR arg;
+myreadc (PTR arg)
 {
   return fgetc (stdin);
 }
 
 static char *
-mygets (arg, buffer, len)
-     PTR arg;
-     char *buffer;
-     int len;
+mygets (PTR arg, char *buffer, int len)
 {
   return fgets (buffer, len, stdin);
 }
@@ -220,9 +207,7 @@ static int closed_already = 1;
    for communication.  */
 
 static void
-arm_rdi_open (name, from_tty)
-     char *name;
-     int from_tty;
+arm_rdi_open (char *name, int from_tty)
 {
   int rslt, i;
   unsigned long arg1, arg2;
@@ -236,8 +221,8 @@ device is attached to the remote system (e.g. /dev/ttya).");
 
   /* split name after whitespace, pass tail as arg to open command */
 
-  devName = strdup(name);
-  p = strchr(devName,' ');
+  devName = xstrdup (name);
+  p = strchr (devName, ' ');
   if (p)
     {
       *p = '\0';
@@ -251,7 +236,7 @@ device is attached to the remote system (e.g. /dev/ttya).");
 
   /* Make the basic low-level connection.  */
 
-  Adp_CloseDevice ();
+  arm_rdi_close (0);
   rslt = Adp_OpenDevice (devName, openArgs, rdi_heartbeat);
 
   if (rslt != adp_ok)
@@ -280,7 +265,7 @@ device is attached to the remote system (e.g. /dev/ttya).");
     {
       printf_filtered ("RDI_open: %s\n", rdi_error_message (rslt));
       Adp_CloseDevice ();
-      error("RID_open failed\n");
+      error ("RDI_open failed\n");
     }
 
   rslt = angel_RDI_info (RDIInfo_Target, &arg1, &arg2);
@@ -348,7 +333,7 @@ device is attached to the remote system (e.g. /dev/ttya).");
     for (entry = local_bp_list; entry != NULL; entry = entry->next)
       {
        if (preventry)
-         free (preventry);
+         xfree (preventry);
       }
   }
 
@@ -366,10 +351,7 @@ device is attached to the remote system (e.g. /dev/ttya).");
    user types "run" after having attached.  */
 
 static void
-arm_rdi_create_inferior (exec_file, args, env)
-     char *exec_file;
-     char *args;
-     char **env;
+arm_rdi_create_inferior (char *exec_file, char *args, char **env)
 {
   int len, rslt;
   unsigned long arg1, arg2;
@@ -436,9 +418,7 @@ arm_rdi_create_inferior (exec_file, args, env)
    die when it hits one.  */
 
 static void
-arm_rdi_detach (args, from_tty)
-     char *args;
-     int from_tty;
+arm_rdi_detach (char *args, int from_tty)
 {
   pop_target ();
 }
@@ -446,8 +426,7 @@ arm_rdi_detach (args, from_tty)
 /* Clean up connection to a remote debugger.  */
 
 static void
-arm_rdi_close (quitting)
-     int quitting;
+arm_rdi_close (int quitting)
 {
   int rslt;
 
@@ -461,15 +440,14 @@ arm_rdi_close (quitting)
       closed_already = 1;
       inferior_pid = 0;
       Adp_CloseDevice ();
+      generic_mourn_inferior ();
     }
 }
 \f
 /* Tell the remote machine to resume.  */
 
 static void
-arm_rdi_resume (pid, step, siggnal)
-     int pid, step;
-     enum target_signal siggnal;
+arm_rdi_resume (int pid, int step, enum target_signal siggnal)
 {
   int rslt;
   PointHandle point;
@@ -511,8 +489,7 @@ arm_rdi_resume (pid, step, siggnal)
    packet.  */
 
 static void
-arm_rdi_interrupt (signo)
-     int signo;
+arm_rdi_interrupt (int signo)
 {
 }
 
@@ -520,15 +497,14 @@ static void (*ofunc) ();
 
 /* The user typed ^C twice.  */
 static void
-arm_rdi_interrupt_twice (signo)
-     int signo;
+arm_rdi_interrupt_twice (int signo)
 {
 }
 
 /* Ask the user what to do when an interrupt is received.  */
 
 static void
-interrupt_query ()
+interrupt_query (void)
 {
 }
 
@@ -537,9 +513,7 @@ interrupt_query ()
    what, if anything, that means in the case of this target).  */
 
 static int
-arm_rdi_wait (pid, status)
-     int pid;
-     struct target_waitstatus *status;
+arm_rdi_wait (int pid, struct target_waitstatus *status)
 {
   status->kind = (execute_status == RDIError_NoError ?
                  TARGET_WAITKIND_EXITED : TARGET_WAITKIND_STOPPED);
@@ -554,8 +528,7 @@ arm_rdi_wait (pid, status)
 
 /* ARGSUSED */
 static void
-arm_rdi_fetch_registers (regno)
-     int regno;
+arm_rdi_fetch_registers (int regno)
 {
   int rslt, rdi_regmask;
   unsigned long rawreg, rawregs[32];
@@ -604,7 +577,7 @@ arm_rdi_fetch_registers (regno)
 }
 
 static void
-arm_rdi_prepare_to_store ()
+arm_rdi_prepare_to_store (void)
 {
   /* Nothing to do.  */
 }
@@ -613,8 +586,7 @@ arm_rdi_prepare_to_store ()
    of REGISTERS.  FIXME: ignores errors.  */
 
 static void
-arm_rdi_store_registers (regno)
-     int regno;
+arm_rdi_store_registers (int regno)
 {
   int rslt, rdi_regmask;
 
@@ -652,16 +624,13 @@ arm_rdi_store_registers (regno)
 /* 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.  */
+   read; 0 for error.  TARGET is unused.  */
 
 /* ARGSUSED */
 static int
-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 */
+arm_rdi_xfer_memory (CORE_ADDR memaddr, char *myaddr, int len, int should_write,
+                    struct mem_attrib *attrib ATTRIBUTE_UNUSED,
+                    struct target_ops *target ATTRIBUTE_UNUSED)
 {
   int rslt, i;
 
@@ -688,8 +657,7 @@ arm_rdi_xfer_memory (memaddr, myaddr, len, should_write, target)
 /* Display random info collected from the target.  */
 
 static void
-arm_rdi_files_info (ignore)
-     struct target_ops *ignore;
+arm_rdi_files_info (struct target_ops *ignore)
 {
   char *file = "nothing";
   int rslt;
@@ -724,7 +692,7 @@ arm_rdi_files_info (ignore)
 }
 \f
 static void
-arm_rdi_kill ()
+arm_rdi_kill (void)
 {
   int rslt;
 
@@ -736,8 +704,14 @@ arm_rdi_kill ()
 }
 
 static void
-arm_rdi_mourn_inferior ()
+arm_rdi_mourn_inferior (void)
 {
+  /* We remove the inserted breakpoints in case the user wants to
+     issue another target and load commands to rerun his application;
+     This is something that wouldn't work on a native target, for instance,
+     as the process goes away when the inferior exits, but it works with
+     some remote targets like this one.  That is why this is done here. */
+  remove_breakpoints();
   unpush_target (&arm_rdi_ops);
   generic_mourn_inferior ();
 }
@@ -748,9 +722,7 @@ arm_rdi_mourn_inferior ()
    here.  */
 
 static int
-arm_rdi_insert_breakpoint (addr, contents_cache)
-     CORE_ADDR addr;
-     char *contents_cache;
+arm_rdi_insert_breakpoint (CORE_ADDR addr, char *contents_cache)
 {
   int rslt;
   PointHandle point;
@@ -774,9 +746,7 @@ arm_rdi_insert_breakpoint (addr, contents_cache)
 }
 
 static int
-arm_rdi_remove_breakpoint (addr, contents_cache)
-     CORE_ADDR addr;
-     char *contents_cache;
+arm_rdi_remove_breakpoint (CORE_ADDR addr, char *contents_cache)
 {
   int rslt;
   PointHandle point;
@@ -806,14 +776,13 @@ arm_rdi_remove_breakpoint (addr, contents_cache)
        {
          preventry->next = entry->next;
        }
-      free (entry);
+      xfree (entry);
     }
   return 0;
 }
 \f
 static char *
-rdi_error_message (err)
-     int err;
+rdi_error_message (int err)
 {
   switch (err)
     {
@@ -903,8 +872,7 @@ rdi_error_message (err)
 /* Convert the ARM error messages to signals that GDB knows about.  */
 
 static enum target_signal
-rdi_error_signal (err)
-     int err;
+rdi_error_signal (int err)
 {
   switch (err)
     {
@@ -964,11 +932,18 @@ rdi_error_signal (err)
       return TARGET_SIGNAL_UNKNOWN;
     }
 }
+
+static void
+arm_rdi_stop(void)
+{
+  angel_RDI_stop_request();
+}
+
 \f
 /* Define the target operations structure.  */
 
 static void
-init_rdi_ops ()
+init_rdi_ops (void)
 {
   arm_rdi_ops.to_shortname = "rdi";
   arm_rdi_ops.to_longname = "ARM RDI";
@@ -979,6 +954,7 @@ Specify the serial device it is connected to (e.g. /dev/ttya).";
   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_stop = arm_rdi_stop;
   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;
@@ -999,69 +975,74 @@ Specify the serial device it is connected to (e.g. /dev/ttya).";
   arm_rdi_ops.to_magic = OPS_MAGIC;
 }
 
-static void rdilogfile_command (char *arg, int from_tty)
+static void 
+rdilogfile_command (char *arg, int from_tty)
 {
   if (!arg || strlen (arg) == 0)
     {
       printf_filtered ("rdi log file is '%s'\n", log_filename);
       return;
     }
-  
+
   if (log_filename)
-    free (log_filename);
-  
-  log_filename = strdup (arg);
+    xfree (log_filename);
+
+  log_filename = xstrdup (arg);
 
   Adp_SetLogfile (log_filename);
 }
 
-static void rdilogenable_command (char *args, int from_tty)
+static void 
+rdilogenable_command (char *args, int from_tty)
 {
   if (!args || strlen (args) == 0)
     {
       printf_filtered ("rdi log is %s\n", log_enable ? "enabled" : "disabled");
       return;
     }
-  
-  if (!strcasecmp (args,"1") || 
-      !strcasecmp (args,"y") ||
-      !strcasecmp (args,"yes") ||
-      !strcasecmp (args,"on") ||
-      !strcasecmp (args,"t") ||
-      !strcasecmp (args,"true"))
-    Adp_SetLogEnable (log_enable=1);
-  else if (!strcasecmp (args,"0") || 
-      !strcasecmp (args,"n") ||
-      !strcasecmp (args,"no") ||
-      !strcasecmp (args,"off") ||
-      !strcasecmp (args,"f") ||
-      !strcasecmp (args,"false"))
-    Adp_SetLogEnable (log_enable=0);
+
+  if (!strcasecmp (args, "1") ||
+      !strcasecmp (args, "y") ||
+      !strcasecmp (args, "yes") ||
+      !strcasecmp (args, "on") ||
+      !strcasecmp (args, "t") ||
+      !strcasecmp (args, "true"))
+    Adp_SetLogEnable (log_enable = 1);
+  else if (!strcasecmp (args, "0") ||
+          !strcasecmp (args, "n") ||
+          !strcasecmp (args, "no") ||
+          !strcasecmp (args, "off") ||
+          !strcasecmp (args, "f") ||
+          !strcasecmp (args, "false"))
+    Adp_SetLogEnable (log_enable = 0);
   else
     printf_filtered ("rdilogenable: unrecognized argument '%s'\n"
-                     "              try y or n\n",args);
+                    "              try y or n\n", args);
 }
 
 void
-_initialize_remote_rdi ()
+_initialize_remote_rdi (void)
 {
+  struct cmd_list_element *c;
+
   init_rdi_ops ();
   add_target (&arm_rdi_ops);
 
-  log_filename = strdup("rdi.log");
-  Adp_SetLogfile(log_filename);
-  Adp_SetLogEnable(log_enable);
+  log_filename = xstrdup ("rdi.log");
+  Adp_SetLogfile (log_filename);
+  Adp_SetLogEnable (log_enable);
 
-  add_cmd ("rdilogfile", class_maintenance,
-          rdilogfile_command,
-          "Set filename for ADP packet log.\n\
+  c = add_cmd ("rdilogfile", class_maintenance,
+              rdilogfile_command,
+              "Set filename for ADP packet log.\n\
 This file is used to log Angel Debugger Protocol packets.\n\
 With a single argument, sets the logfile name to that value.\n\
 Without an argument, shows the current logfile name.\n\
 See also: rdilogenable\n",
           &maintenancelist);
+  c->completer = filename_completer;
 
-  add_cmd("rdilogenable", class_maintenance,
+  add_cmd ("rdilogenable", class_maintenance,
           rdilogenable_command,
           "Set enable logging of ADP packets.\n\
 This will log ADP packets exchanged between gdb and the\n\
@@ -1078,7 +1059,7 @@ Withough an argument, it will display current state.\n",
 A true value disables vector catching, false enables vector catching.\n\
 This is evaluated at the time the 'target rdi' command is executed\n",
                  &setlist),
-    &showlist);
+     &showlist);
 
   add_show_from_set
     (add_set_cmd ("rdiheartbeat", no_class,
@@ -1088,13 +1069,13 @@ I don't know why you would want this. If you enable them,\n\
 it will confuse ARM and EPI JTAG interface boxes as well\n\
 as the Angel Monitor.\n",
                  &setlist),
-    &showlist);
+     &showlist);
 }
 
 /* A little dummy to make linking with the library succeed. */
 
 int
-Fail ()
+Fail (void)
 {
   return 0;
 }
This page took 0.032458 seconds and 4 git commands to generate.