From patchwork Thu Jun 2 09:30:35 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yao Qi X-Patchwork-Id: 12699 Received: (qmail 82341 invoked by alias); 2 Jun 2016 09:31:07 -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 82206 invoked by uid 89); 2 Jun 2016 09:31:05 -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= X-HELO: mail-pa0-f68.google.com Received: from mail-pa0-f68.google.com (HELO mail-pa0-f68.google.com) (209.85.220.68) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Thu, 02 Jun 2016 09:30:55 +0000 Received: by mail-pa0-f68.google.com with SMTP id fg1so2847368pad.3 for ; Thu, 02 Jun 2016 02:30:55 -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:subject:date:message-id:in-reply-to :references; bh=p8tG3OsjgN5Sm2MXnqPgOvrNgvK8PwXYz8EXIhfoZLo=; b=JhvqGgJxP9OzBQIuVrvf7l+Ix7j/zNkYnxPih9/gxBCX9XBl0K1ubLgjW9ivZaufRD CGCi+kOpIKkzpm2Lm+SxEfw2+De6ywG6ui/3LCiKyh/XEz4N3EwXg53L7yd+KwaIsFXw CkrjyD9dt6ZAJdNwbJeEr40HlfNrYkuNP3Pbh3Yxo4dr0UNgxcElhZHsPGVhlVmwamKh 8tmMBOM6uxa77iYCH2BmEEzHO49X4WLr//YdrxNk0irG/2OTN2C65hBJZeg6snORtrR5 J6vYrCUlZ388FURtdwGFBCu8yj43lfban2fVYum9zML9kZj3FB9PYWFKgVEwF1/V4pqI qgLQ== X-Gm-Message-State: ALyK8tKlaYDony7qx/fKEVE51bntH9Mx0ereQLrenanmDwYk+U+5uwRKE4P0uSruG7Wdqw== X-Received: by 10.66.170.168 with SMTP id an8mr4101721pac.47.1464859853549; Thu, 02 Jun 2016 02:30:53 -0700 (PDT) Received: from E107787-LIN.cambridge.arm.com (gcc113.osuosl.org. [140.211.9.71]) by smtp.gmail.com with ESMTPSA id hw10sm68656218pac.15.2016.06.02.02.30.52 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 02 Jun 2016 02:30:52 -0700 (PDT) From: Yao Qi X-Google-Original-From: Yao Qi To: gdb-patches@sourceware.org Subject: [PATCH 01/12] Switch to current thread in finish_step_over Date: Thu, 2 Jun 2016 10:30:35 +0100 Message-Id: <1464859846-15619-2-git-send-email-yao.qi@linaro.org> In-Reply-To: <1464859846-15619-1-git-send-email-yao.qi@linaro.org> References: <1464859846-15619-1-git-send-email-yao.qi@linaro.org> X-IsSubscribed: yes V2: move current_thread switch into finsh_step_over This patch adds some sanity check that reinsert breakpoints must be there when doing step-over on software single step target. The check triggers an assert when running forking-threads-plus-breakpoint.exp on arm-linux target, gdb/gdbserver/linux-low.c:4714: A problem internal to GDBserver has been detected.^M int finish_step_over(lwp_info*): Assertion `has_reinsert_breakpoints ()' failed. the error happens when GDBserver has already resumed a thread of process A for step-over (and wait for it hitting reinsert breakpoint), but receives detach request for process B from GDB, which is shown in the backtrace below, (gdb) bt #2 0x000228aa in finish_step_over (lwp=0x12bbd98) at /home/yao/SourceCode/gnu/gdb/git/gdb/gdbserver/linux-low.c:4703 #3 0x00025a50 in finish_step_over (lwp=0x12bbd98) at /home/yao/SourceCode/gnu/gdb/git/gdb/gdbserver/linux-low.c:4749 #4 complete_ongoing_step_over () at /home/yao/SourceCode/gnu/gdb/git/gdb/gdbserver/linux-low.c:4760 #5 linux_detach (pid=25228) at /home/yao/SourceCode/gnu/gdb/git/gdb/gdbserver/linux-low.c:1503 #6 0x00012bae in process_serial_event () at /home/yao/SourceCode/gnu/gdb/git/gdb/gdbserver/server.c:3974 #7 handle_serial_event (err=, client_data=) at /home/yao/SourceCode/gnu/gdb/git/gdb/gdbserver/server.c:4347 #8 0x00016d68 in handle_file_event (event_file_desc=) at /home/yao/SourceCode/gnu/gdb/git/gdb/gdbserver/event-loop.c:429 #9 0x000173ea in process_event () at /home/yao/SourceCode/gnu/gdb/git/gdb/gdbserver/event-loop.c:184 #10 start_event_loop () at /home/yao/SourceCode/gnu/gdb/git/gdb/gdbserver/event-loop.c:547 #11 0x0000aa2c in captured_main (argv=, argc=) at /home/yao/SourceCode/gnu/gdb/git/gdb/gdbserver/server.c:3719 #12 main (argc=, argv=) at /home/yao/SourceCode/gnu/gdb/git/gdb/gdbserver/server.c:3804 the sanity check tries to find the reinsert breakpoint from process B, but nothing is found. It is wrong, we need to search in process A, since we started step-over of a thread of process A. (gdb) p lwp->thread->entry.id $3 = {pid = 25120, lwp = 25131, tid = 0} (gdb) p current_thread->entry.id $4 = {pid = 25228, lwp = 25228, tid = 0} This patch switched current_thread to the thread we are doing step-over in complete_ongoing_step_over. gdb/gdbserver: 2016-05-31 Yao Qi * linux-low.c (maybe_hw_step): New function. (linux_resume_one_lwp_throw): Call maybe_hw_step. (finish_step_over): Switch current_thread to lwp temporarily, and assert has_reinsert_breakpoints returns true. (proceed_one_lwp): Call maybe_hw_step. * mem-break.c (has_reinsert_breakpoints): New function. * mem-break.h (has_reinsert_breakpoints): Declare. --- gdb/gdbserver/linux-low.c | 35 +++++++++++++++++++++++++++++++---- gdb/gdbserver/mem-break.c | 22 ++++++++++++++++++++++ gdb/gdbserver/mem-break.h | 4 ++++ 3 files changed, 57 insertions(+), 4 deletions(-) diff --git a/gdb/gdbserver/linux-low.c b/gdb/gdbserver/linux-low.c index 81134b0..77c296c 100644 --- a/gdb/gdbserver/linux-low.c +++ b/gdb/gdbserver/linux-low.c @@ -2495,6 +2495,24 @@ linux_low_filter_event (int lwpid, int wstat) return child; } +/* Return true if THREAD is doing hardware single step. */ + +static int +maybe_hw_step (struct thread_info *thread) +{ + if (can_hardware_single_step ()) + return 1; + else + { + struct process_info *proc = get_thread_process (thread); + + /* GDBserver must insert reinsert breakpoint for software + single step. */ + gdb_assert (has_reinsert_breakpoints (proc)); + return 0; + } +} + /* Resume LWPs that are currently stopped without any pending status to report, but are resumed from the core's perspective. */ @@ -4215,9 +4233,9 @@ linux_resume_one_lwp_throw (struct lwp_info *lwp, fprintf (stderr, "BAD - reinserting and suspended(%d).\n", lwp->suspended); } - - step = 1; } + + step = maybe_hw_step (thread); } if (fast_tp_collecting == 1) @@ -4689,9 +4707,13 @@ finish_step_over (struct lwp_info *lwp) { if (lwp->bp_reinsert != 0) { + struct thread_info *saved_thread = current_thread; + if (debug_threads) debug_printf ("Finished step over.\n"); + current_thread = get_lwp_thread (lwp); + /* Reinsert any breakpoint at LWP->BP_REINSERT. Note that there may be no breakpoint to reinsert there by now. */ reinsert_breakpoints_at (lwp->bp_reinsert); @@ -4705,9 +4727,13 @@ finish_step_over (struct lwp_info *lwp) because we were stepping over a breakpoint, and we hold all threads but LWP stopped while doing that. */ if (!can_hardware_single_step ()) - delete_reinsert_breakpoints (); + { + gdb_assert (has_reinsert_breakpoints (current_process ())); + delete_reinsert_breakpoints (); + } step_over_bkpt = null_ptid; + current_thread = saved_thread; return 1; } else @@ -5029,7 +5055,8 @@ proceed_one_lwp (struct inferior_list_entry *entry, void *except) if (debug_threads) debug_printf (" stepping LWP %ld, reinsert set\n", lwpid_of (thread)); - step = 1; + + step = maybe_hw_step (thread); } else step = 0; diff --git a/gdb/gdbserver/mem-break.c b/gdb/gdbserver/mem-break.c index 363d7ca..3313459 100644 --- a/gdb/gdbserver/mem-break.c +++ b/gdb/gdbserver/mem-break.c @@ -1553,6 +1553,28 @@ reinsert_breakpoints_at (CORE_ADDR pc) } } +int +has_reinsert_breakpoints (struct process_info *proc) +{ + struct breakpoint *bp, **bp_link; + + bp = proc->breakpoints; + bp_link = &proc->breakpoints; + + while (bp) + { + if (bp->type == reinsert_breakpoint) + return 1; + else + { + bp_link = &bp->next; + bp = *bp_link; + } + } + + return 0; +} + void reinsert_all_breakpoints (void) { diff --git a/gdb/gdbserver/mem-break.h b/gdb/gdbserver/mem-break.h index 4d9a76c..b84dc1e 100644 --- a/gdb/gdbserver/mem-break.h +++ b/gdb/gdbserver/mem-break.h @@ -163,6 +163,10 @@ void delete_reinsert_breakpoints (void); void reinsert_breakpoints_at (CORE_ADDR where); +/* Process PROC has reinsert breakpoints or not. */ + +int has_reinsert_breakpoints (struct process_info *proc); + /* Uninsert breakpoints at WHERE (and change their status to uninserted). This still leaves the breakpoints in the table. */