From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 14373 invoked by alias); 17 Dec 2013 11:58:56 -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 14363 invoked by uid 89); 17 Dec 2013 11:58:55 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-3.4 required=5.0 tests=AWL,BAYES_00,RP_MATCHES_RCVD,SPF_PASS autolearn=ham version=3.3.2 X-HELO: mga09.intel.com Received: from mga09.intel.com (HELO mga09.intel.com) (134.134.136.24) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 17 Dec 2013 11:58:54 +0000 Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga102.jf.intel.com with ESMTP; 17 Dec 2013 03:55:05 -0800 X-ExtLoop1: 1 Received: from irsmsx102.ger.corp.intel.com ([163.33.3.155]) by orsmga002.jf.intel.com with ESMTP; 17 Dec 2013 03:58:51 -0800 Received: from irsmsx104.ger.corp.intel.com ([169.254.5.135]) by IRSMSX102.ger.corp.intel.com ([169.254.2.114]) with mapi id 14.03.0123.003; Tue, 17 Dec 2013 11:57:22 +0000 From: "Metzger, Markus T" To: Pedro Alves CC: "jan.kratochvil@redhat.com" , "gdb-patches@sourceware.org" Subject: RE: [patch v8 17/24] record-btrace: provide xfer_partial target method Date: Tue, 17 Dec 2013 11:58:00 -0000 Message-ID: References: <1386839747-8860-1-git-send-email-markus.t.metzger@intel.com> <1386839747-8860-18-git-send-email-markus.t.metzger@intel.com> <52AB555A.3070301@redhat.com> <52AF5188.9040800@redhat.com> In-Reply-To: <52AF5188.9040800@redhat.com> Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-IsSubscribed: yes X-SW-Source: 2013-12/txt/msg00623.txt.bz2 > -----Original Message----- > From: Pedro Alves [mailto:palves@redhat.com] > Sent: Monday, December 16, 2013 8:16 PM > > I changed the return -1 to throw_error (...) and added a check for > > writebuf !=3D NULL. Suddenly I got tons of errors when GDB can't insert > > breakpoints any longer for (reverse-)stepping. >=20 > This is why precord keeps track of breakpoints itself too: [...]=20 > > Also stepping gets broken. >=20 > I can't immediately why that would be. Because we can't set temporary breakpoints. > > I now get an error when trying to access a variable with static storage > > duration or when trying to access memory directly via its address. > > It would be nice to also get an in those cases. This wou= ld > > require the respective layer to catch my exception. >=20 > Please try returning TARGET_XFER_E_UNAVAILABLE instead. That is ignored just like the -1 I returned earlier. I nevertheless changed the default return to that since it is more descriptive. > > To avoid those errors when trying to set breakpoints, I could try > > providing to_insert_breakpoint and to_remove_breakpoint methods > > and maintain my own breakpoints. >=20 > Right. I have something to temporarily disable the xfer checks during to_insert_breakpoint and to_remove_breakpoint. Not sure whether this is considered too hacky or what else I'm missing. My tests all pass. Any idea where else GDB would need to access target memory in order to function correctly? Here's the patch. I omit a preparation patch to pass target_ops to to_insert_breakpoint and to_remove_breakpoint so that the request can be forwarded to the target beneath. diff --git a/gdb/record-btrace.c b/gdb/record-btrace.c index 00a056d..0536071 100644 --- a/gdb/record-btrace.c +++ b/gdb/record-btrace.c @@ -42,6 +42,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; =20 +/* 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. */ =20 @@ -805,7 +808,7 @@ record_btrace_xfer_partial (struct target_ops *ops, enu= m target_object object, struct target_ops *t; =20 /* Filter out requests that don't make sense during replay. */ - if (record_btrace_is_replaying ()) + if (record_btrace_allow_memory_access =3D=3D 0 && record_btrace_is_repla= ying ()) { switch (object) { @@ -850,6 +853,58 @@ record_btrace_xfer_partial (struct target_ops *ops, en= um target_object object, return TARGET_XFER_E_UNAVAILABLE; } =20 +/* 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 =3D record_btrace_allow_memory_access; + record_btrace_allow_memory_access =3D 1; + + TRY_CATCH (except, RETURN_MASK_ALL) + ret =3D forward_target_insert_breakpoint (ops->beneath, gdbarch, bp_tg= t); + + record_btrace_allow_memory_access =3D 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 =3D record_btrace_allow_memory_access; + record_btrace_allow_memory_access =3D 1; + + TRY_CATCH (except, RETURN_MASK_ALL) + ret =3D forward_target_remove_breakpoint (ops->beneath, gdbarch, bp_tg= t); + + record_btrace_allow_memory_access =3D old; + + if (except.reason < 0) + throw_exception (except); + + return ret; +} + /* The to_fetch_registers method of target record-btrace. */ =20 static void @@ -1804,6 +1859,8 @@ init_record_btrace_ops (void) ops->to_call_history_range =3D record_btrace_call_history_range; ops->to_record_is_replaying =3D record_btrace_is_replaying; ops->to_xfer_partial =3D record_btrace_xfer_partial; + ops->to_remove_breakpoint =3D record_btrace_remove_breakpoint; + ops->to_insert_breakpoint =3D record_btrace_insert_breakpoint; ops->to_fetch_registers =3D record_btrace_fetch_registers; ops->to_store_registers =3D record_btrace_store_registers; ops->to_prepare_to_store =3D record_btrace_prepare_to_store; Regards, Markus. Intel GmbH Dornacher Strasse 1 85622 Feldkirchen/Muenchen, Deutschland Sitz der Gesellschaft: Feldkirchen bei Muenchen Geschaeftsfuehrer: Christian Lamprechter, Hannes Schwaderer, Douglas Lusk Registergericht: Muenchen HRB 47456 Ust.-IdNr./VAT Registration No.: DE129385895 Citibank Frankfurt a.M. (BLZ 502 109 00) 600119052