* elf64-ppc.c (dec_dynrel_count): Don't error when elf_gc_sweep_symbol
[external/binutils.git] / gdb / remote-mips.c
index 5e197df..e20a740 100644 (file)
@@ -1,6 +1,6 @@
 /* Remote debugging interface for MIPS remote debugging protocol.
 
-   Copyright (C) 1993-2004, 2006-2012 Free Software Foundation, Inc.
+   Copyright (C) 1993-2013 Free Software Foundation, Inc.
 
    Contributed by Cygnus Support.  Written by Ian Lance Taylor
    <ian@cygnus.com>.
@@ -36,6 +36,7 @@
 #include <ctype.h>
 #include "mips-tdep.h"
 #include "gdbthread.h"
+#include "gdb_bfd.h"
 \f
 
 /* Breakpoint types.  Values 0, 1, and 2 must agree with the watch
@@ -587,6 +588,7 @@ mips_expect_timeout (const char *string, int timeout)
     }
 
   immediate_quit++;
+  QUIT;
   while (1)
     {
       int c;
@@ -1240,7 +1242,7 @@ mips_request (int cmd,
              int timeout,
              char *buff)
 {
-  int addr_size = gdbarch_addr_bit (target_gdbarch) / 8;
+  int addr_size = gdbarch_addr_bit (target_gdbarch ()) / 8;
   char myBuff[DATA_MAXLEN + 1];
   char response_string[17];
   int len;
@@ -1537,7 +1539,6 @@ common_open (struct target_ops *ops, char *name, int from_tty,
             enum mips_monitor_type new_monitor,
             const char *new_monitor_prompt)
 {
-  char *ptype;
   char *serial_port_name;
   char *remote_name = 0;
   char *local_name = 0;
@@ -1662,10 +1663,10 @@ static void
 mips_open (char *name, int from_tty)
 {
   const char *monitor_prompt = NULL;
-  if (gdbarch_bfd_arch_info (target_gdbarch) != NULL
-      && gdbarch_bfd_arch_info (target_gdbarch)->arch == bfd_arch_mips)
+  if (gdbarch_bfd_arch_info (target_gdbarch ()) != NULL
+      && gdbarch_bfd_arch_info (target_gdbarch ())->arch == bfd_arch_mips)
     {
-    switch (gdbarch_bfd_arch_info (target_gdbarch)->mach)
+    switch (gdbarch_bfd_arch_info (target_gdbarch ())->mach)
       {
       case bfd_mach_mips4100:
       case bfd_mach_mips4300:
@@ -1757,7 +1758,7 @@ mips_detach (struct target_ops *ops, char *args, int from_tty)
 
 static void
 mips_resume (struct target_ops *ops,
-            ptid_t ptid, int step, enum target_signal siggnal)
+            ptid_t ptid, int step, enum gdb_signal siggnal)
 {
   int err;
 
@@ -1771,7 +1772,7 @@ mips_resume (struct target_ops *ops,
 /* Return the signal corresponding to SIG, where SIG is the number which
    the MIPS protocol uses for the signal.  */
 
-static enum target_signal
+static enum gdb_signal
 mips_signal_from_protocol (int sig)
 {
   /* We allow a few more signals than the IDT board actually returns, on
@@ -1779,13 +1780,13 @@ mips_signal_from_protocol (int sig)
      for these signals is widely agreed upon.  */
   if (sig <= 0
       || sig > 31)
-    return TARGET_SIGNAL_UNKNOWN;
+    return GDB_SIGNAL_UNKNOWN;
 
-  /* Don't want to use target_signal_from_host because we are converting
+  /* Don't want to use gdb_signal_from_host because we are converting
      from MIPS signal numbers, not host ones.  Our internal numbers
      match the MIPS numbers for the signals the board can return, which
      are: SIGINT, SIGSEGV, SIGBUS, SIGILL, SIGFPE, SIGTRAP.  */
-  return (enum target_signal) sig;
+  return (enum gdb_signal) sig;
 }
 
 /* Set the register designated by REGNO to the value designated by VALUE.  */
@@ -1828,7 +1829,6 @@ mips_wait (struct target_ops *ops,
   ULONGEST rpc, rfp, rsp;
   char pc_string[17], fp_string[17], sp_string[17], flags[20];
   int nfields;
-  int i;
 
   interrupt_count = 0;
   hit_watchpoint = 0;
@@ -1839,7 +1839,7 @@ mips_wait (struct target_ops *ops,
   if (!mips_need_reply)
     {
       status->kind = TARGET_WAITKIND_STOPPED;
-      status->value.sig = TARGET_SIGNAL_TRAP;
+      status->value.sig = GDB_SIGNAL_TRAP;
       return inferior_ptid;
     }
 
@@ -2147,7 +2147,7 @@ static int
 mips_xfer_memory (CORE_ADDR memaddr, gdb_byte *myaddr, int len, int write,
                  struct mem_attrib *attrib, struct target_ops *target)
 {
-  enum bfd_endian byte_order = gdbarch_byte_order (target_gdbarch);
+  enum bfd_endian byte_order = gdbarch_byte_order (target_gdbarch ());
   int i;
   CORE_ADDR addr;
   int count;
@@ -2384,7 +2384,7 @@ mips_remove_breakpoint (struct gdbarch *gdbarch,
    is the number of hardware breakpoints already installed.  This
    implements the target_can_use_hardware_watchpoint macro.  */
 
-int
+static int
 mips_can_use_watchpoint (int type, int cnt, int othertype)
 {
   return cnt < MAX_LSI_BREAKPOINTS && strcmp (target_shortname, "lsi") == 0;
@@ -2418,7 +2418,7 @@ calculate_mask (CORE_ADDR addr, int len)
    for a write watchpoint, 1 for a read watchpoint, or 2 for a read/write
    watchpoint.  */
 
-int
+static int
 mips_insert_watchpoint (CORE_ADDR addr, int len, int type,
                        struct expression *cond)
 {
@@ -2430,7 +2430,7 @@ mips_insert_watchpoint (CORE_ADDR addr, int len, int type,
 
 /* Remove a watchpoint.  */
 
-int
+static int
 mips_remove_watchpoint (CORE_ADDR addr, int len, int type,
                        struct expression *cond)
 {
@@ -2443,7 +2443,7 @@ mips_remove_watchpoint (CORE_ADDR addr, int len, int type,
 /* Test to see if a watchpoint has been hit.  Return 1 if so; return 0,
    if not.  */
 
-int
+static int
 mips_stopped_by_watchpoint (void)
 {
   return hit_watchpoint;
@@ -2479,7 +2479,7 @@ static int
 mips_check_lsi_error (CORE_ADDR addr, int rerrflg)
 {
   struct lsi_error *err;
-  const char *saddr = paddress (target_gdbarch, addr);
+  const char *saddr = paddress (target_gdbarch (), addr);
 
   if (rerrflg == 0)            /* no error */
     return 0;
@@ -2547,13 +2547,13 @@ mips_common_breakpoint (%s): Unknown error: 0x%x\n",
 static int
 mips_common_breakpoint (int set, CORE_ADDR addr, int len, enum break_type type)
 {
-  int addr_size = gdbarch_addr_bit (target_gdbarch) / 8;
+  int addr_size = gdbarch_addr_bit (target_gdbarch ()) / 8;
   char buf[DATA_MAXLEN + 1];
   char cmd, rcmd;
   int rpid, rerrflg, rresponse, rlen;
   int nfields;
 
-  addr = gdbarch_addr_bits_remove (target_gdbarch, addr);
+  addr = gdbarch_addr_bits_remove (target_gdbarch (), addr);
 
   if (mips_monitor == MON_LSI)
     {
@@ -2581,7 +2581,7 @@ mips_common_breakpoint (int set, CORE_ADDR addr, int len, enum break_type type)
            {
              warning (_("\
 mips_common_breakpoint: Attempt to clear bogus breakpoint at %s"),
-                      paddress (target_gdbarch, addr));
+                      paddress (target_gdbarch (), addr));
              return 1;
            }
 
@@ -2732,7 +2732,7 @@ mips_common_breakpoint: Attempt to clear bogus breakpoint at %s"),
          if (rresponse != 22)  /* invalid argument */
            fprintf_unfiltered (gdb_stderr, "\
 mips_common_breakpoint (%s):  Got error: 0x%x\n",
-                               paddress (target_gdbarch, addr), rresponse);
+                               paddress (target_gdbarch (), addr), rresponse);
          return 1;
        }
     }
@@ -2765,7 +2765,7 @@ send_srec (char *srec, int len, CORE_ADDR addr)
        case 0x15:              /* NACK */
          fprintf_unfiltered (gdb_stderr,
                              "Download got a NACK at byte %s!  Retrying.\n",
-                             paddress (target_gdbarch, addr));
+                             paddress (target_gdbarch (), addr));
          continue;
        default:
          error (_("Download got unexpected ack char: 0x%x, retrying."),
@@ -2785,20 +2785,23 @@ mips_load_srec (char *args)
   unsigned int i;
   unsigned int srec_frame = 200;
   int reclen;
+  struct cleanup *cleanup;
   static int hashmark = 1;
 
   buffer = alloca (srec_frame * 2 + 256);
 
-  abfd = bfd_openr (args, 0);
+  abfd = gdb_bfd_open (args, NULL, -1);
   if (!abfd)
     {
       printf_filtered ("Unable to open file %s\n", args);
       return;
     }
 
+  cleanup = make_cleanup_bfd_unref (abfd);
   if (bfd_check_format (abfd, bfd_object) == 0)
     {
       printf_filtered ("File is not an object file\n");
+      do_cleanups (cleanup);
       return;
     }
 
@@ -2852,6 +2855,7 @@ mips_load_srec (char *args)
   send_srec (srec, reclen, abfd->start_address);
 
   serial_flush_input (mips_desc);
+  do_cleanups (cleanup);
 }
 
 /*
@@ -3368,20 +3372,23 @@ pmon_load_fast (char *file)
   int bintotal = 0;
   int final = 0;
   int finished = 0;
+  struct cleanup *cleanup;
 
   buffer = (char *) xmalloc (MAXRECSIZE + 1);
   binbuf = (unsigned char *) xmalloc (BINCHUNK);
 
-  abfd = bfd_openr (file, 0);
+  abfd = gdb_bfd_open (file, NULL, -1);
   if (!abfd)
     {
       printf_filtered ("Unable to open file %s\n", file);
       return;
     }
+  cleanup = make_cleanup_bfd_unref (abfd);
 
   if (bfd_check_format (abfd, bfd_object) == 0)
     {
       printf_filtered ("File is not an object file\n");
+      do_cleanups (cleanup);
       return;
     }
 
@@ -3505,6 +3512,7 @@ pmon_load_fast (char *file)
       pmon_end_download (final, bintotal);
     }
 
+  do_cleanups (cleanup);
   return;
 }