From patchwork Thu Nov 22 03:12:43 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Marchi X-Patchwork-Id: 30258 Received: (qmail 27332 invoked by alias); 22 Nov 2018 03:12:55 -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 27309 invoked by uid 89); 22 Nov 2018 03:12:54 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3 autolearn=ham version=3.3.2 spammy=H*Ad:U*dblaikie, hand-made, handmade X-HELO: sessmg23.ericsson.net Received: from sessmg23.ericsson.net (HELO sessmg23.ericsson.net) (193.180.251.45) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 22 Nov 2018 03:12:52 +0000 DKIM-Signature: v=1; a=rsa-sha256; d=ericsson.com; s=mailgw201801; c=relaxed/simple; q=dns/txt; i=@ericsson.com; t=1542856369; x=1545448369; h=From:Sender:Reply-To:Subject:Date:Message-ID:To:CC:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=SSD6bk05TcL1bpCJNm2Bn4M0WfowAnesf+y5WrosmhM=; b=coKJ9PhoPjqSjC24PJVbcuG9grdQyagLo+jegTvsMb+SD0staAgH2r8X2JiRh97E TsOJ0481p5CIRcmk/fO+ysOZzhwnd+XLeMzSL8NL5dqNVC0K4jUEqlXJBQswWKEG jQvvasl8YrHsdnfZCpIirC7PqbYde+sWDeSGzdUbIWU=; Received: from ESESSMB501.ericsson.se (Unknown_Domain [153.88.183.119]) by sessmg23.ericsson.net (Symantec Mail Security) with SMTP id BC.40.31473.1BE16FB5; Thu, 22 Nov 2018 04:12:49 +0100 (CET) Received: from ESESSMR501.ericsson.se (153.88.183.108) by ESESSMB501.ericsson.se (153.88.183.119) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1466.3; Thu, 22 Nov 2018 04:12:46 +0100 Received: from ESESBMB502.ericsson.se (153.88.183.169) by ESESSMR501.ericsson.se (153.88.183.108) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1466.3; Thu, 22 Nov 2018 04:12:46 +0100 Received: from NAM02-BL2-obe.outbound.protection.outlook.com (153.88.183.157) by ESESBMB502.ericsson.se (153.88.183.169) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1466.3 via Frontend Transport; Thu, 22 Nov 2018 04:12:45 +0100 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ericsson.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=PJHHezwJd71/FWWgCuYER0zBh9BCq8KEpLSyd1DLrMI=; b=JniRCiAHoCHzsxGWSnuGNsUkzUCbUulKhDlrVVKuqn0WKntj7FmxGIJi+bwnCsCRDStGfOg8KSZwbH5nwLei5vWhuSqWtkOEowEXkTnT+owP5utCij49mLcDTqpDGesjNb8bDFid/i1B2dBYyU4W+Yz/fzQxw2o+jml05bh9LBs= Received: from BYAPR15MB2390.namprd15.prod.outlook.com (52.135.198.30) by BYAPR15MB2392.namprd15.prod.outlook.com (52.135.198.139) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1339.20; Thu, 22 Nov 2018 03:12:43 +0000 Received: from BYAPR15MB2390.namprd15.prod.outlook.com ([fe80::2978:b8d7:86fd:94ed]) by BYAPR15MB2390.namprd15.prod.outlook.com ([fe80::2978:b8d7:86fd:94ed%3]) with mapi id 15.20.1294.048; Thu, 22 Nov 2018 03:12:43 +0000 From: Simon Marchi To: "gdb-patches@sourceware.org" CC: "dblaikie@gmail.com" , Simon Marchi Subject: [PATCH] Use std::vector for displaced_step_inferior_states Date: Thu, 22 Nov 2018 03:12:43 +0000 Message-ID: <20181122031229.15621-1-simon.marchi@ericsson.com> authentication-results: spf=none (sender IP is ) smtp.mailfrom=simon.marchi@ericsson.com; received-spf: None (protection.outlook.com: ericsson.com does not designate permitted sender hosts) MIME-Version: 1.0 Return-Path: simon.marchi@ericsson.com X-IsSubscribed: yes Commit 39a36629f68e ("Use std::forward_list for displaced_step_inferior_states") changed a hand-made linked list to use std::forward_list of pointers. As suggested by David Blaikie, we might as well use values instead of pointers. And instead of a list, we might as well use a vector. The size of this list will always be at most the number of inferiors, typically very small. And in any case the operation we do in the hottest path (doing a displaced step) is iterate, and iterating on a vector is always faster than a linked list. A consequence of using a vector is that objects can be moved, when the vector is resized. I don't think this is a problem, because we don't save the address of the objects. In displaced_step_prepare_throw, we save a pointer to the step_saved_copy field in a cleanup, but it is ran or discarded immediately after. gdb/ChangeLog: * infrun.c (struct displaced_step_inferior_state): Add constructor, initialize fields. : Change type to bool. (displaced_step_inferior_states): Change type to vector. (get_displaced_stepping_state): Adjust. (displaced_step_in_progress_any_inferior): Adjust. (add_displaced_stepping_state): Adjust. (remove_displaced_stepping_state): Adjust. (displaced_step_prepare): Change 1 to true. --- gdb/infrun.c | 57 ++++++++++++++++++++++++++-------------------------- 1 file changed, 28 insertions(+), 29 deletions(-) diff --git a/gdb/infrun.c b/gdb/infrun.c index 3e9acb45aa9..6cdcd1a1f93 100644 --- a/gdb/infrun.c +++ b/gdb/infrun.c @@ -1484,36 +1484,40 @@ displaced_step_closure::~displaced_step_closure () = default; /* Per-inferior displaced stepping state. */ struct displaced_step_inferior_state { + displaced_step_inferior_state (inferior *inf) + : inf (inf) + {} + /* The process this displaced step state refers to. */ inferior *inf; /* True if preparing a displaced step ever failed. If so, we won't try displaced stepping for this inferior again. */ - int failed_before; + bool failed_before = false; /* If this is not nullptr, this is the thread carrying out a displaced single-step in process PID. This thread's state will require fixing up once it has completed its step. */ - thread_info *step_thread; + thread_info *step_thread = nullptr; /* The architecture the thread had when we stepped it. */ - struct gdbarch *step_gdbarch; + gdbarch *step_gdbarch = nullptr; /* The closure provided gdbarch_displaced_step_copy_insn, to be used for post-step cleanup. */ - struct displaced_step_closure *step_closure; + displaced_step_closure *step_closure = nullptr; /* The address of the original instruction, and the copy we made. */ - CORE_ADDR step_original, step_copy; + CORE_ADDR step_original = 0, step_copy = 0; /* Saved contents of copy area. */ - gdb_byte *step_saved_copy; + gdb_byte *step_saved_copy = nullptr; }; /* The list of states of processes involved in displaced stepping presently. */ -static std::forward_list +static std::vector displaced_step_inferior_states; /* Get the displaced stepping state of process PID. */ @@ -1521,10 +1525,10 @@ static std::forward_list static displaced_step_inferior_state * get_displaced_stepping_state (inferior *inf) { - for (auto *state : displaced_step_inferior_states) + for (auto &state : displaced_step_inferior_states) { - if (state->inf == inf) - return state; + if (state.inf == inf) + return &state; } return nullptr; @@ -1536,9 +1540,9 @@ get_displaced_stepping_state (inferior *inf) static bool displaced_step_in_progress_any_inferior () { - for (auto *state : displaced_step_inferior_states) + for (const auto &state : displaced_step_inferior_states) { - if (state->step_thread != nullptr) + if (state.step_thread != nullptr) return true; } @@ -1587,12 +1591,9 @@ add_displaced_stepping_state (inferior *inf) if (state != nullptr) return state; - state = XCNEW (struct displaced_step_inferior_state); - state->inf = inf; + displaced_step_inferior_states.emplace_back (inf); - displaced_step_inferior_states.push_front (state); - - return state; + return &displaced_step_inferior_states.back (); } /* If inferior is in displaced stepping, and ADDR equals to starting address @@ -1621,17 +1622,15 @@ remove_displaced_stepping_state (inferior *inf) { gdb_assert (inf != nullptr); - displaced_step_inferior_states.remove_if - ([inf] (displaced_step_inferior_state *state) - { - if (state->inf == inf) - { - xfree (state); - return true; - } - else - return false; - }); + auto it = std::find_if (displaced_step_inferior_states.begin (), + displaced_step_inferior_states.end (), + [inf] (const displaced_step_inferior_state &s) + { + return s.inf == inf; + }); + + if (it != displaced_step_inferior_states.end ()) + displaced_step_inferior_states.erase (it); } static void @@ -1910,7 +1909,7 @@ displaced_step_prepare (thread_info *thread) /* Disable further displaced stepping attempts. */ displaced_state = get_displaced_stepping_state (thread->inf); - displaced_state->failed_before = 1; + displaced_state->failed_before = true; } END_CATCH