From: Markus Metzger <markus.t.metzger@intel.com>
To: jan.kratochvil@redhat.com, palves@redhat.com
Cc: gdb-patches@sourceware.org
Subject: [PATCH v10 20/28] record-btrace: provide xfer_partial target method
Date: Tue, 14 Jan 2014 08:04:00 -0000 [thread overview]
Message-ID: <1389686678-9039-21-git-send-email-markus.t.metzger@intel.com> (raw)
In-Reply-To: <1389686678-9039-1-git-send-email-markus.t.metzger@intel.com>
Provide the xfer_partial target method for the btrace record target.
Only allow memory read accesses to readonly memory while we're replaying,
except for inserting and removing breakpoints.
2014-01-14 Markus Metzger <markus.t.metzger@intel.com>
* record-btrace.c (record_btrace_xfer_partial)
(record_btrace_insert_breakpoint, record_btrace_remove_breakpoint)
(record_btrace_allow_memory_access): New.
(init_record_btrace_ops): Initialize new methods.
* target.c (raw_memory_xfer_partial): Bail out if target reports
that this memory is not available.
---
gdb/record-btrace.c | 112 ++++++++++++++++++++++++++++++++++++++++++++++++++++
gdb/target.c | 4 ++
2 files changed, 116 insertions(+)
diff --git a/gdb/record-btrace.c b/gdb/record-btrace.c
index 870ad7d..24e697f 100644
--- a/gdb/record-btrace.c
+++ b/gdb/record-btrace.c
@@ -41,6 +41,9 @@ static struct target_ops record_btrace_ops;
/* A new thread observer enabling branch tracing for the new thread. */
static struct observer *record_btrace_thread_observer;
+/* Temporarily allow memory accesses. */
+static int record_btrace_allow_memory_access;
+
/* Print a record-btrace debug message. Use do ... while (0) to avoid
ambiguities when used in if statements. */
@@ -753,6 +756,112 @@ record_btrace_is_replaying (void)
return 0;
}
+/* The to_xfer_partial method of target record-btrace. */
+
+static LONGEST
+record_btrace_xfer_partial (struct target_ops *ops, enum target_object object,
+ const char *annex, gdb_byte *readbuf,
+ const gdb_byte *writebuf, ULONGEST offset,
+ LONGEST len)
+{
+ struct target_ops *t;
+
+ /* Filter out requests that don't make sense during replay. */
+ if (!record_btrace_allow_memory_access && record_btrace_is_replaying ())
+ {
+ switch (object)
+ {
+ case TARGET_OBJECT_MEMORY:
+ {
+ struct target_section *section;
+
+ /* We do not allow writing memory in general. */
+ if (writebuf != NULL)
+ return TARGET_XFER_E_UNAVAILABLE;
+
+ /* We allow reading readonly memory. */
+ section = target_section_by_addr (ops, offset);
+ if (section != NULL)
+ {
+ /* Check if the section we found is readonly. */
+ if ((bfd_get_section_flags (section->the_bfd_section->owner,
+ section->the_bfd_section)
+ & SEC_READONLY) != 0)
+ {
+ /* Truncate the request to fit into this section. */
+ len = min (len, section->endaddr - offset);
+ break;
+ }
+ }
+
+ return TARGET_XFER_E_UNAVAILABLE;
+ }
+ }
+ }
+
+ /* Forward the request. */
+ for (ops = ops->beneath; ops != NULL; ops = ops->beneath)
+ if (ops->to_xfer_partial != NULL)
+ return ops->to_xfer_partial (ops, object, annex, readbuf, writebuf,
+ offset, len);
+
+ return TARGET_XFER_E_UNAVAILABLE;
+}
+
+/* The to_insert_breakpoint method of target record-btrace. */
+
+static int
+record_btrace_insert_breakpoint (struct target_ops *ops,
+ struct gdbarch *gdbarch,
+ struct bp_target_info *bp_tgt)
+{
+ volatile struct gdb_exception except;
+ int old, ret;
+
+ /* Inserting breakpoints requires accessing memory. Allow it for the
+ duration of this function. */
+ old = record_btrace_allow_memory_access;
+ record_btrace_allow_memory_access = 1;
+
+ ret = 0;
+ TRY_CATCH (except, RETURN_MASK_ALL)
+ ret = forward_target_insert_breakpoint (ops->beneath, gdbarch, bp_tgt);
+
+ record_btrace_allow_memory_access = old;
+
+ if (except.reason < 0)
+ throw_exception (except);
+
+ return ret;
+}
+
+/* The to_remove_breakpoint method of target record-btrace. */
+
+static int
+record_btrace_remove_breakpoint (struct target_ops *ops,
+ struct gdbarch *gdbarch,
+ struct bp_target_info *bp_tgt)
+{
+ volatile struct gdb_exception except;
+ int old, ret;
+
+ /* Removing breakpoints requires accessing memory. Allow it for the
+ duration of this function. */
+ old = record_btrace_allow_memory_access;
+ record_btrace_allow_memory_access = 1;
+
+ ret = 0;
+ TRY_CATCH (except, RETURN_MASK_ALL)
+ ret = forward_target_remove_breakpoint (ops->beneath, gdbarch, bp_tgt);
+
+ record_btrace_allow_memory_access = old;
+
+ if (except.reason < 0)
+ throw_exception (except);
+
+ return ret;
+}
+
/* The to_fetch_registers method of target record-btrace. */
static void
@@ -930,6 +1039,9 @@ init_record_btrace_ops (void)
ops->to_call_history_from = record_btrace_call_history_from;
ops->to_call_history_range = record_btrace_call_history_range;
ops->to_record_is_replaying = record_btrace_is_replaying;
+ ops->to_xfer_partial = record_btrace_xfer_partial;
+ ops->to_remove_breakpoint = record_btrace_remove_breakpoint;
+ ops->to_insert_breakpoint = record_btrace_insert_breakpoint;
ops->to_fetch_registers = record_btrace_fetch_registers;
ops->to_store_registers = record_btrace_store_registers;
ops->to_prepare_to_store = record_btrace_prepare_to_store;
diff --git a/gdb/target.c b/gdb/target.c
index 36e23aa..c3e42f2 100644
--- a/gdb/target.c
+++ b/gdb/target.c
@@ -1406,6 +1406,10 @@ raw_memory_xfer_partial (struct target_ops *ops, void *readbuf,
if (res > 0)
break;
+ /* Stop if the target reports that the memory is not available. */
+ if (res == TARGET_XFER_E_UNAVAILABLE)
+ break;
+
/* We want to continue past core files to executables, but not
past a running target's memory. */
if (ops->to_has_all_memory (ops))
--
1.8.3.1
next prev parent reply other threads:[~2014-01-14 8:04 UTC|newest]
Thread overview: 58+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-01-14 8:05 [PATCH v10 00/28] record-btrace: reverse Markus Metzger
2014-01-14 8:04 ` Markus Metzger [this message]
2014-01-15 15:51 ` [PATCH v10 20/28] record-btrace: provide xfer_partial target method Pedro Alves
2014-01-14 8:04 ` [PATCH v10 26/28] record-btrace: show trace from enable location Markus Metzger
2014-01-14 8:04 ` [PATCH v10 10/28] record-btrace: optionally indent function call history Markus Metzger
2014-01-14 16:07 ` Eli Zaretskii
2014-01-14 8:04 ` [PATCH v10 03/28] btrace: uppercase btrace_read_type Markus Metzger
2014-01-14 8:04 ` [PATCH v10 14/28] record-btrace: supply register target methods Markus Metzger
2014-01-14 8:04 ` [PATCH v10 18/28] record-btrace, frame: supply target-specific unwinder Markus Metzger
2014-01-14 8:04 ` [PATCH v10 05/28] frame: add frame_id_build_unavailable_stack_special Markus Metzger
2014-01-14 8:04 ` [PATCH v10 01/28] btrace, test: fix multi-line btrace tests Markus Metzger
2014-01-14 8:05 ` [PATCH v10 25/28] btrace, gdbserver: read branch trace incrementally Markus Metzger
2014-01-16 17:57 ` Tom Tromey
2014-01-17 8:28 ` Metzger, Markus T
2014-01-20 5:44 ` Tom Tromey
2014-01-14 8:05 ` [PATCH v10 16/28] frame, cfa: check unwind stop reason first Markus Metzger
2014-01-14 8:05 ` [PATCH v10 19/28] target, breakpoint: allow insert/remove breakpoint to be forwarded Markus Metzger
2014-01-15 15:52 ` Pedro Alves
2014-01-14 8:05 ` [PATCH v10 15/28] frame, backtrace: allow targets to supply a frame unwinder Markus Metzger
2014-01-14 8:05 ` [PATCH v10 24/28] record-btrace: extend unwinder Markus Metzger
2014-01-14 8:05 ` [PATCH v10 23/28] record-btrace: add record goto target methods Markus Metzger
2014-01-14 8:05 ` [PATCH v10 13/28] Add target_ops argument to to_prepare_to_store Markus Metzger
2014-01-14 8:05 ` [PATCH v10 08/28] record-btrace: start counting at one Markus Metzger
2014-01-14 8:05 ` [PATCH v10 17/28] frame: do not assume unwinding will succeed Markus Metzger
2014-01-14 8:05 ` [PATCH v10 28/28] record-btrace: add (reverse-)stepping support Markus Metzger
2014-01-14 8:05 ` [PATCH v10 21/28] record-btrace: add to_wait and to_resume target methods Markus Metzger
2014-01-14 8:05 ` [PATCH v10 27/28] target: allow decr_pc_after_break to be defined by the target Markus Metzger
2014-01-14 8:05 ` [PATCH v10 09/28] btrace: increase buffer size Markus Metzger
2014-01-14 8:05 ` [PATCH v10 12/28] btrace: add replay position to btrace thread info Markus Metzger
2014-01-14 8:05 ` [PATCH v10 22/28] record-btrace: provide target_find_new_threads method Markus Metzger
2014-01-14 8:05 ` [PATCH v10 02/28] btrace, linux: fix memory leak when reading branch trace Markus Metzger
2014-01-14 8:05 ` [PATCH v10 11/28] record-btrace: make ranges include begin and end Markus Metzger
2014-01-14 8:05 ` [PATCH v10 07/28] record-btrace: fix insn range in function call history Markus Metzger
2014-01-14 8:05 ` [PATCH v10 06/28] btrace: change branch trace data structure Markus Metzger
2015-01-08 20:49 ` x86_64-m32 internal error for multi-thread-step.exp [Re: [PATCH v10 06/28] btrace: change branch trace data structure] Jan Kratochvil
2015-01-20 15:19 ` Metzger, Markus T
2015-01-22 12:30 ` Metzger, Markus T
2015-01-22 13:36 ` Pedro Alves
2015-01-22 17:37 ` Linux: make target_is_async_p return false when async is off Pedro Alves
2015-01-23 10:39 ` Metzger, Markus T
2015-01-23 12:34 ` Pedro Alves
2015-01-22 16:37 ` x86_64-m32 internal error for multi-thread-step.exp [Re: [PATCH v10 06/28] btrace: change branch trace data structure] Jan Kratochvil
2015-01-23 7:56 ` Metzger, Markus T
2015-01-23 16:01 ` Metzger, Markus T
2015-01-23 16:33 ` Metzger, Markus T
2015-01-27 18:05 ` Pedro Alves
2015-01-29 16:28 ` Metzger, Markus T
2015-01-25 19:56 ` record btrace experience [Re: x86_64-m32 internal error for multi-thread-step.exp [Re: [PATCH v10 06/28] btrace: change branch trace data structure]] Jan Kratochvil
2015-01-26 12:41 ` Metzger, Markus T
2015-01-27 8:07 ` Jan Kratochvil
2015-01-27 15:52 ` Pedro Alves
2015-01-29 19:28 ` Metzger, Markus T
2015-01-23 12:55 ` x86_64-m32 internal error for multi-thread-step.exp [Re: [PATCH v10 06/28] btrace: change branch trace data structure] Patrick Palka
2014-01-14 8:05 ` [PATCH v10 04/28] gdbarch: add instruction predicate methods Markus Metzger
2014-01-15 15:54 ` [PATCH v10 00/28] record-btrace: reverse Pedro Alves
2014-01-16 12:01 ` Metzger, Markus T
2014-01-16 12:37 ` Pedro Alves
2014-01-16 14:35 ` Tom Tromey
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=1389686678-9039-21-git-send-email-markus.t.metzger@intel.com \
--to=markus.t.metzger@intel.com \
--cc=gdb-patches@sourceware.org \
--cc=jan.kratochvil@redhat.com \
--cc=palves@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