Check for NULL character before calling strchr.
[platform/upstream/binutils.git] / gdb / common / agent.c
index 70a6de7..99cef4f 100644 (file)
@@ -1,6 +1,6 @@
 /* Shared utility routines for GDB to interact with agent.
 
-   Copyright (C) 2009-2012 Free Software Foundation, Inc.
+   Copyright (C) 2009-2013 Free Software Foundation, Inc.
 
    This file is part of GDB.
 
@@ -28,6 +28,7 @@
 #include <string.h>
 #include <unistd.h>
 #include "agent.h"
+#include "filestuff.h"
 
 int debug_agent = 0;
 
@@ -83,7 +84,7 @@ agent_loaded_p (void)
    found, return non-zero otherwise.  */
 
 int
-agent_look_up_symbols (void)
+agent_look_up_symbols (void *arg)
 {
   int i;
 
@@ -97,8 +98,9 @@ agent_look_up_symbols (void)
 
       if (look_up_one_symbol (symbol_list[i].name, addrp, 1) == 0)
 #else
-      struct minimal_symbol *sym = lookup_minimal_symbol (symbol_list[i].name,
-                                                         NULL, NULL);
+      struct minimal_symbol *sym =
+       lookup_minimal_symbol (symbol_list[i].name, NULL,
+                              (struct objfile *) arg);
 
       if (sym != NULL)
        *addrp = SYMBOL_VALUE_ADDRESS (sym);
@@ -124,7 +126,7 @@ agent_get_helper_thread_id (void)
                                (unsigned char *) &helper_thread_id,
                                sizeof helper_thread_id))
 #else
-      enum bfd_endian byte_order = gdbarch_byte_order (target_gdbarch);
+      enum bfd_endian byte_order = gdbarch_byte_order (target_gdbarch ());
       gdb_byte buf[4];
 
       if (target_read_memory (ipa_sym_addrs.addr_helper_thread_id,
@@ -134,7 +136,7 @@ agent_get_helper_thread_id (void)
       else
 #endif
        {
-         warning ("Error reading helper thread's id in lib");
+         warning (_("Error reading helper thread's id in lib"));
        }
     }
 
@@ -167,10 +169,10 @@ gdb_connect_sync_socket (int pid)
   if (res >= UNIX_PATH_MAX)
     return -1;
 
-  res = fd = socket (PF_UNIX, SOCK_STREAM, 0);
+  res = fd = gdb_socket_cloexec (PF_UNIX, SOCK_STREAM, 0);
   if (res == -1)
     {
-      warning ("error opening sync socket: %s\n", strerror (errno));
+      warning (_("error opening sync socket: %s"), strerror (errno));
       return -1;
     }
 
@@ -179,7 +181,7 @@ gdb_connect_sync_socket (int pid)
   res = xsnprintf (addr.sun_path, UNIX_PATH_MAX, "%s", path);
   if (res >= UNIX_PATH_MAX)
     {
-      warning ("string overflow allocating socket name\n");
+      warning (_("string overflow allocating socket name"));
       close (fd);
       return -1;
     }
@@ -187,9 +189,9 @@ gdb_connect_sync_socket (int pid)
   res = connect (fd, (struct sockaddr *) &addr, sizeof (addr));
   if (res == -1)
     {
-      warning ("error connecting sync socket (%s): %s. "
-              "Make sure the directory exists and that it is writable.",
-              path, strerror (errno));
+      warning (_("error connecting sync socket (%s): %s. "
+                "Make sure the directory exists and that it is writable."),
+                path, strerror (errno));
       close (fd);
       return -1;
     }
@@ -207,23 +209,23 @@ gdb_connect_sync_socket (int pid)
    socket.  Return zero if success, otherwise return non-zero.  */
 
 int
-agent_run_command (int pid, const char *cmd)
+agent_run_command (int pid, const char *cmd, int len)
 {
   int fd;
   int tid = agent_get_helper_thread_id ();
   ptid_t ptid = ptid_build (pid, tid, 0);
-  int len = strlen (cmd) + 1;
 
 #ifdef GDBSERVER
   int ret = write_inferior_memory (ipa_sym_addrs.addr_cmd_buf,
                                   (const unsigned char *) cmd, len);
 #else
-  int ret = target_write_memory (ipa_sym_addrs.addr_cmd_buf, cmd, len);
+  int ret = target_write_memory (ipa_sym_addrs.addr_cmd_buf,
+                                (gdb_byte *) cmd, len);
 #endif
 
   if (ret != 0)
     {
-      warning ("unable to write");
+      warning (_("unable to write"));
       return -1;
     }
 
@@ -236,11 +238,11 @@ agent_run_command (int pid, const char *cmd)
 
   resume_info.thread = ptid;
   resume_info.kind = resume_continue;
-  resume_info.sig = TARGET_SIGNAL_0;
+  resume_info.sig = GDB_SIGNAL_0;
   (*the_target->resume) (&resume_info, 1);
 }
 #else
- target_resume (ptid, 0, TARGET_SIGNAL_0);
+ target_resume (ptid, 0, GDB_SIGNAL_0);
 #endif
 
   fd = gdb_connect_sync_socket (pid);
@@ -283,7 +285,7 @@ agent_run_command (int pid, const char *cmd)
 
        resume_info.thread = ptid;
        resume_info.kind = resume_stop;
-       resume_info.sig = TARGET_SIGNAL_0;
+       resume_info.sig = GDB_SIGNAL_0;
        (*the_target->resume) (&resume_info, 1);
       }
 
@@ -309,7 +311,7 @@ agent_run_command (int pid, const char *cmd)
                              IPA_CMD_BUF_SIZE))
 #endif
        {
-         warning ("Error reading command response");
+         warning (_("Error reading command response"));
          return -1;
        }
     }
@@ -332,7 +334,7 @@ agent_capability_check (enum agent_capa agent_capa)
                                (unsigned char *) &agent_capability,
                                sizeof agent_capability))
 #else
-      enum bfd_endian byte_order = gdbarch_byte_order (target_gdbarch);
+      enum bfd_endian byte_order = gdbarch_byte_order (target_gdbarch ());
       gdb_byte buf[4];
 
       if (target_read_memory (ipa_sym_addrs.addr_capability,
@@ -341,7 +343,7 @@ agent_capability_check (enum agent_capa agent_capa)
                                                     byte_order);
       else
 #endif
-       warning ("Error reading capability of agent");
+       warning (_("Error reading capability of agent"));
     }
   return agent_capability & agent_capa;
 }