From patchwork Sun Mar 4 20:56:04 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Marchi X-Patchwork-Id: 26189 Received: (qmail 20378 invoked by alias); 4 Mar 2018 20:56:17 -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 20317 invoked by uid 89); 4 Mar 2018 20:56:16 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.2 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_SOFTFAIL autolearn=ham version=3.3.2 spammy=Hx-languages-length:6216 X-HELO: barracuda.ebox.ca Received: from barracuda.ebox.ca (HELO barracuda.ebox.ca) (96.127.255.19) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sun, 04 Mar 2018 20:56:14 +0000 X-ASG-Debug-ID: 1520196969-0c856e618922f110001-fS2M51 Received: from smtp.ebox.ca (smtp.electronicbox.net [96.127.255.82]) by barracuda.ebox.ca with ESMTP id 1OBnFPkA22o0GDF1 (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Sun, 04 Mar 2018 15:56:09 -0500 (EST) X-Barracuda-Envelope-From: simon.marchi@polymtl.ca X-Barracuda-RBL-Trusted-Forwarder: 96.127.255.82 Received: from simark.lan (192-222-251-162.qc.cable.ebox.net [192.222.251.162]) by smtp.ebox.ca (Postfix) with ESMTP id BE5A3441B21; Sun, 4 Mar 2018 15:56:09 -0500 (EST) From: Simon Marchi X-Barracuda-Effective-Source-IP: 192-222-251-162.qc.cable.ebox.net[192.222.251.162] X-Barracuda-Apparent-Source-IP: 192.222.251.162 X-Barracuda-RBL-IP: 192.222.251.162 To: gdb-patches@sourceware.org Cc: Simon Marchi Subject: [PATCH 2/3] btrace: Remove VEC cleanups Date: Sun, 4 Mar 2018 15:56:04 -0500 X-ASG-Orig-Subj: [PATCH 2/3] btrace: Remove VEC cleanups Message-Id: <20180304205605.13037-2-simon.marchi@polymtl.ca> In-Reply-To: <20180304205605.13037-1-simon.marchi@polymtl.ca> References: <20180304205605.13037-1-simon.marchi@polymtl.ca> X-Barracuda-Connect: smtp.electronicbox.net[96.127.255.82] X-Barracuda-Start-Time: 1520196969 X-Barracuda-Encrypted: DHE-RSA-AES256-SHA X-Barracuda-URL: https://96.127.255.19:443/cgi-mod/mark.cgi X-Barracuda-Scan-Msg-Size: 6806 X-Barracuda-BRTS-Status: 1 X-Barracuda-Spam-Score: 0.00 X-Barracuda-Spam-Status: No, SCORE=0.00 using global scores of TAG_LEVEL=1000.0 QUARANTINE_LEVEL=1000.0 KILL_LEVEL=8.0 tests= X-Barracuda-Spam-Report: Code version 3.2, rules version 3.2.3.48563 Rule breakdown below pts rule name description ---- ---------------------- -------------------------------------------------- X-IsSubscribed: yes This patch replaces two VEC(tp_t) with std::vector, which allows to remove two cleanups. To make it easier to map the old code to the new code, I added the ordered_remove and unordered_remove functions, which operate on std::vector and do the same as VEC's ordered_remove/unordered_remove. gdb/ChangeLog: * record-btrace.c (record_btrace_maybe_mark_async_event): Change parameter types to std::vector. Use bool. (record_btrace_wait): Replace VEC(tp_t) with std::vector. * common/gdb_vecs.h (unordered_remove, ordered_remove): New. --- gdb/common/gdb_vecs.h | 31 +++++++++++++++++++++++ gdb/record-btrace.c | 68 +++++++++++++++++++++++++-------------------------- 2 files changed, 64 insertions(+), 35 deletions(-) diff --git a/gdb/common/gdb_vecs.h b/gdb/common/gdb_vecs.h index 29db27a892..7318e53132 100644 --- a/gdb/common/gdb_vecs.h +++ b/gdb/common/gdb_vecs.h @@ -50,4 +50,35 @@ extern void dirnames_to_char_ptr_vec_append extern std::vector> dirnames_to_char_ptr_vec (const char *dirnames); +/* Remove the element at position IX from VEC, not preserving the order of the + remaining elements. Return the removed element. */ + +template +T +unordered_remove (std::vector &vec, typename std::vector::size_type ix) +{ + gdb_assert (ix < vec.size ()); + + T removed = std::move (vec[ix]); + vec[ix] = std::move (vec.back ()); + vec.pop_back (); + + return removed; +} + +/* Remove the element at position IX from VEC, preserving the order the + remaining elements. Return the removed element. */ + +template +T +ordered_remove (std::vector &vec, typename std::vector::size_type ix) +{ + gdb_assert (ix < vec.size ()); + + T removed = std::move (vec[ix]); + vec.erase (vec.begin () + ix); + + return removed; +} + #endif /* GDB_VECS_H */ diff --git a/gdb/record-btrace.c b/gdb/record-btrace.c index b04a7e5049..15ce760f5a 100644 --- a/gdb/record-btrace.c +++ b/gdb/record-btrace.c @@ -2428,13 +2428,12 @@ DEF_VEC_P (tp_t); /* Announce further events if necessary. */ static void -record_btrace_maybe_mark_async_event (const VEC (tp_t) *moving, - const VEC (tp_t) *no_history) +record_btrace_maybe_mark_async_event + (const std::vector &moving, + const std::vector &no_history) { - int more_moving, more_no_history; - - more_moving = !VEC_empty (tp_t, moving); - more_no_history = !VEC_empty (tp_t, no_history); + bool more_moving = !moving.empty (); + bool more_no_history = !no_history.empty ();; if (!more_moving && !more_no_history) return; @@ -2454,9 +2453,8 @@ static ptid_t record_btrace_wait (struct target_ops *ops, ptid_t ptid, struct target_waitstatus *status, int options) { - VEC (tp_t) *moving, *no_history; - struct thread_info *tp, *eventing; - struct cleanup *cleanups = make_cleanup (null_cleanup, NULL); + std::vector moving; + std::vector no_history; DEBUG ("wait %s (0x%x)", target_pid_to_str (ptid), options); @@ -2468,26 +2466,25 @@ record_btrace_wait (struct target_ops *ops, ptid_t ptid, return ops->to_wait (ops, ptid, status, options); } - moving = NULL; - no_history = NULL; - - make_cleanup (VEC_cleanup (tp_t), &moving); - make_cleanup (VEC_cleanup (tp_t), &no_history); - /* Keep a work list of moving threads. */ - ALL_NON_EXITED_THREADS (tp) - if (ptid_match (tp->ptid, ptid) - && ((tp->btrace.flags & (BTHR_MOVE | BTHR_STOP)) != 0)) - VEC_safe_push (tp_t, moving, tp); + { + thread_info *tp; + + ALL_NON_EXITED_THREADS (tp) + { + if (ptid_match (tp->ptid, ptid) + && ((tp->btrace.flags & (BTHR_MOVE | BTHR_STOP)) != 0)) + moving.push_back (tp); + } + } - if (VEC_empty (tp_t, moving)) + if (moving.empty ()) { *status = btrace_step_no_resumed (); DEBUG ("wait ended by %s: %s", target_pid_to_str (null_ptid), target_waitstatus_to_string (status).c_str ()); - do_cleanups (cleanups); return null_ptid; } @@ -2508,14 +2505,13 @@ record_btrace_wait (struct target_ops *ops, ptid_t ptid, nothing else to report. By this time, all threads should have moved to either the beginning or the end of their execution history. There will be a single user-visible stop. */ - eventing = NULL; - while ((eventing == NULL) && !VEC_empty (tp_t, moving)) + struct thread_info *eventing = NULL; + while ((eventing == NULL) && !moving.empty ()) { - unsigned int ix; - - ix = 0; - while ((eventing == NULL) && VEC_iterate (tp_t, moving, ix, tp)) + for (unsigned int ix = 0; eventing == NULL && ix < moving.size ();) { + thread_info *tp = moving[ix]; + *status = record_btrace_step_thread (tp); switch (status->kind) @@ -2525,12 +2521,11 @@ record_btrace_wait (struct target_ops *ops, ptid_t ptid, break; case TARGET_WAITKIND_NO_HISTORY: - VEC_safe_push (tp_t, no_history, - VEC_ordered_remove (tp_t, moving, ix)); + no_history.push_back (ordered_remove (moving, ix)); break; default: - eventing = VEC_unordered_remove (tp_t, moving, ix); + eventing = unordered_remove (moving, ix); break; } } @@ -2543,11 +2538,11 @@ record_btrace_wait (struct target_ops *ops, ptid_t ptid, In the former case, EVENTING must not be NULL. In the latter case, NO_HISTORY must not be empty. */ - gdb_assert (!VEC_empty (tp_t, no_history)); + gdb_assert (!no_history.empty ()); /* We kept threads moving at the end of their execution history. Stop EVENTING now that we are going to report its stop. */ - eventing = VEC_unordered_remove (tp_t, no_history, 0); + eventing = unordered_remove (no_history, 0); eventing->btrace.flags &= ~BTHR_MOVE; *status = btrace_step_no_history (); @@ -2561,8 +2556,12 @@ record_btrace_wait (struct target_ops *ops, ptid_t ptid, /* Stop all other threads. */ if (!target_is_non_stop_p ()) - ALL_NON_EXITED_THREADS (tp) - record_btrace_cancel_resume (tp); + { + thread_info *tp; + + ALL_NON_EXITED_THREADS (tp) + record_btrace_cancel_resume (tp); + } /* In async mode, we need to announce further events. */ if (target_is_async_p ()) @@ -2579,7 +2578,6 @@ record_btrace_wait (struct target_ops *ops, ptid_t ptid, target_pid_to_str (eventing->ptid), target_waitstatus_to_string (status).c_str ()); - do_cleanups (cleanups); return eventing->ptid; }