From: Gary Benson <gbenson@redhat.com>
To: gdb-patches@sourceware.org
Cc: Tom Tromey <tromey@redhat.com>, Doug Evans <dje@google.com>
Subject: [PATCH 10/15 v2] Add target/target.h
Date: Wed, 16 Jul 2014 17:04:00 -0000 [thread overview]
Message-ID: <1405520243-17282-11-git-send-email-gbenson@redhat.com> (raw)
In-Reply-To: <1405520243-17282-1-git-send-email-gbenson@redhat.com>
This adds target/target.h. This file declares some functions that the
"common" code can use and that the clients must implement. It also
changes code in common to use these functions.
gdb/
2014-07-16 Tom Tromey <tromey@redhat.com>
Gary Benson <gbenson@redhat.com>
* 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: Don't include server.h or defs.h; update
includes.
(agent_get_helper_thread_id): Use target_read_uint32.
(agent_run_command): Always use target_write_memory,
target_read_memory.
(agent_capability_check): Use target_read_uint32.
* target/target.h: New file.
gdb/gdbserver/
2014-07-16 Tom Tromey <tromey@redhat.com>
* target.c (target_read_memory, target_read_uint32)
(target_write_memory): New functions.
---
gdb/ChangeLog | 14 +++++++++++
gdb/common/agent.c | 56 ++++++++++++---------------------------------
gdb/gdbserver/ChangeLog | 5 ++++
gdb/gdbserver/target.c | 24 +++++++++++++++++++
gdb/target.c | 16 +++++++++++++
gdb/target.h | 7 +-----
gdb/target/target.h | 57 +++++++++++++++++++++++++++++++++++++++++++++++
7 files changed, 132 insertions(+), 47 deletions(-)
create mode 100644 gdb/target/target.h
diff --git a/gdb/common/agent.c b/gdb/common/agent.c
index 549b784..52de3d4 100644
--- a/gdb/common/agent.c
+++ b/gdb/common/agent.c
@@ -26,6 +26,16 @@
#include "objfiles.h"
#endif
+#include <stdarg.h>
+#include <errno.h>
+
+#include "common-types.h"
+#include "target/target.h"
+#include "errors.h"
+#include "ptid.h"
+#include "gdb_locale.h"
+#include "common-utils.h"
+
#include <string.h>
#include <unistd.h>
#include "agent.h"
@@ -128,23 +138,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;
@@ -222,13 +218,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)
{
@@ -310,13 +301,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;
@@ -336,20 +322,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;
diff --git a/gdb/gdbserver/target.c b/gdb/gdbserver/target.c
index dcad5c9..44e1e11 100644
--- a/gdb/gdbserver/target.c
+++ b/gdb/gdbserver/target.c
@@ -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, int len)
+{
+ return read_inferior_memory (memaddr, myaddr, len);
+}
+
+/* See target/target.h. */
+
+int
+target_read_uint32 (CORE_ADDR memaddr, unsigned int *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)
diff --git a/gdb/target.c b/gdb/target.c
index 07d029a..d4907b6 100644
--- a/gdb/target.c
+++ b/gdb/target.c
@@ -1306,6 +1306,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, unsigned int *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. */
diff --git a/gdb/target.h b/gdb/target.h
index 8bf160c..8a2faca 100644
--- a/gdb/target.h
+++ b/gdb/target.h
@@ -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"
@@ -1278,9 +1279,6 @@ 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);
-
extern int target_read_raw_memory (CORE_ADDR memaddr, gdb_byte *myaddr,
ssize_t len);
@@ -1288,9 +1286,6 @@ 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);
-
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
index 0000000..4ac3440
--- /dev/null
+++ b/gdb/target/target.h
@@ -0,0 +1,57 @@
+/* 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
+
+/* 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. 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. 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, unsigned int *result);
+
+/* Write LEN bytes from MYADDR to target memory at address MEMADDR.
+ Return zero for success, nonzero if any error occurs.
+ 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 */
--
1.7.1
next prev parent reply other threads:[~2014-07-16 17:03 UTC|newest]
Thread overview: 34+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-07-16 16:19 [PATCH 00/15 v2] Common code cleanups Gary Benson
2014-07-16 16:19 ` [PATCH 04/15 v2] Introduce common-types.h Gary Benson
2014-07-17 11:21 ` Doug Evans
2014-07-16 16:19 ` [PATCH 15/15 v2] Finally remove GDBSERVER (mostly) from linux-btrace.c Gary Benson
2014-07-16 16:32 ` [PATCH 09/15 v2] Mostly remove GDBSERVER from linux-waitpid.c Gary Benson
2014-07-16 16:33 ` [PATCH 14/15 v2] Introduce get_thread_regcache_for_ptid Gary Benson
2014-07-16 16:45 ` [PATCH 05/15 v2] Introduce and use debug_printf and debug_vprintf Gary Benson
2014-07-16 16:45 ` [PATCH 02/15 v2] Remove some GDBSERVER checks from linux-ptrace Gary Benson
2014-07-17 8:37 ` Doug Evans
2014-07-17 16:40 ` Pedro Alves
2014-07-16 16:45 ` [PATCH 01/15 v2] Introduce common/errors.h Gary Benson
2014-07-16 18:36 ` Doug Evans
2014-07-17 13:41 ` [PATCH] " Gary Benson
2014-07-17 13:47 ` Gary Benson
2014-07-17 14:05 ` [PATCH 01/15 v3] " Gary Benson
2014-07-17 15:40 ` Pedro Alves
2014-07-17 16:03 ` Gary Benson
2014-07-17 16:19 ` Pedro Alves
2014-07-18 9:20 ` Gary Benson
2014-07-18 10:42 ` Doug Evans
2014-07-18 11:23 ` Gary Benson
2014-07-18 12:31 ` Doug Evans
2014-07-18 10:44 ` Pedro Alves
2014-07-16 16:48 ` [PATCH 03/15 v2] Make gdbserver CORE_ADDR unsigned Gary Benson
2014-07-17 9:02 ` Doug Evans
2014-07-17 16:42 ` Pedro Alves
2014-07-18 8:07 ` Maciej W. Rozycki
2014-07-16 16:48 ` [PATCH 06/15 v2] Remove simple GDBSERVER uses from common, nat and target Gary Benson
2014-07-16 17:03 ` [PATCH 13/15 v2] Finally remove GDBSERVER (mostly) from agent.c Gary Benson
2014-07-16 17:03 ` [PATCH 11/15 v2] More target unification Gary Benson
2014-07-16 17:03 ` [PATCH 08/15 v2] Make btrace-common.h not use GDBSERVER Gary Benson
2014-07-16 17:04 ` Gary Benson [this message]
2014-07-16 17:20 ` [PATCH 12/15 v2] Add target/symbol.h, update users Gary Benson
2014-07-16 17:24 ` [PATCH 07/15 v2] Remove GDBSERVER use from nat/i386-dregs.c Gary Benson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1405520243-17282-11-git-send-email-gbenson@redhat.com \
--to=gbenson@redhat.com \
--cc=dje@google.com \
--cc=gdb-patches@sourceware.org \
--cc=tromey@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox