From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 48699 invoked by alias); 11 Sep 2015 06:51:49 -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 48663 invoked by uid 89); 11 Sep 2015 06:51:49 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.0 required=5.0 tests=AWL,BAYES_00,KAM_LAZY_DOMAIN_SECURITY,T_RP_MATCHES_RCVD autolearn=no version=3.3.2 X-HELO: mga14.intel.com Received: from mga14.intel.com (HELO mga14.intel.com) (192.55.52.115) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 11 Sep 2015 06:51:44 +0000 Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by fmsmga103.fm.intel.com with ESMTP; 10 Sep 2015 23:51:43 -0700 X-ExtLoop1: 1 Received: from irvmail001.ir.intel.com ([163.33.26.43]) by FMSMGA003.fm.intel.com with ESMTP; 10 Sep 2015 23:51:41 -0700 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 t8B6pePn021800; Fri, 11 Sep 2015 07:51:40 +0100 Received: from ulvlx001.iul.intel.com (localhost [127.0.0.1]) by ulvlx001.iul.intel.com with ESMTP id t8B6peGp025605; Fri, 11 Sep 2015 08:51:40 +0200 Received: (from mmetzger@localhost) by ulvlx001.iul.intel.com with œ id t8B6pdkC025601; Fri, 11 Sep 2015 08:51:40 +0200 From: Markus Metzger To: palves@redhat.com Cc: gdb-patches@sourceware.org Subject: [PATCH v2 05/17] btrace: split record_btrace_step_thread Date: Fri, 11 Sep 2015 06:51:00 -0000 Message-Id: <1441954298-25298-6-git-send-email-markus.t.metzger@intel.com> In-Reply-To: <1441954298-25298-1-git-send-email-markus.t.metzger@intel.com> References: <1441954298-25298-1-git-send-email-markus.t.metzger@intel.com> X-IsSubscribed: yes X-SW-Source: 2015-09/txt/msg00188.txt.bz2 The code for BTHR_STEP and BTHR_CONT is fairly similar. Extract the common parts into a new function record_btrace_single_step_forward. The function returns TARGET_WAITKIND_SPURIOUS to indicate that the single-step completed without triggering a trap. Same for BTHR_RSTEP and BTHR_RCONT. 2015-09-11 Markus Metzger gdb/ * record-btrace.c (btrace_step_spurious) (record_btrace_single_step_forward) (record_btrace_single_step_backward): New. (record_btrace_step_thread): Call record_btrace_single_step_forward and record_btrace_single_step_backward. --- gdb/record-btrace.c | 187 +++++++++++++++++++++++++++++----------------------- 1 file changed, 105 insertions(+), 82 deletions(-) diff --git a/gdb/record-btrace.c b/gdb/record-btrace.c index 77494ba..fdf7afb 100644 --- a/gdb/record-btrace.c +++ b/gdb/record-btrace.c @@ -1971,6 +1971,18 @@ btrace_step_stopped_on_request (void) return status; } +/* Return a target_waitstatus indicating a spurious stop. */ + +static struct target_waitstatus +btrace_step_spurious (void) +{ + struct target_waitstatus status; + + status.kind = TARGET_WAITKIND_SPURIOUS; + + return status; +} + /* Clear the record histories. */ static void @@ -2011,20 +2023,86 @@ record_btrace_replay_at_breakpoint (struct thread_info *tp) &btinfo->stop_reason); } -/* Step a single thread. */ +/* Step one instruction in forward direction. */ static struct target_waitstatus -record_btrace_step_thread (struct thread_info *tp) +record_btrace_single_step_forward (struct thread_info *tp) { struct btrace_insn_iterator *replay, end; struct btrace_thread_info *btinfo; - enum btrace_thread_flag flags; - unsigned int steps; + btinfo = &tp->btrace; + replay = btinfo->replay; + + /* We're done if we're not replaying. */ + if (replay == NULL) + return btrace_step_no_history (); + + /* Skip gaps during replay. */ + do + { + unsigned int steps; + + steps = btrace_insn_next (replay, 1); + if (steps == 0) + { + record_btrace_stop_replaying (tp); + return btrace_step_no_history (); + } + } + while (btrace_insn_get (replay) == NULL); + + /* Determine the end of the instruction trace. */ + btrace_insn_end (&end, btinfo); + + /* We stop replaying if we reached the end of the trace. */ + if (btrace_insn_cmp (replay, &end) == 0) + record_btrace_stop_replaying (tp); + + return btrace_step_spurious (); +} + +/* Step one instruction in backward direction. */ + +static struct target_waitstatus +record_btrace_single_step_backward (struct thread_info *tp) +{ + struct btrace_insn_iterator *replay; + struct btrace_thread_info *btinfo; btinfo = &tp->btrace; replay = btinfo->replay; + /* Start replaying if we're not already doing so. */ + if (replay == NULL) + replay = record_btrace_start_replaying (tp); + + /* If we can't step any further, we reached the end of the history. + Skip gaps during replay. */ + do + { + unsigned int steps; + + steps = btrace_insn_prev (replay, 1); + if (steps == 0) + return btrace_step_no_history (); + } + while (btrace_insn_get (replay) == NULL); + + return btrace_step_spurious (); +} + +/* Step a single thread. */ + +static struct target_waitstatus +record_btrace_step_thread (struct thread_info *tp) +{ + struct btrace_thread_info *btinfo; + struct target_waitstatus status; + enum btrace_thread_flag flags; + + btinfo = &tp->btrace; + flags = btinfo->flags & (BTHR_MOVE | BTHR_STOP); btinfo->flags &= ~(BTHR_MOVE | BTHR_STOP); @@ -2045,110 +2123,55 @@ record_btrace_step_thread (struct thread_info *tp) return btrace_step_stopped_on_request (); case BTHR_STEP: - /* We're done if we're not replaying. */ - if (replay == NULL) - return btrace_step_no_history (); - - /* Skip gaps during replay. */ - do - { - steps = btrace_insn_next (replay, 1); - if (steps == 0) - { - record_btrace_stop_replaying (tp); - return btrace_step_no_history (); - } - } - while (btrace_insn_get (replay) == NULL); - - /* Determine the end of the instruction trace. */ - btrace_insn_end (&end, btinfo); - - /* We stop replaying if we reached the end of the trace. */ - if (btrace_insn_cmp (replay, &end) == 0) - record_btrace_stop_replaying (tp); + status = record_btrace_single_step_forward (tp); + if (status.kind != TARGET_WAITKIND_SPURIOUS) + return status; return btrace_step_stopped (); case BTHR_RSTEP: - /* Start replaying if we're not already doing so. */ - if (replay == NULL) - replay = record_btrace_start_replaying (tp); - - /* If we can't step any further, we reached the end of the history. - Skip gaps during replay. */ - do - { - steps = btrace_insn_prev (replay, 1); - if (steps == 0) - return btrace_step_no_history (); - - } - while (btrace_insn_get (replay) == NULL); + status = record_btrace_single_step_backward (tp); + if (status.kind != TARGET_WAITKIND_SPURIOUS) + return status; return btrace_step_stopped (); case BTHR_CONT: - /* We're done if we're not replaying. */ - if (replay == NULL) - return btrace_step_no_history (); - - /* Determine the end of the instruction trace. */ - btrace_insn_end (&end, btinfo); - for (;;) { - const struct btrace_insn *insn; + status = record_btrace_single_step_forward (tp); + if (status.kind != TARGET_WAITKIND_SPURIOUS) + return status; - /* Skip gaps during replay. */ - do + if (btinfo->replay != NULL) { - steps = btrace_insn_next (replay, 1); - if (steps == 0) - { - record_btrace_stop_replaying (tp); - return btrace_step_no_history (); - } + const struct btrace_insn *insn; - insn = btrace_insn_get (replay); - } - while (insn == NULL); + insn = btrace_insn_get (btinfo->replay); + gdb_assert (insn != NULL); - /* We stop replaying if we reached the end of the trace. */ - if (btrace_insn_cmp (replay, &end) == 0) - { - record_btrace_stop_replaying (tp); - return btrace_step_no_history (); + DEBUG ("stepping %d (%s) ... %s", tp->num, + target_pid_to_str (tp->ptid), + core_addr_to_string_nz (insn->pc)); } - DEBUG ("stepping %d (%s) ... %s", tp->num, - target_pid_to_str (tp->ptid), - core_addr_to_string_nz (insn->pc)); - if (record_btrace_replay_at_breakpoint (tp)) return btrace_step_stopped (); } case BTHR_RCONT: - /* Start replaying if we're not already doing so. */ - if (replay == NULL) - replay = record_btrace_start_replaying (tp); - for (;;) { const struct btrace_insn *insn; - /* If we can't step any further, we reached the end of the history. - Skip gaps during replay. */ - do - { - steps = btrace_insn_prev (replay, 1); - if (steps == 0) - return btrace_step_no_history (); + status = record_btrace_single_step_backward (tp); + if (status.kind != TARGET_WAITKIND_SPURIOUS) + return status; - insn = btrace_insn_get (replay); - } - while (insn == NULL); + gdb_assert (btinfo->replay != NULL); + + insn = btrace_insn_get (btinfo->replay); + gdb_assert (insn != NULL); DEBUG ("reverse-stepping %d (%s) ... %s", tp->num, target_pid_to_str (tp->ptid), -- 1.8.3.1