From patchwork Mon Apr 25 08:44:28 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yao Qi X-Patchwork-Id: 11874 Received: (qmail 95088 invoked by alias); 25 Apr 2016 08:45:12 -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 95016 invoked by uid 89); 25 Apr 2016 08:45:03 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.6 required=5.0 tests=AWL, BAYES_00, FREEMAIL_FROM, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 spammy=bp, xcnew, XCNEW, yours X-HELO: mail-pf0-f180.google.com Received: from mail-pf0-f180.google.com (HELO mail-pf0-f180.google.com) (209.85.192.180) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Mon, 25 Apr 2016 08:44:53 +0000 Received: by mail-pf0-f180.google.com with SMTP id y69so44138568pfb.1 for ; Mon, 25 Apr 2016 01:44:53 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:references:date:in-reply-to :message-id:user-agent:mime-version:content-transfer-encoding; bh=eUPvVMYtFmTzWJE6DBz53kP2Wc231RVbe6xFUWIMdaM=; b=X8FQDUx/sL5SXl+LKraNIDEB4fijfg+thlpeg9KAEDh4Gu+E9TFmm3bmmjWb2uWQL4 og5jq2eA+L9AVU8+svxJ/oXiK/T2aQnGeAIBQk2NTaNXx0MWJIvytM7JG/kbjI65EjNx lDTGXlTJmMl6/ls9oCrHFb66tipRU8smTqyC59Liw/qSEedYNKgNADuD6FV6tOUdGfLJ 6+cgogVssy5buLmsU1i/Z0HZaxx/IH3P3AJPNp0lEJ4zraK/UdU4HjnpgRIoIAkm/i44 PCJYJdvUM0EEOY/S9Wf4rSBHXD7cLADu0WCiAJT5AcMUPid9RhDcdPfS2l8RY9eTLsZH ooSw== X-Gm-Message-State: AOPr4FWQYPsAgwbMCXfqvM9d3MwF/q8csXpU1jq0ES737X5klyma400gEGcxkI3Amtmx/w== X-Received: by 10.98.76.216 with SMTP id e85mr47224901pfj.121.1461573891750; Mon, 25 Apr 2016 01:44:51 -0700 (PDT) Received: from E107787-LIN (gcc1-power7.osuosl.org. [140.211.15.137]) by smtp.gmail.com with ESMTPSA id p189sm26581206pfb.51.2016.04.25.01.44.49 (version=TLS1_2 cipher=AES128-SHA bits=128/128); Mon, 25 Apr 2016 01:44:51 -0700 (PDT) From: Yao Qi To: Pedro Alves Cc: Yao Qi , gdb-patches@sourceware.org Subject: Re: [PATCH 4/7] Insert breakpoint even when the raw breakpoint is found 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> <570CC2DA.6050504@redhat.com> Date: Mon, 25 Apr 2016 09:44:28 +0100 In-Reply-To: <570CC2DA.6050504@redhat.com> (Pedro Alves's message of "Tue, 12 Apr 2016 10:41:46 +0100") Message-ID: <864maqgjrn.fsf@gmail.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) MIME-Version: 1.0 X-IsSubscribed: yes Pedro Alves writes: > 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: Looks yours is good to me. I pushed it in. diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 0b08605..5c94832 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,10 @@ +2016-04-25 Pedro Alves + Yao Qi + + * mem-break.c (set_raw_breakpoint_at): Create a raw breakpoint + object. Insert it if it is not inserted yet. Increase the + refcount and link it into the proc's raw breakpoint list. + 2016-04-25 Yao Qi * breakpoint.c (should_be_inserted): Return 0 if the location's 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; }