From patchwork Sat Apr 7 14:42:05 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Marchi X-Patchwork-Id: 26639 Received: (qmail 104328 invoked by alias); 7 Apr 2018 14:42:16 -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 104319 invoked by uid 89); 7 Apr 2018 14:42: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, T_FILL_THIS_FORM_SHORT autolearn=ham version=3.3.2 spammy= 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; Sat, 07 Apr 2018 14:42:10 +0000 X-ASG-Debug-ID: 1523112125-0c856e618a8abfd0001-fS2M51 Received: from smtp.ebox.ca (smtp.electronicbox.net [96.127.255.82]) by barracuda.ebox.ca with ESMTP id zdpSqMPQpeDQ8jlM (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Sat, 07 Apr 2018 10:42:05 -0400 (EDT) X-Barracuda-Envelope-From: simon.marchi@polymtl.ca X-Barracuda-RBL-Trusted-Forwarder: 96.127.255.82 Received: from simark.lan (unknown [192.222.164.54]) by smtp.ebox.ca (Postfix) with ESMTP id BE5E7441B21; Sat, 7 Apr 2018 10:42:05 -0400 (EDT) From: Simon Marchi X-Barracuda-Effective-Source-IP: 192-222-164-54.qc.cable.ebox.net[192.222.164.54] X-Barracuda-Apparent-Source-IP: 192.222.164.54 X-Barracuda-RBL-IP: 192.222.164.54 To: gdb-patches@sourceware.org Cc: Simon Marchi Subject: [PATCH] Use an std::vector for inline_states Date: Sat, 7 Apr 2018 10:42:05 -0400 X-ASG-Orig-Subj: [PATCH] Use an std::vector for inline_states Message-Id: <20180407144205.20909-1-simon.marchi@polymtl.ca> X-Barracuda-Connect: smtp.electronicbox.net[96.127.255.82] X-Barracuda-Start-Time: 1523112125 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: 6286 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.49668 Rule breakdown below pts rule name description ---- ---------------------- -------------------------------------------------- X-IsSubscribed: yes This patch replaces VEC(inline_state) with std::vector and adjusts the code that uses it. gdb/ChangeLog: * inline-frame.c: Include . (struct inline_state): Add constructor. (inline_state_s): Remove. (DEF_VEC_O(inline_state_s)): Remove. (inline_states): Change type to std::vector. (find_inline_frame_state): Adjust to std::vector. (allocate_inline_frame_state): Remove. (clear_inline_frame_state): Adjust to std::vector. (skip_inline_frames): Adjust to std::vector. --- gdb/inline-frame.c | 113 +++++++++++++++++++++++------------------------------ 1 file changed, 48 insertions(+), 65 deletions(-) diff --git a/gdb/inline-frame.c b/gdb/inline-frame.c index a01961955949..37c6c1d57e5a 100644 --- a/gdb/inline-frame.c +++ b/gdb/inline-frame.c @@ -27,6 +27,7 @@ #include "symtab.h" #include "vec.h" #include "frame.h" +#include /* We need to save a few variables for every thread stopped at the virtual call site of an inlined function. If there was always a @@ -34,6 +35,12 @@ keep our own list. */ struct inline_state { + inline_state (ptid_t ptid_, int skipped_frames_, CORE_ADDR saved_pc_, + symbol *skipped_symbol_) + : ptid (ptid_), skipped_frames (skipped_frames_), saved_pc (saved_pc_), + skipped_symbol (skipped_symbol_) + {} + /* The thread this data relates to. It should be a currently stopped thread; we assume thread IDs never change while the thread is stopped. */ @@ -55,10 +62,7 @@ struct inline_state struct symbol *skipped_symbol; }; -typedef struct inline_state inline_state_s; -DEF_VEC_O(inline_state_s); - -static VEC(inline_state_s) *inline_states; +static std::vector inline_states; /* Locate saved inlined frame state for PTID, if it exists and is valid. */ @@ -66,43 +70,29 @@ static VEC(inline_state_s) *inline_states; static struct inline_state * find_inline_frame_state (ptid_t ptid) { - struct inline_state *state; - int ix; - - for (ix = 0; VEC_iterate (inline_state_s, inline_states, ix, state); ix++) - { - if (ptid_equal (state->ptid, ptid)) - { - struct regcache *regcache = get_thread_regcache (ptid); - CORE_ADDR current_pc = regcache_read_pc (regcache); - - if (current_pc != state->saved_pc) - { - /* PC has changed - this context is invalid. Use the - default behavior. */ - VEC_unordered_remove (inline_state_s, inline_states, ix); - return NULL; - } - else - return state; - } - } + auto state_it = std::find_if (inline_states.begin (), inline_states.end (), + [&ptid] (const inline_state &state) + { + return ptid == state.ptid; + }); - return NULL; -} + if (state_it == inline_states.end ()) + return nullptr; -/* Allocate saved inlined frame state for PTID. */ + inline_state &state = *state_it; + struct regcache *regcache = get_thread_regcache (ptid); + CORE_ADDR current_pc = regcache_read_pc (regcache); -static struct inline_state * -allocate_inline_frame_state (ptid_t ptid) -{ - struct inline_state *state; + if (current_pc != state.saved_pc) + { + /* PC has changed - this context is invalid. Use the + default behavior. */ - state = VEC_safe_push (inline_state_s, inline_states, NULL); - memset (state, 0, sizeof (*state)); - state->ptid = ptid; + inline_states.erase (state_it); + return nullptr; + } - return state; + return &state; } /* Forget about any hidden inlined functions in PTID, which is new or @@ -112,36 +102,34 @@ allocate_inline_frame_state (ptid_t ptid) void clear_inline_frame_state (ptid_t ptid) { - struct inline_state *state; - int ix; - - if (ptid_equal (ptid, minus_one_ptid)) + if (ptid == minus_one_ptid) { - VEC_free (inline_state_s, inline_states); + inline_states.clear (); return; } - if (ptid_is_pid (ptid)) + if (ptid.is_pid ()) { - VEC (inline_state_s) *new_states = NULL; - int pid = ptid_get_pid (ptid); - - for (ix = 0; - VEC_iterate (inline_state_s, inline_states, ix, state); - ix++) - if (pid != ptid_get_pid (state->ptid)) - VEC_safe_push (inline_state_s, new_states, state); - VEC_free (inline_state_s, inline_states); - inline_states = new_states; + int pid = ptid.pid (); + auto it = std::remove_if (inline_states.begin (), inline_states.end (), + [pid] (const inline_state &state) + { + return pid == state.ptid.pid (); + }); + + inline_states.erase (it, inline_states.end ()); + return; } - for (ix = 0; VEC_iterate (inline_state_s, inline_states, ix, state); ix++) - if (ptid_equal (state->ptid, ptid)) - { - VEC_unordered_remove (inline_state_s, inline_states, ix); - return; - } + auto it = std::find_if (inline_states.begin (), inline_states.end (), + [&ptid] (const inline_state &state) + { + return ptid == state.ptid; + }); + + if (it != inline_states.end ()) + inline_states.erase (it); } static void @@ -303,16 +291,14 @@ block_starting_point_at (CORE_ADDR pc, const struct block *block) void skip_inline_frames (ptid_t ptid) { - CORE_ADDR this_pc; const struct block *frame_block, *cur_block; struct symbol *last_sym = NULL; int skip_count = 0; - struct inline_state *state; /* This function is called right after reinitializing the frame cache. We try not to do more unwinding than absolutely necessary, for performance. */ - this_pc = get_frame_pc (get_current_frame ()); + CORE_ADDR this_pc = get_frame_pc (get_current_frame ()); frame_block = block_for_pc (this_pc); if (frame_block != NULL) @@ -341,10 +327,7 @@ skip_inline_frames (ptid_t ptid) } gdb_assert (find_inline_frame_state (ptid) == NULL); - state = allocate_inline_frame_state (ptid); - state->skipped_frames = skip_count; - state->saved_pc = this_pc; - state->skipped_symbol = last_sym; + inline_states.emplace_back (ptid, skip_count, this_pc, last_sym); if (skip_count != 0) reinit_frame_cache ();