From patchwork Tue Apr 12 09:41:46 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pedro Alves X-Patchwork-Id: 11704 Received: (qmail 7772 invoked by alias); 12 Apr 2016 09:41:50 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 7757 invoked by uid 89); 12 Apr 2016 09:41:50 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.9 required=5.0 tests=BAYES_00, RP_MATCHES_RCVD, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy= X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Tue, 12 Apr 2016 09:41:49 +0000 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 10F208AE73; Tue, 12 Apr 2016 09:41:48 +0000 (UTC) Received: from [127.0.0.1] (ovpn01.gateway.prod.ext.phx2.redhat.com [10.5.9.1]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u3C9fksR022750; Tue, 12 Apr 2016 05:41:47 -0400 Subject: Re: [PATCH 4/7] Insert breakpoint even when the raw breakpoint is found To: Yao Qi References: <1458749384-19793-1-git-send-email-yao.qi@linaro.org> <1458749384-19793-5-git-send-email-yao.qi@linaro.org> <570BB7AF.1080703@redhat.com> <86y48jjj0v.fsf@gmail.com> Cc: gdb-patches@sourceware.org From: Pedro Alves Message-ID: <570CC2DA.6050504@redhat.com> Date: Tue, 12 Apr 2016 10:41:46 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.7.1 MIME-Version: 1.0 In-Reply-To: <86y48jjj0v.fsf@gmail.com> On 04/12/2016 10:03 AM, Yao Qi wrote: > Pedro Alves writes: > >> Can we only increase the refcount if inserting succeeds? gdbserver can >> use gdb exceptions nowadays, and even though lots of current gdbserver >> code isn't exception safe, it'd be nice to start considering that. > > One thing I can think of is to properly decrease refcount if exception > is thrown. Anything else? Nothing else, that's all I meant. Actually, now that I look closer, I think we could merge the new code with the code that handles inserting a new raw breakpoint just below. For example: diff --git a/gdb/gdbserver/mem-break.c b/gdb/gdbserver/mem-break.c index b06f8e9..419db9e 100644 --- a/gdb/gdbserver/mem-break.c +++ b/gdb/gdbserver/mem-break.c @@ -390,6 +390,7 @@ set_raw_breakpoint_at (enum raw_bkpt_type type, CORE_ADDR where, int kind, { struct process_info *proc = current_process (); struct raw_breakpoint *bp; + struct cleanup *old_chain = make_cleanup (null_cleanup, NULL); if (type == raw_bkpt_type_sw || type == raw_bkpt_type_hw) { @@ -408,32 +409,39 @@ set_raw_breakpoint_at (enum raw_bkpt_type type, CORE_ADDR where, int kind, else bp = find_raw_breakpoint_at (where, type, kind); - if (bp != NULL) + if (bp == NULL) { - bp->refcount++; - return bp; + bp = XCNEW (struct raw_breakpoint); + bp->pc = where; + bp->kind = kind; + bp->raw_type = type; + make_cleanup (xfree, bp); } - bp = XCNEW (struct raw_breakpoint); - bp->pc = where; - bp->kind = kind; - bp->refcount = 1; - bp->raw_type = type; - - *err = the_target->insert_point (bp->raw_type, bp->pc, bp->kind, bp); - if (*err != 0) + if (!bp->inserted) { - if (debug_threads) - debug_printf ("Failed to insert breakpoint at 0x%s (%d).\n", - paddress (where), *err); - free (bp); - return NULL; + *err = the_target->insert_point (bp->raw_type, bp->pc, bp->kind, bp); + if (*err != 0) + { + if (debug_threads) + debug_printf ("Failed to insert breakpoint at 0x%s (%d).\n", + paddress (where), *err); + + do_cleanups (old_chain); + return NULL; + } + + bp->inserted = 1; } - bp->inserted = 1; - /* Link the breakpoint in. */ - bp->next = proc->raw_breakpoints; - proc->raw_breakpoints = bp; + discard_cleanups (old_chain); + + /* Link the breakpoint in, if this is the first reference. */ + if (++bp->refcount == 1) + { + bp->next = proc->raw_breakpoints; + proc->raw_breakpoints = bp; + } return bp; }