From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 22673 invoked by alias); 19 Dec 2013 16:45:42 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 21182 invoked by uid 89); 19 Dec 2013 16:45:28 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-3.3 required=5.0 tests=AWL,BAYES_00,RP_MATCHES_RCVD autolearn=ham version=3.3.2 X-HELO: mga01.intel.com Received: from mga01.intel.com (HELO mga01.intel.com) (192.55.52.88) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 19 Dec 2013 16:45:25 +0000 Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga101.fm.intel.com with ESMTP; 19 Dec 2013 08:45:15 -0800 X-ExtLoop1: 1 Received: from irvmail001.ir.intel.com ([163.33.26.43]) by fmsmga002.fm.intel.com with ESMTP; 19 Dec 2013 08:45:02 -0800 Received: from ulvlx001.iul.intel.com (ulvlx001.iul.intel.com [172.28.207.17]) by irvmail001.ir.intel.com (8.14.3/8.13.6/MailSET/Hub) with ESMTP id rBJGj164026077; Thu, 19 Dec 2013 16:45:02 GMT Received: from ulvlx001.iul.intel.com (localhost [127.0.0.1]) by ulvlx001.iul.intel.com with ESMTP id rBJGj1TK029886; Thu, 19 Dec 2013 17:45:01 +0100 Received: (from mmetzger@localhost) by ulvlx001.iul.intel.com with œ id rBJGj1jv029882; Thu, 19 Dec 2013 17:45:01 +0100 From: Markus Metzger To: jan.kratochvil@redhat.com, palves@redhat.com Cc: gdb-patches@sourceware.org Subject: [PATCH v9 21/29] record-btrace: provide xfer_partial target method Date: Thu, 19 Dec 2013 16:45:00 -0000 Message-Id: <1387471499-29444-22-git-send-email-markus.t.metzger@intel.com> In-Reply-To: <1387471499-29444-1-git-send-email-markus.t.metzger@intel.com> References: <1387471499-29444-1-git-send-email-markus.t.metzger@intel.com> X-IsSubscribed: yes X-SW-Source: 2013-12/txt/msg00764.txt.bz2 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. 2013-12-19 Markus Metzger * 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. --- gdb/record-btrace.c | 116 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 116 insertions(+) diff --git a/gdb/record-btrace.c b/gdb/record-btrace.c index cf30e17..5011d6c 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,116 @@ 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: + case TARGET_OBJECT_RAW_MEMORY: + case TARGET_OBJECT_STACK_MEMORY: + { + struct target_section *section; + + /* We do not allow writing memory in general. */ + if (writebuf != NULL) + throw_error (NOT_AVAILABLE_ERROR, + _("This record target does not record memory.")); + + /* 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; + } + } + + throw_error (NOT_AVAILABLE_ERROR, + _("This record target does not record memory.")); + } + } + } + + /* 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 +1043,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; -- 1.8.3.1