]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Introduce target/target.h
authorGary Benson <gbenson@redhat.com>
Thu, 11 Sep 2014 10:19:56 +0000 (11:19 +0100)
committerGary Benson <gbenson@redhat.com>
Thu, 11 Sep 2014 10:19:56 +0000 (11:19 +0100)
This introduces target/target.h.  This file declares some functions
that the shared code can use and that clients must implement.  It also
changes some shared code to use these functions.

gdb/ChangeLog:

* target/target.h: New file.
* Makefile.in (HFILES_NO_SRCDIR): Add target/target.h.
* target.h: Include target/target.h.
(target_read_memory, target_write_memory): Don't declare.
* target.c (target_read_uint32): New function.
* common/agent.c: Include target/target.h.
[!GDBSERVER]: Don't include target.h.
(helper_thread_id): Type changed to uint32_t.
(agent_get_helper_thread_id): Use target_read_uint32.
(agent_run_command): Always use target_read_memory and
target_write_memory.
(agent_capability): Type changed to uint32_t.
(agent_capability_check): Use target_read_uint32.

gdb/gdbserver/ChangeLog:

* target.h: Include target/target.h.
* target.c (target_read_memory, target_read_uint32)
(target_write_memory): New functions.

gdb/ChangeLog
gdb/Makefile.in
gdb/common/agent.c
gdb/gdbserver/ChangeLog
gdb/gdbserver/target.c
gdb/gdbserver/target.h
gdb/target.c
gdb/target.h
gdb/target/target.h [new file with mode: 0644]

index 916b093a1e3a95e16fec0ad057c4018e1ceddef8..dda7ed96dbb2334100340e8f98ce67b54682384f 100644 (file)
@@ -1,3 +1,20 @@
+2014-09-11  Tom Tromey  <tromey@redhat.com>
+           Gary Benson  <gbenson@redhat.com>
+
+       * target/target.h: New file.
+       * Makefile.in (HFILES_NO_SRCDIR): Add target/target.h.
+       * target.h: Include target/target.h.
+       (target_read_memory, target_write_memory): Don't declare.
+       * target.c (target_read_uint32): New function.
+       * common/agent.c: Include target/target.h.
+       [!GDBSERVER]: Don't include target.h.
+       (helper_thread_id): Type changed to uint32_t.
+       (agent_get_helper_thread_id): Use target_read_uint32.
+       (agent_run_command): Always use target_read_memory and
+       target_write_memory.
+       (agent_capability): Type changed to uint32_t.
+       (agent_capability_check): Use target_read_uint32.
+
 2014-09-11  Gary Benson  <gbenson@redhat.com>
 
        * common/common-debug.h (show_debug_regs): Declare.
index ec11d4256830e6764483c4df5cbb209b6dd505b0..55b982946a44e0c56ffe57854c6d858fdf64e38e 100644 (file)
@@ -938,7 +938,7 @@ target/wait.h target/waitstatus.h nat/linux-nat.h nat/linux-waitpid.h \
 common/print-utils.h common/rsp-low.h nat/x86-dregs.h x86-linux-nat.h \
 i386-linux-nat.h common/common-defs.h common/errors.h common/common-types.h \
 common/common-debug.h common/cleanups.h common/gdb_setjmp.h \
-common/common-exceptions.h
+common/common-exceptions.h target/target.h
 
 # Header files that already have srcdir in them, or which are in objdir.
 
index 2963917641c10b2147d7f4c647ec6c4d333dbf38..9f8ea9a469125c0d9660b37f6765a2a6b072e2a2 100644 (file)
 #include "server.h"
 #else
 #include "defs.h"
-#include "target.h"
 #include "infrun.h"
 #include "objfiles.h"
 #endif
+#include "target/target.h"
 #include <unistd.h>
 #include "agent.h"
 #include "filestuff.h"
@@ -62,7 +62,7 @@ struct ipa_sym_addresses
 
 /* Cache of the helper thread id.  FIXME: this global should be made
    per-process.  */
-static unsigned int helper_thread_id = 0;
+static uint32_t helper_thread_id = 0;
 
 static struct
 {
@@ -126,23 +126,9 @@ agent_get_helper_thread_id (void)
 {
   if  (helper_thread_id == 0)
     {
-#ifdef GDBSERVER
-      if (read_inferior_memory (ipa_sym_addrs.addr_helper_thread_id,
-                               (unsigned char *) &helper_thread_id,
-                               sizeof helper_thread_id))
-#else
-      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,
-                             buf, sizeof buf) == 0)
-       helper_thread_id = extract_unsigned_integer (buf, sizeof buf,
-                                                    byte_order);
-      else
-#endif
-       {
-         warning (_("Error reading helper thread's id in lib"));
-       }
+      if (target_read_uint32 (ipa_sym_addrs.addr_helper_thread_id,
+                             &helper_thread_id))
+       warning (_("Error reading helper thread's id in lib"));
     }
 
   return helper_thread_id;
@@ -220,13 +206,8 @@ agent_run_command (int pid, const char *cmd, int len)
   int tid = agent_get_helper_thread_id ();
   ptid_t ptid = ptid_build (pid, tid, 0);
 
-#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,
                                 (gdb_byte *) cmd, len);
-#endif
 
   if (ret != 0)
     {
@@ -308,13 +289,8 @@ agent_run_command (int pid, const char *cmd, int len)
 
   if (fd >= 0)
     {
-#ifdef GDBSERVER
-      if (read_inferior_memory (ipa_sym_addrs.addr_cmd_buf,
-                               (unsigned char *) cmd, IPA_CMD_BUF_SIZE))
-#else
       if (target_read_memory (ipa_sym_addrs.addr_cmd_buf, (gdb_byte *) cmd,
                              IPA_CMD_BUF_SIZE))
-#endif
        {
          warning (_("Error reading command response"));
          return -1;
@@ -325,7 +301,7 @@ agent_run_command (int pid, const char *cmd, int len)
 }
 
 /* Each bit of it stands for a capability of agent.  */
-static unsigned int agent_capability = 0;
+static uint32_t agent_capability = 0;
 
 /* Return true if agent has capability AGENT_CAP, otherwise return false.  */
 
@@ -334,20 +310,8 @@ agent_capability_check (enum agent_capa agent_capa)
 {
   if (agent_capability == 0)
     {
-#ifdef GDBSERVER
-      if (read_inferior_memory (ipa_sym_addrs.addr_capability,
-                               (unsigned char *) &agent_capability,
-                               sizeof agent_capability))
-#else
-      enum bfd_endian byte_order = gdbarch_byte_order (target_gdbarch ());
-      gdb_byte buf[4];
-
-      if (target_read_memory (ipa_sym_addrs.addr_capability,
-                             buf, sizeof buf) == 0)
-       agent_capability = extract_unsigned_integer (buf, sizeof buf,
-                                                    byte_order);
-      else
-#endif
+      if (target_read_uint32 (ipa_sym_addrs.addr_capability,
+                             &agent_capability))
        warning (_("Error reading capability of agent"));
     }
   return agent_capability & agent_capa;
index 04410fe170c8f123f45f1f10b5220f4d98afffa6..f2f63b4dd78d99c5bffb9a0beaf4710b9649efe8 100644 (file)
@@ -1,3 +1,10 @@
+2014-09-11  Tom Tromey  <tromey@redhat.com>
+           Gary Benson  <gbenson@redhat.com>
+
+       * target.h: Include target/target.h.
+       * target.c (target_read_memory, target_read_uint32)
+       (target_write_memory): New functions.
+
 2014-09-11  Gary Benson  <gbenson@redhat.com>
 
        * server.h (debug_hw_points): Don't declare.
index dcad5c946713591cc93a2e2af41af4765401857b..08506e516bceb384a1787ac2cb5d4eef15b0d6d7 100644 (file)
@@ -48,6 +48,22 @@ read_inferior_memory (CORE_ADDR memaddr, unsigned char *myaddr, int len)
   return res;
 }
 
+/* See target/target.h.  */
+
+int
+target_read_memory (CORE_ADDR memaddr, gdb_byte *myaddr, ssize_t len)
+{
+  return read_inferior_memory (memaddr, myaddr, len);
+}
+
+/* See target/target.h.  */
+
+int
+target_read_uint32 (CORE_ADDR memaddr, uint32_t *result)
+{
+  return read_inferior_memory (memaddr, (gdb_byte *) result, sizeof (*result));
+}
+
 int
 write_inferior_memory (CORE_ADDR memaddr, const unsigned char *myaddr,
                       int len)
@@ -71,6 +87,14 @@ write_inferior_memory (CORE_ADDR memaddr, const unsigned char *myaddr,
   return res;
 }
 
+/* See target/target.h.  */
+
+int
+target_write_memory (CORE_ADDR memaddr, const gdb_byte *myaddr, ssize_t len)
+{
+  return write_inferior_memory (memaddr, myaddr, len);
+}
+
 ptid_t
 mywait (ptid_t ptid, struct target_waitstatus *ourstatus, int options,
        int connected_wait)
index f5eda8ae18f6c740e73447da640c5fe953e7ffce..a08b753c0d01ee158a663ef96d20cf60d4264de9 100644 (file)
@@ -21,6 +21,7 @@
 #ifndef TARGET_H
 #define TARGET_H
 
+#include "target/target.h"
 #include "target/resume.h"
 #include "target/wait.h"
 #include "target/waitstatus.h"
index 8bf6031f4534b148d9637dcdcbc626f35c21252b..711e7cb7052e17e881f1de5feb783312390b60dc 100644 (file)
@@ -1269,6 +1269,22 @@ target_read_memory (CORE_ADDR memaddr, gdb_byte *myaddr, ssize_t len)
     return TARGET_XFER_E_IO;
 }
 
+/* See target/target.h.  */
+
+int
+target_read_uint32 (CORE_ADDR memaddr, uint32_t *result)
+{
+  gdb_byte buf[4];
+  int r;
+
+  r = target_read_memory (memaddr, buf, sizeof buf);
+  if (r != 0)
+    return r;
+  *result = extract_unsigned_integer (buf, sizeof buf,
+                                     gdbarch_byte_order (target_gdbarch ()));
+  return 0;
+}
+
 /* Like target_read_memory, but specify explicitly that this is a read
    from the target's raw memory.  That is, this read bypasses the
    dcache, breakpoint shadowing, etc.  */
index 85763baf94f419d3536edf815b30bcdcecd32b77..2ea7a2d83f293b240938710793989d1d040fa40b 100644 (file)
@@ -58,6 +58,7 @@ struct dcache_struct;
    it goes into the file stratum, which is always below the process
    stratum.  */
 
+#include "target/target.h"
 #include "target/resume.h"
 #include "target/wait.h"
 #include "target/waitstatus.h"
@@ -1292,8 +1293,7 @@ int target_supports_disable_randomization (void);
 
 extern int target_read_string (CORE_ADDR, char **, int, int *);
 
-extern int target_read_memory (CORE_ADDR memaddr, gdb_byte *myaddr,
-                              ssize_t len);
+/* For target_read_memory see target/target.h.  */
 
 extern int target_read_raw_memory (CORE_ADDR memaddr, gdb_byte *myaddr,
                                   ssize_t len);
@@ -1302,8 +1302,7 @@ extern int target_read_stack (CORE_ADDR memaddr, gdb_byte *myaddr, ssize_t len);
 
 extern int target_read_code (CORE_ADDR memaddr, gdb_byte *myaddr, ssize_t len);
 
-extern int target_write_memory (CORE_ADDR memaddr, const gdb_byte *myaddr,
-                               ssize_t len);
+/* For target_write_memory see target/target.h.  */
 
 extern int target_write_raw_memory (CORE_ADDR memaddr, const gdb_byte *myaddr,
                                    ssize_t len);
diff --git a/gdb/target/target.h b/gdb/target/target.h
new file mode 100644 (file)
index 0000000..0a3c4b7
--- /dev/null
@@ -0,0 +1,62 @@
+/* Declarations for common target functions.
+
+   Copyright (C) 1986-2014 Free Software Foundation, Inc.
+
+   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 3 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, see <http://www.gnu.org/licenses/>.  */
+
+#ifndef TARGET_COMMON_H
+#define TARGET_COMMON_H
+
+#include "target/waitstatus.h"
+#include <stdint.h>
+
+/* This header is a stopgap until more code is shared.  */
+
+/* Read LEN bytes of target memory at address MEMADDR, placing the
+   results in GDB's memory at MYADDR.  Return zero for success,
+   nonzero if any error occurs.  This function must be provided by
+   the client.  Implementations of this function may define and use
+   their own error codes, but functions in the common, nat and target
+   directories must treat the return code as opaque.  No guarantee is
+   made about the contents of the data at MYADDR if any error
+   occurs.  */
+
+extern int target_read_memory (CORE_ADDR memaddr, gdb_byte *myaddr,
+                              ssize_t len);
+
+/* Read an unsigned 32-bit integer in the target's format from target
+   memory at address MEMADDR, storing the result in GDB's format in
+   GDB's memory at RESULT.  Return zero for success, nonzero if any
+   error occurs.  This function must be provided by the client.
+   Implementations of this function may define and use their own error
+   codes, but functions in the common, nat and target directories must
+   treat the return code as opaque.  No guarantee is made about the
+   contents of the data at RESULT if any error occurs.  */
+
+extern int target_read_uint32 (CORE_ADDR memaddr, uint32_t *result);
+
+/* Write LEN bytes from MYADDR to target memory at address MEMADDR.
+   Return zero for success, nonzero if any error occurs.  This
+   function must be provided by the client.  Implementations of this
+   function may define and use their own error codes, but functions
+   in the common, nat and target directories must treat the return
+   code as opaque.  No guarantee is made about the contents of the
+   data at MEMADDR if any error occurs.  */
+
+extern int target_write_memory (CORE_ADDR memaddr, const gdb_byte *myaddr,
+                               ssize_t len);
+
+#endif /* TARGET_COMMON_H */