gdb/linux-record: Fix newfstatat handling
[deliverable/binutils-gdb.git] / gdb / remote-m32r-sdi.c
index ff4ba718671f21abbaa903b9c80a8f4b08c1370d..e67f9d43f721294bc5afd2dfb7b17f2422ced304 100644 (file)
@@ -1,6 +1,6 @@
 /* Remote debugging interface for M32R/SDI.
 
-   Copyright (C) 2003-2012 Free Software Foundation, Inc.
+   Copyright (C) 2003-2015 Free Software Foundation, Inc.
 
    Contributed by Renesas Technology Co.
    Written by Kei Sakamoto <sakamoto.kei@renesas.com>.
@@ -24,9 +24,9 @@
 #include "gdbcmd.h"
 #include "gdbcore.h"
 #include "inferior.h"
+#include "infrun.h"
 #include "target.h"
 #include "regcache.h"
-#include "gdb_string.h"
 #include "gdbthread.h"
 #include <ctype.h>
 #include <signal.h>
 #include <netinet/in.h>
 #endif
 #include <sys/types.h>
-#include <sys/time.h>
-#include <signal.h>
+#include "gdb_sys_time.h"
 #include <time.h>
-
-
+#include "gdb_bfd.h"
+#include "cli/cli-utils.h"
+#include "symfile.h"
 #include "serial.h"
 
 /* Descriptor for I/O to remote machine.  */
@@ -179,10 +179,8 @@ get_ack (void)
 
 /* Send data to the target and check an ack packet.  */
 static int
-send_data (void *buf, int len)
+send_data (const void *buf, int len)
 {
-  int ret;
-
   if (!sdi_desc)
     return -1;
 
@@ -341,7 +339,7 @@ m32r_create_inferior (struct target_ops *ops, char *execfile,
   /* The "process" (board) is already stopped awaiting our commands, and
      the program is already downloaded.  We just set its PC and go.  */
 
-  clear_proceed_status ();
+  clear_proceed_status (0);
 
   /* Tell wait_for_inferior that we've started a new process.  */
   init_wait_for_inferior ();
@@ -360,11 +358,12 @@ m32r_create_inferior (struct target_ops *ops, char *execfile,
    NAME is the filename used for communication.  */
 
 static void
-m32r_open (char *args, int from_tty)
+m32r_open (const char *args, int from_tty)
 {
   struct hostent *host_ent;
   struct sockaddr_in server_addr;
-  char *port_str, hostname[256];
+  char hostname[256];
+  const char *port_str;
   int port;
   int i, n;
   int yes = 1;
@@ -377,14 +376,14 @@ m32r_open (char *args, int from_tty)
   push_target (&m32r_ops);
 
   if (args == NULL)
-    sprintf (hostname, "localhost:%d", SDIPORT);
+    xsnprintf (hostname, sizeof (hostname), "localhost:%d", SDIPORT);
   else
     {
       port_str = strchr (args, ':');
       if (port_str == NULL)
-       sprintf (hostname, "%s:%d", args, SDIPORT);
+       xsnprintf (hostname, sizeof (hostname), "%s:%d", args, SDIPORT);
       else
-       strcpy (hostname, args);
+       xsnprintf (hostname, sizeof (hostname), "%s", args);
     }
 
   sdi_desc = serial_open (hostname);
@@ -431,10 +430,10 @@ m32r_open (char *args, int from_tty)
 /* Close out all files and local state before this target loses control.  */
 
 static void
-m32r_close (int quitting)
+m32r_close (struct target_ops *self)
 {
   if (remote_debug)
-    fprintf_unfiltered (gdb_stdlog, "m32r_close(%d)\n", quitting);
+    fprintf_unfiltered (gdb_stdlog, "m32r_close()\n");
 
   if (sdi_desc)
     {
@@ -452,7 +451,7 @@ m32r_close (int quitting)
 
 static void
 m32r_resume (struct target_ops *ops,
-            ptid_t ptid, int step, enum target_signal sig)
+            ptid_t ptid, int step, enum gdb_signal sig)
 {
   unsigned long pc_addr, bp_addr, ab_addr;
   int ib_breakpoints;
@@ -488,7 +487,7 @@ m32r_resume (struct target_ops *ops,
       else
        {
          buf[0] = SDI_WRITE_MEMORY;
-         if (gdbarch_byte_order (target_gdbarch) == BFD_ENDIAN_BIG)
+         if (gdbarch_byte_order (target_gdbarch ()) == BFD_ENDIAN_BIG)
            store_long_parameter (buf + 1, pc_addr);
          else
            store_long_parameter (buf + 1, pc_addr - 1);
@@ -528,7 +527,7 @@ m32r_resume (struct target_ops *ops,
        continue;
 
       /* Set PBP.  */
-      if (gdbarch_byte_order (target_gdbarch) == BFD_ENDIAN_BIG)
+      if (gdbarch_byte_order (target_gdbarch ()) == BFD_ENDIAN_BIG)
        send_three_arg_cmd (SDI_WRITE_MEMORY, 0xffff8000 + 4 * i, 4,
                            0x00000006);
       else
@@ -555,7 +554,7 @@ m32r_resume (struct target_ops *ops,
       store_long_parameter (buf + 5, 4);
       if ((bp_addr & 2) == 0 && bp_addr != (pc_addr & 0xfffffffc))
        {
-         if (gdbarch_byte_order (target_gdbarch) == BFD_ENDIAN_BIG)
+         if (gdbarch_byte_order (target_gdbarch ()) == BFD_ENDIAN_BIG)
            {
              buf[9] = dbt_bp_entry[0];
              buf[10] = dbt_bp_entry[1];
@@ -572,7 +571,7 @@ m32r_resume (struct target_ops *ops,
        }
       else
        {
-         if (gdbarch_byte_order (target_gdbarch) == BFD_ENDIAN_BIG)
+         if (gdbarch_byte_order (target_gdbarch ()) == BFD_ENDIAN_BIG)
            {
              if ((bp_addr & 2) == 0)
                {
@@ -619,7 +618,7 @@ m32r_resume (struct target_ops *ops,
        continue;
 
       /* DBC register.  */
-      if (gdbarch_byte_order (target_gdbarch) == BFD_ENDIAN_BIG)
+      if (gdbarch_byte_order (target_gdbarch ()) == BFD_ENDIAN_BIG)
        {
          switch (ab_type[i])
            {
@@ -702,19 +701,18 @@ static ptid_t
 m32r_wait (struct target_ops *ops,
           ptid_t ptid, struct target_waitstatus *status, int options)
 {
-  static RETSIGTYPE (*prev_sigint) ();
+  static sighandler_t prev_sigint;
   unsigned long bp_addr, pc_addr;
   int ib_breakpoints;
   long i;
   unsigned char buf[13];
-  unsigned long val;
   int ret, c;
 
   if (remote_debug)
     fprintf_unfiltered (gdb_stdlog, "m32r_wait()\n");
 
   status->kind = TARGET_WAITKIND_EXITED;
-  status->value.sig = TARGET_SIGNAL_0;
+  status->value.sig = GDB_SIGNAL_0;
 
   interrupted = 0;
   prev_sigint = signal (SIGINT, gdb_cntrl_c);
@@ -733,7 +731,7 @@ m32r_wait (struct target_ops *ops,
       if (c == '-')            /* error */
        {
          status->kind = TARGET_WAITKIND_STOPPED;
-         status->value.sig = TARGET_SIGNAL_HUP;
+         status->value.sig = GDB_SIGNAL_HUP;
          return inferior_ptid;
        }
       else if (c == '+')       /* stopped */
@@ -749,9 +747,9 @@ m32r_wait (struct target_ops *ops,
 
   status->kind = TARGET_WAITKIND_STOPPED;
   if (interrupted)
-    status->value.sig = TARGET_SIGNAL_INT;
+    status->value.sig = GDB_SIGNAL_INT;
   else
-    status->value.sig = TARGET_SIGNAL_TRAP;
+    status->value.sig = GDB_SIGNAL_TRAP;
 
   interrupted = 0;
   signal (SIGINT, prev_sigint);
@@ -762,7 +760,7 @@ m32r_wait (struct target_ops *ops,
   if (last_pc_addr != 0xffffffff)
     {
       buf[0] = SDI_WRITE_MEMORY;
-      if (gdbarch_byte_order (target_gdbarch) == BFD_ENDIAN_BIG)
+      if (gdbarch_byte_order (target_gdbarch ()) == BFD_ENDIAN_BIG)
        store_long_parameter (buf + 1, last_pc_addr);
       else
        store_long_parameter (buf + 1, last_pc_addr - 1);
@@ -791,7 +789,7 @@ m32r_wait (struct target_ops *ops,
             address, we have to take care of it later.  */
          if ((pc_addr & 0x2) != 0)
            {
-             if (gdbarch_byte_order (target_gdbarch) == BFD_ENDIAN_BIG)
+             if (gdbarch_byte_order (target_gdbarch ()) == BFD_ENDIAN_BIG)
                {
                  if ((bp_data[i][2] & 0x80) != 0)
                    {
@@ -853,7 +851,7 @@ m32r_wait (struct target_ops *ops,
          c = serial_readchar (sdi_desc, SDI_TIMEOUT);
          if (c != '-' && recv_data (buf, 4) != -1)
            {
-             if (gdbarch_byte_order (target_gdbarch) == BFD_ENDIAN_BIG)
+             if (gdbarch_byte_order (target_gdbarch ()) == BFD_ENDIAN_BIG)
                {
                  if ((buf[3] & 0x1) == 0x1)
                    hit_watchpoint_addr = ab_address[i];
@@ -880,15 +878,15 @@ m32r_wait (struct target_ops *ops,
    Use this when you want to detach and do something else
    with your gdb.  */
 static void
-m32r_detach (struct target_ops *ops, char *args, int from_tty)
+m32r_detach (struct target_ops *ops, const char *args, int from_tty)
 {
   if (remote_debug)
     fprintf_unfiltered (gdb_stdlog, "m32r_detach(%d)\n", from_tty);
 
-  m32r_resume (ops, inferior_ptid, 0, TARGET_SIGNAL_0);
+  m32r_resume (ops, inferior_ptid, 0, GDB_SIGNAL_0);
 
   /* Calls m32r_close to do the real work.  */
-  pop_target ();
+  unpush_target (ops);
   if (from_tty)
     fprintf_unfiltered (gdb_stdlog, "Ending remote %s debugging\n",
                        target_shortname);
@@ -935,7 +933,7 @@ m32r_fetch_register (struct target_ops *ops,
     }
   else
     {
-      char buffer[MAX_REGISTER_SIZE];
+      gdb_byte buffer[MAX_REGISTER_SIZE];
 
       regid = get_reg_id (regno);
       send_one_arg_cmd (SDI_READ_CPU_REG, regid);
@@ -1015,7 +1013,7 @@ m32r_store_register (struct target_ops *ops,
    debugged.  */
 
 static void
-m32r_prepare_to_store (struct regcache *regcache)
+m32r_prepare_to_store (struct target_ops *self, struct regcache *regcache)
 {
   /* Do nothing, since we can store individual regs.  */
   if (remote_debug)
@@ -1035,11 +1033,12 @@ m32r_files_info (struct target_ops *target)
     }
 }
 
-/* Read/Write memory.  */
-static int
-m32r_xfer_memory (CORE_ADDR memaddr, gdb_byte *myaddr, int len,
-                 int write,
-                 struct mem_attrib *attrib, struct target_ops *target)
+/* Helper for m32r_xfer_partial that handles memory transfers.
+   Arguments are like target_xfer_partial.  */
+
+static enum target_xfer_status
+m32r_xfer_memory (gdb_byte *readbuf, const gdb_byte *writebuf,
+                 ULONGEST memaddr, ULONGEST len, ULONGEST *xfered_len)
 {
   unsigned long taddr;
   unsigned char buf[0x2000];
@@ -1055,22 +1054,24 @@ m32r_xfer_memory (CORE_ADDR memaddr, gdb_byte *myaddr, int len,
 
   if (remote_debug)
     {
-      if (write)
-       fprintf_unfiltered (gdb_stdlog, "m32r_xfer_memory(%s,%d,write)\n",
-                           paddress (target_gdbarch, memaddr), len);
+      if (writebuf != NULL)
+       fprintf_unfiltered (gdb_stdlog, "m32r_xfer_memory(%s,%s,write)\n",
+                           paddress (target_gdbarch (), memaddr),
+                           plongest (len));
       else
-       fprintf_unfiltered (gdb_stdlog, "m32r_xfer_memory(%s,%d,read)\n",
-                           paddress (target_gdbarch, memaddr), len);
+       fprintf_unfiltered (gdb_stdlog, "m32r_xfer_memory(%s,%s,read)\n",
+                           paddress (target_gdbarch (), memaddr),
+                           plongest (len));
     }
 
-  if (write)
+  if (writebuf != NULL)
     {
       buf[0] = SDI_WRITE_MEMORY;
       store_long_parameter (buf + 1, taddr);
       store_long_parameter (buf + 5, len);
       if (len < 0x1000)
        {
-         memcpy (buf + 9, myaddr, len);
+         memcpy (buf + 9, writebuf, len);
          ret = send_data (buf, len + 9) - 9;
        }
       else
@@ -1080,9 +1081,9 @@ m32r_xfer_memory (CORE_ADDR memaddr, gdb_byte *myaddr, int len,
              if (remote_debug)
                fprintf_unfiltered (gdb_stdlog,
                                    "m32r_xfer_memory() failed\n");
-             return 0;
+             return TARGET_XFER_EOF;
            }
-         ret = send_data (myaddr, len);
+         ret = send_data (writebuf, len);
        }
     }
   else
@@ -1094,7 +1095,7 @@ m32r_xfer_memory (CORE_ADDR memaddr, gdb_byte *myaddr, int len,
        {
          if (remote_debug)
            fprintf_unfiltered (gdb_stdlog, "m32r_xfer_memory() failed\n");
-         return 0;
+         return TARGET_XFER_EOF;
        }
 
       c = serial_readchar (sdi_desc, SDI_TIMEOUT);
@@ -1102,20 +1103,41 @@ m32r_xfer_memory (CORE_ADDR memaddr, gdb_byte *myaddr, int len,
        {
          if (remote_debug)
            fprintf_unfiltered (gdb_stdlog, "m32r_xfer_memory() failed\n");
-         return 0;
+         return TARGET_XFER_EOF;
        }
 
-      ret = recv_data (myaddr, len);
+      ret = recv_data (readbuf, len);
     }
 
   if (ret <= 0)
     {
       if (remote_debug)
        fprintf_unfiltered (gdb_stdlog, "m32r_xfer_memory() fails\n");
-      return 0;
+      return TARGET_XFER_E_IO;
     }
 
-  return ret;
+  *xfered_len = ret;
+  return TARGET_XFER_OK;
+}
+
+/* Target to_xfer_partial implementation.  */
+
+static enum target_xfer_status
+m32r_xfer_partial (struct target_ops *ops, enum target_object object,
+                  const char *annex, gdb_byte *readbuf,
+                  const gdb_byte *writebuf, ULONGEST offset, ULONGEST len,
+                  ULONGEST *xfered_len)
+{
+  switch (object)
+    {
+    case TARGET_OBJECT_MEMORY:
+      return m32r_xfer_memory (readbuf, writebuf, offset, len, xfered_len);
+
+    default:
+      return ops->beneath->to_xfer_partial (ops->beneath, object, annex,
+                                           readbuf, writebuf, offset, len,
+                                           xfered_len);
+    }
 }
 
 static void
@@ -1147,10 +1169,11 @@ m32r_mourn_inferior (struct target_ops *ops)
 }
 
 static int
-m32r_insert_breakpoint (struct gdbarch *gdbarch,
+m32r_insert_breakpoint (struct target_ops *ops,
+                       struct gdbarch *gdbarch,
                        struct bp_target_info *bp_tgt)
 {
-  CORE_ADDR addr = bp_tgt->placed_address;
+  CORE_ADDR addr = bp_tgt->placed_address = bp_tgt->reqstd_address;
   int ib_breakpoints;
   unsigned char buf[13];
   int i, c;
@@ -1191,7 +1214,8 @@ m32r_insert_breakpoint (struct gdbarch *gdbarch,
 }
 
 static int
-m32r_remove_breakpoint (struct gdbarch *gdbarch,
+m32r_remove_breakpoint (struct target_ops *ops,
+                       struct gdbarch *gdbarch,
                        struct bp_target_info *bp_tgt)
 {
   CORE_ADDR addr = bp_tgt->placed_address;
@@ -1214,9 +1238,9 @@ m32r_remove_breakpoint (struct gdbarch *gdbarch,
 }
 
 static void
-m32r_load (char *args, int from_tty)
+m32r_load (struct target_ops *self, const char *args, int from_tty)
 {
-  struct cleanup *old_chain;
+  struct cleanup *old_chain = make_cleanup (null_cleanup, NULL);
   asection *section;
   bfd *pbfd;
   bfd_vma entry;
@@ -1225,8 +1249,7 @@ m32r_load (char *args, int from_tty)
   int nostart;
   struct timeval start_time, end_time;
   unsigned long data_count;    /* Number of bytes transferred to memory.  */
-  int ret;
-  static RETSIGTYPE (*prev_sigint) ();
+  static sighandler_t prev_sigint;
 
   /* for direct tcp connections, we can do a fast binary download.  */
   quiet = 0;
@@ -1235,24 +1258,17 @@ m32r_load (char *args, int from_tty)
 
   while (*args != '\000')
     {
-      char *arg;
-
-      while (isspace (*args))
-       args++;
-
-      arg = args;
+      char *arg = extract_arg_const (&args);
 
-      while ((*args != '\000') && !isspace (*args))
-       args++;
-
-      if (*args != '\000')
-       *args++ = '\000';
+      if (arg == NULL)
+       break;
+      make_cleanup (xfree, arg);
 
       if (*arg != '-')
        filename = arg;
-      else if (strncmp (arg, "-quiet", strlen (arg)) == 0)
+      else if (startswith ("-quiet", arg))
        quiet = 1;
-      else if (strncmp (arg, "-nostart", strlen (arg)) == 0)
+      else if (startswith ("-nostart", arg))
        nostart = 1;
       else
        error (_("Unknown option `%s'"), arg);
@@ -1261,13 +1277,10 @@ m32r_load (char *args, int from_tty)
   if (!filename)
     filename = get_exec_file (1);
 
-  pbfd = bfd_openr (filename, gnutarget);
+  pbfd = gdb_bfd_open (filename, gnutarget, -1);
   if (pbfd == NULL)
-    {
-      perror_with_name (filename);
-      return;
-    }
-  old_chain = make_cleanup_bfd_close (pbfd);
+    perror_with_name (filename);
+  make_cleanup_bfd_unref (pbfd);
 
   if (!bfd_check_format (pbfd, bfd_object))
     error (_("\"%s\" is not an object file: %s"), filename,
@@ -1394,10 +1407,10 @@ m32r_load (char *args, int from_tty)
 }
 
 static void
-m32r_stop (ptid_t ptid)
+m32r_interrupt (struct target_ops *self, ptid_t ptid)
 {
   if (remote_debug)
-    fprintf_unfiltered (gdb_stdlog, "m32r_stop()\n");
+    fprintf_unfiltered (gdb_stdlog, "m32r_interrupt()\n");
 
   send_cmd (SDI_STOP_CPU);
 
@@ -1410,7 +1423,9 @@ m32r_stop (ptid_t ptid)
    implements the target_can_use_hardware_watchpoint macro.  */
 
 static int
-m32r_can_use_hw_watchpoint (int type, int cnt, int othertype)
+m32r_can_use_hw_watchpoint (struct target_ops *self,
+                           enum bptype type,
+                           int cnt, int othertype)
 {
   return sdi_desc != NULL && cnt < max_access_breaks;
 }
@@ -1420,14 +1435,15 @@ m32r_can_use_hw_watchpoint (int type, int cnt, int othertype)
    watchpoint.  */
 
 static int
-m32r_insert_watchpoint (CORE_ADDR addr, int len, int type,
+m32r_insert_watchpoint (struct target_ops *self,
+                       CORE_ADDR addr, int len, enum target_hw_bp_type type,
                        struct expression *cond)
 {
   int i;
 
   if (remote_debug)
     fprintf_unfiltered (gdb_stdlog, "m32r_insert_watchpoint(%s,%d,%d)\n",
-                       paddress (target_gdbarch, addr), len, type);
+                       paddress (target_gdbarch (), addr), len, type);
 
   for (i = 0; i < MAX_ACCESS_BREAKS; i++)
     {
@@ -1445,14 +1461,14 @@ m32r_insert_watchpoint (CORE_ADDR addr, int len, int type,
 }
 
 static int
-m32r_remove_watchpoint (CORE_ADDR addr, int len, int type,
-                       struct expression *cond)
+m32r_remove_watchpoint (struct target_ops *self, CORE_ADDR addr, int len,
+                       enum target_hw_bp_type type, struct expression *cond)
 {
   int i;
 
   if (remote_debug)
     fprintf_unfiltered (gdb_stdlog, "m32r_remove_watchpoint(%s,%d,%d)\n",
-                       paddress (target_gdbarch, addr), len, type);
+                       paddress (target_gdbarch (), addr), len, type);
 
   for (i = 0; i < MAX_ACCESS_BREAKS; i++)
     {
@@ -1480,7 +1496,7 @@ m32r_stopped_data_address (struct target_ops *target, CORE_ADDR *addr_p)
 }
 
 static int
-m32r_stopped_by_watchpoint (void)
+m32r_stopped_by_watchpoint (struct target_ops *ops)
 {
   CORE_ADDR addr;
 
@@ -1635,7 +1651,7 @@ init_m32r_ops (void)
   m32r_ops.to_fetch_registers = m32r_fetch_register;
   m32r_ops.to_store_registers = m32r_store_register;
   m32r_ops.to_prepare_to_store = m32r_prepare_to_store;
-  m32r_ops.deprecated_xfer_memory = m32r_xfer_memory;
+  m32r_ops.to_xfer_partial = m32r_xfer_partial;
   m32r_ops.to_files_info = m32r_files_info;
   m32r_ops.to_insert_breakpoint = m32r_insert_breakpoint;
   m32r_ops.to_remove_breakpoint = m32r_remove_breakpoint;
@@ -1648,7 +1664,7 @@ init_m32r_ops (void)
   m32r_ops.to_load = m32r_load;
   m32r_ops.to_create_inferior = m32r_create_inferior;
   m32r_ops.to_mourn_inferior = m32r_mourn_inferior;
-  m32r_ops.to_stop = m32r_stop;
+  m32r_ops.to_interrupt = m32r_interrupt;
   m32r_ops.to_log_command = serial_log_command;
   m32r_ops.to_thread_alive = m32r_thread_alive;
   m32r_ops.to_pid_to_str = m32r_pid_to_str;
This page took 0.030944 seconds and 4 git commands to generate.