From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 31415 invoked by alias); 9 May 2017 07:01:09 -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 17551 invoked by uid 89); 9 May 2017 07:00:42 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-24.6 required=5.0 tests=AWL,BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,KAM_LAZY_DOMAIN_SECURITY,RP_MATCHES_RCVD autolearn=ham version=3.3.2 spammy=11249 X-HELO: mga03.intel.com Received: from mga03.intel.com (HELO mga03.intel.com) (134.134.136.65) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 09 May 2017 07:00:40 +0000 Received: from orsmga005.jf.intel.com ([10.7.209.41]) by orsmga103.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 09 May 2017 00:00:20 -0700 X-ExtLoop1: 1 Received: from irvmail001.ir.intel.com ([163.33.26.43]) by orsmga005.jf.intel.com with ESMTP; 09 May 2017 00:00:16 -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 v4970Ght016653; Tue, 9 May 2017 08:00:16 +0100 Received: from ulvlx001.iul.intel.com (localhost [127.0.0.1]) by ulvlx001.iul.intel.com with ESMTP id v4970Fvl023973; Tue, 9 May 2017 09:00:15 +0200 Received: (from twiederh@localhost) by ulvlx001.iul.intel.com with œ id v4970Fkj023969; Tue, 9 May 2017 09:00:15 +0200 From: Tim Wiederhake To: gdb-patches@sourceware.org Cc: markus.t.metzger@intel.com Subject: [PATCH v3 11/12] btrace: Remove bfun_s vector. Date: Tue, 09 May 2017 07:01:00 -0000 Message-Id: <1494312929-22749-12-git-send-email-tim.wiederhake@intel.com> In-Reply-To: <1494312929-22749-1-git-send-email-tim.wiederhake@intel.com> References: <1494312929-22749-1-git-send-email-tim.wiederhake@intel.com> X-IsSubscribed: yes X-SW-Source: 2017-05/txt/msg00197.txt.bz2 2017-05-09 Tim Wiederhake gdb/ChangeLog: * btrace.c: Remove typedef bfun_s. (ftrace_new_gap): Directly add gaps to the list of gaps. (btrace_bridge_gaps, btrace_compute_ftrace_bts, pt_btrace_insn_flags, ftrace_add_pt, btrace_compute_ftrace_pt, btrace_compute_ftrace_1, btrace_finalize_ftrace, btrace_compute_ftrace): Use std::vector instead of gdb VEC. --- gdb/btrace.c | 107 ++++++++++++++++++++--------------------------------------- 1 file changed, 36 insertions(+), 71 deletions(-) diff --git a/gdb/btrace.c b/gdb/btrace.c index 921cb64..7b82000 100644 --- a/gdb/btrace.c +++ b/gdb/btrace.c @@ -49,10 +49,6 @@ static struct cmd_list_element *maint_btrace_pt_show_cmdlist; /* Control whether to skip PAD packets when computing the packet history. */ static int maint_btrace_pt_skip_pad = 1; -/* A vector of function segments. */ -typedef struct btrace_function * bfun_s; -DEF_VEC_P (bfun_s); - static void btrace_add_pc (struct thread_info *tp); /* Print a record debug message. Use do ... while (0) to avoid ambiguities @@ -512,7 +508,8 @@ ftrace_new_switch (struct btrace_thread_info *btinfo, ERRCODE is the format-specific error code. */ static struct btrace_function * -ftrace_new_gap (struct btrace_thread_info *btinfo, int errcode) +ftrace_new_gap (struct btrace_thread_info *btinfo, int errcode, + std::vector &gaps) { struct btrace_function *bfun; @@ -527,15 +524,15 @@ ftrace_new_gap (struct btrace_thread_info *btinfo, int errcode) } bfun->errcode = errcode; + gaps.push_back (bfun->number); ftrace_debug (bfun, "new gap"); return bfun; } -/* Update BFUN with respect to the instruction at PC. BTINFO is the branch - trace information for the current thread. This may create new function - segments. +/* Update the current function segment at the end of the trace in BTINFO with + respect to the instruction at PC. This may create new function segments. Return the chronologically latest function segment, never NULL. */ static struct btrace_function * @@ -955,19 +952,14 @@ ftrace_bridge_gap (struct btrace_thread_info *btinfo, function segments that are separated by the gap. */ static void -btrace_bridge_gaps (struct thread_info *tp, VEC (bfun_s) **gaps) +btrace_bridge_gaps (struct thread_info *tp, std::vector &gaps) { struct btrace_thread_info *btinfo = &tp->btrace; - VEC (bfun_s) *remaining; - struct cleanup *old_chain; + std::vector remaining; int min_matches; DEBUG ("bridge gaps"); - btinfo = &tp->btrace; - remaining = NULL; - old_chain = make_cleanup (VEC_cleanup (bfun_s), &remaining); - /* We require a minimum amount of matches for bridging a gap. The number of required matches will be lowered with each iteration. @@ -978,16 +970,15 @@ btrace_bridge_gaps (struct thread_info *tp, VEC (bfun_s) **gaps) { /* Let's try to bridge as many gaps as we can. In some cases, we need to skip a gap and revisit it again after we closed later gaps. */ - while (!VEC_empty (bfun_s, *gaps)) + while (!gaps.empty ()) { - struct btrace_function *gap; - unsigned int idx; - - for (idx = 0; VEC_iterate (bfun_s, *gaps, idx, gap); ++idx) + for (const auto& number : gaps) { - struct btrace_function *lhs, *rhs; + struct btrace_function *gap, *lhs, *rhs; int bridged; + gap = ftrace_find_call_by_number (btinfo, number); + /* We may have a sequence of gaps if we run from one error into the next as we try to re-sync onto the trace stream. Ignore all but the leftmost gap in such a sequence. @@ -1012,28 +1003,24 @@ btrace_bridge_gaps (struct thread_info *tp, VEC (bfun_s) **gaps) If we just pushed them to the end of GAPS we would risk an infinite loop in case we simply cannot bridge a gap. */ if (bridged == 0) - VEC_safe_push (bfun_s, remaining, gap); + remaining.push_back (number); } /* Let's see if we made any progress. */ - if (VEC_length (bfun_s, remaining) == VEC_length (bfun_s, *gaps)) + if (remaining.size () == gaps.size ()) break; - VEC_free (bfun_s, *gaps); - - *gaps = remaining; - remaining = NULL; + gaps.clear (); + gaps.swap (remaining); } /* We get here if either GAPS is empty or if GAPS equals REMAINING. */ - if (VEC_empty (bfun_s, *gaps)) + if (gaps.empty ()) break; - VEC_free (bfun_s, remaining); + remaining.clear (); } - do_cleanups (old_chain); - /* We may omit this in some cases. Not sure it is worth the extra complication, though. */ ftrace_compute_global_level_offset (btinfo); @@ -1044,7 +1031,7 @@ btrace_bridge_gaps (struct thread_info *tp, VEC (bfun_s) **gaps) static void btrace_compute_ftrace_bts (struct thread_info *tp, const struct btrace_data_bts *btrace, - VEC (bfun_s) **gaps) + std::vector &gaps) { struct btrace_thread_info *btinfo; struct gdbarch *gdbarch; @@ -1080,9 +1067,7 @@ btrace_compute_ftrace_bts (struct thread_info *tp, if (block->end < pc) { /* Indicate the gap in the trace. */ - bfun = ftrace_new_gap (btinfo, BDE_BTS_OVERFLOW); - - VEC_safe_push (bfun_s, *gaps, bfun); + bfun = ftrace_new_gap (btinfo, BDE_BTS_OVERFLOW, gaps); warning (_("Recorded trace may be corrupted at instruction " "%u (pc = %s)."), bfun->insn_offset - 1, @@ -1124,9 +1109,7 @@ btrace_compute_ftrace_bts (struct thread_info *tp, { /* Indicate the gap in the trace. We just added INSN so we're not at the beginning. */ - bfun = ftrace_new_gap (btinfo, BDE_BTS_INSN_SIZE); - - VEC_safe_push (bfun_s, *gaps, bfun); + bfun = ftrace_new_gap (btinfo, BDE_BTS_INSN_SIZE, gaps); warning (_("Recorded trace may be incomplete at instruction %u " "(pc = %s)."), bfun->insn_offset - 1, @@ -1205,7 +1188,7 @@ static void ftrace_add_pt (struct btrace_thread_info *btinfo, struct pt_insn_decoder *decoder, int *plevel, - VEC (bfun_s) **gaps) + std::vector &gaps) { struct btrace_function *bfun; uint64_t offset; @@ -1240,9 +1223,7 @@ ftrace_add_pt (struct btrace_thread_info *btinfo, from some other instruction. Indicate this as a trace gap. */ if (insn.enabled) { - bfun = ftrace_new_gap (btinfo, BDE_PT_DISABLED); - - VEC_safe_push (bfun_s, *gaps, bfun); + bfun = ftrace_new_gap (btinfo, BDE_PT_DISABLED, gaps); pt_insn_get_offset (decoder, &offset); @@ -1255,9 +1236,7 @@ ftrace_add_pt (struct btrace_thread_info *btinfo, /* Indicate trace overflows. */ if (insn.resynced) { - bfun = ftrace_new_gap (btinfo, BDE_PT_OVERFLOW); - - VEC_safe_push (bfun_s, *gaps, bfun); + bfun = ftrace_new_gap (btinfo, BDE_PT_OVERFLOW, gaps); pt_insn_get_offset (decoder, &offset); @@ -1279,9 +1258,7 @@ ftrace_add_pt (struct btrace_thread_info *btinfo, break; /* Indicate the gap in the trace. */ - bfun = ftrace_new_gap (btinfo, errcode); - - VEC_safe_push (bfun_s, *gaps, bfun); + bfun = ftrace_new_gap (btinfo, errcode, gaps); pt_insn_get_offset (decoder, &offset); @@ -1357,7 +1334,7 @@ static void btrace_finalize_ftrace_pt (struct pt_insn_decoder *decoder, static void btrace_compute_ftrace_pt (struct thread_info *tp, const struct btrace_data_pt *btrace, - VEC (bfun_s) **gaps) + std::vector &gaps) { struct btrace_thread_info *btinfo; struct pt_insn_decoder *decoder; @@ -1410,13 +1387,7 @@ btrace_compute_ftrace_pt (struct thread_info *tp, { /* Indicate a gap in the trace if we quit trace processing. */ if (error.reason == RETURN_QUIT && !btinfo->functions.empty ()) - { - struct btrace_function *bfun; - - bfun = ftrace_new_gap (btinfo, BDE_PT_USER_QUIT); - - VEC_safe_push (bfun_s, *gaps, bfun); - } + ftrace_new_gap (btinfo, BDE_PT_USER_QUIT, gaps); btrace_finalize_ftrace_pt (decoder, tp, level); @@ -1432,7 +1403,7 @@ btrace_compute_ftrace_pt (struct thread_info *tp, static void btrace_compute_ftrace_pt (struct thread_info *tp, const struct btrace_data_pt *btrace, - VEC (bfun_s) **gaps) + std::vector &gaps) { internal_error (__FILE__, __LINE__, _("Unexpected branch trace format.")); } @@ -1444,7 +1415,7 @@ btrace_compute_ftrace_pt (struct thread_info *tp, static void btrace_compute_ftrace_1 (struct thread_info *tp, struct btrace_data *btrace, - VEC (bfun_s) **gaps) + std::vector &gaps) { DEBUG ("compute ftrace"); @@ -1466,11 +1437,11 @@ btrace_compute_ftrace_1 (struct thread_info *tp, struct btrace_data *btrace, } static void -btrace_finalize_ftrace (struct thread_info *tp, VEC (bfun_s) **gaps) +btrace_finalize_ftrace (struct thread_info *tp, std::vector &gaps) { - if (!VEC_empty (bfun_s, *gaps)) + if (!gaps.empty ()) { - tp->btrace.ngaps += VEC_length (bfun_s, *gaps); + tp->btrace.ngaps += gaps.size (); btrace_bridge_gaps (tp, gaps); } } @@ -1478,27 +1449,21 @@ btrace_finalize_ftrace (struct thread_info *tp, VEC (bfun_s) **gaps) static void btrace_compute_ftrace (struct thread_info *tp, struct btrace_data *btrace) { - VEC (bfun_s) *gaps; - struct cleanup *old_chain; - - gaps = NULL; - old_chain = make_cleanup (VEC_cleanup (bfun_s), &gaps); + std::vector gaps; TRY { - btrace_compute_ftrace_1 (tp, btrace, &gaps); + btrace_compute_ftrace_1 (tp, btrace, gaps); } CATCH (error, RETURN_MASK_ALL) { - btrace_finalize_ftrace (tp, &gaps); + btrace_finalize_ftrace (tp, gaps); throw_exception (error); } END_CATCH - btrace_finalize_ftrace (tp, &gaps); - - do_cleanups (old_chain); + btrace_finalize_ftrace (tp, gaps); } /* Add an entry for the current PC. */ -- 2.7.4