From patchwork Mon Nov 12 19:00:03 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Marchi X-Patchwork-Id: 30119 Received: (qmail 124195 invoked by alias); 12 Nov 2018 19:00:45 -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 122493 invoked by uid 89); 12 Nov 2018 19:00:33 -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, SPF_PASS autolearn=ham version=3.3.2 spammy= X-HELO: sesbmg22.ericsson.net Received: from sesbmg22.ericsson.net (HELO sesbmg22.ericsson.net) (193.180.251.48) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 12 Nov 2018 19:00:28 +0000 DKIM-Signature: v=1; a=rsa-sha256; d=ericsson.com; s=mailgw201801; c=relaxed/simple; q=dns/txt; i=@ericsson.com; t=1542049206; x=1544641206; 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=lmsEBw7BESGYfReqrQ22F5Kmvw796v17gY7/HrcnxdU=; b=btluBOY0p0bwMXpWjQU26EKXtfLXrGcZjiMv/X8NnjP6+QBzeG0Mu0wHJ8WUTaey Igm+j1YPl+Z5zLFk5urXoFFoLyda+wMSu7VD0EeTOuvQa+XQ//B/YSEEpcaEcYtz PGxEQJzyQCVt1A/scuUMIK0gWuozl1ttHTbUpMe6YF4=; Received: from ESESSMB505.ericsson.se (Unknown_Domain [153.88.183.123]) by sesbmg22.ericsson.net (Symantec Mail Security) with SMTP id 31.73.17348.6BDC9EB5; Mon, 12 Nov 2018 20:00:06 +0100 (CET) Received: from ESESBMB501.ericsson.se (153.88.183.168) by ESESSMB505.ericsson.se (153.88.183.166) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1466.3; Mon, 12 Nov 2018 20:00:06 +0100 Received: from NAM01-BN3-obe.outbound.protection.outlook.com (153.88.183.157) by ESESBMB501.ericsson.se (153.88.183.168) 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; Mon, 12 Nov 2018 20:00:06 +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=7wjjnkWTeVXTegBgdBoHfUNfxZq1akUzlQSUhdH9Q98=; b=iutJD6+5b3MqrNzAvB/KlLtKiXYRl1yoTGhtkw7h+RhD6KHtdI25xA3LxD5Wy1NEYP0FQLU9rWHpbTsCuCdmMHZylzUlOIrBJUFo5AKXQzi2bLLhz4m6WF9yane5xkciCJ/mLvQjALVq3BFToSLyLUExxEU2712cXDheI3ZhsNY= Received: from BYAPR15MB2390.namprd15.prod.outlook.com (52.135.198.30) by BYAPR15MB2264.namprd15.prod.outlook.com (52.135.197.19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1294.27; Mon, 12 Nov 2018 19:00:03 +0000 Received: from BYAPR15MB2390.namprd15.prod.outlook.com ([fe80::649a:ddbf:ecc5:1f0a]) by BYAPR15MB2390.namprd15.prod.outlook.com ([fe80::649a:ddbf:ecc5:1f0a%3]) with mapi id 15.20.1294.044; Mon, 12 Nov 2018 19:00:03 +0000 From: Simon Marchi To: "gdb-patches@sourceware.org" CC: Simon Marchi Subject: [PATCH] Use std::forward_list for displaced_step_inferior_states Date: Mon, 12 Nov 2018 19:00:03 +0000 Message-ID: <20181112185945.24599-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 Use std::forward_list instead of manually implemented list. This simplifies a bit the code, especially around removal. Regtested on the buildbot. There are some failures as always, but I think they are unrelated. gdb/ChangeLog: * infrun.c (displaced_step_inferior_states): Change type to std::forward_list. (get_displaced_stepping_state): Adjust. (displaced_step_in_progress_any_inferior): Adjust. (add_displaced_stepping_state): Adjust. (remove_displaced_stepping_state): Adjust. --- gdb/infrun.c | 80 +++++++++++++++++++++++----------------------------- 1 file changed, 35 insertions(+), 45 deletions(-) diff --git a/gdb/infrun.c b/gdb/infrun.c index 9473d1f20f6..1c48740404e 100644 --- a/gdb/infrun.c +++ b/gdb/infrun.c @@ -1516,39 +1516,36 @@ struct displaced_step_inferior_state /* The list of states of processes involved in displaced stepping presently. */ -static struct displaced_step_inferior_state *displaced_step_inferior_states; +static std::forward_list + displaced_step_inferior_states; /* Get the displaced stepping state of process PID. */ -static struct displaced_step_inferior_state * +static displaced_step_inferior_state * get_displaced_stepping_state (inferior *inf) { - struct displaced_step_inferior_state *state; - - for (state = displaced_step_inferior_states; - state != NULL; - state = state->next) - if (state->inf == inf) - return state; + for (auto *state : displaced_step_inferior_states) + { + if (state->inf == inf) + return state; + } - return NULL; + return nullptr; } /* Returns true if any inferior has a thread doing a displaced step. */ -static int -displaced_step_in_progress_any_inferior (void) +static bool +displaced_step_in_progress_any_inferior () { - struct displaced_step_inferior_state *state; - - for (state = displaced_step_inferior_states; - state != NULL; - state = state->next) - if (state->step_thread != nullptr) - return 1; + for (auto *state : displaced_step_inferior_states) + { + if (state->step_thread != nullptr) + return true; + } - return 0; + return false; } /* Return true if thread represented by PTID is doing a displaced @@ -1584,21 +1581,19 @@ displaced_step_in_progress (inferior *inf) stepping state list, or return a pointer to an already existing entry, if it already exists. Never returns NULL. */ -static struct displaced_step_inferior_state * +static displaced_step_inferior_state * add_displaced_stepping_state (inferior *inf) { - struct displaced_step_inferior_state *state; + displaced_step_inferior_state *state + = get_displaced_stepping_state (inf); - for (state = displaced_step_inferior_states; - state != NULL; - state = state->next) - if (state->inf == inf) - return state; + if (state != nullptr) + return state; state = XCNEW (struct displaced_step_inferior_state); state->inf = inf; - state->next = displaced_step_inferior_states; - displaced_step_inferior_states = state; + + displaced_step_inferior_states.push_front (state); return state; } @@ -1627,24 +1622,19 @@ get_displaced_step_closure_by_addr (CORE_ADDR addr) static void remove_displaced_stepping_state (inferior *inf) { - struct displaced_step_inferior_state *it, **prev_next_p; - gdb_assert (inf != nullptr); - it = displaced_step_inferior_states; - prev_next_p = &displaced_step_inferior_states; - while (it) - { - if (it->inf == inf) - { - *prev_next_p = it->next; - xfree (it); - return; - } - - prev_next_p = &it->next; - it = *prev_next_p; - } + displaced_step_inferior_states.remove_if + ([inf] (displaced_step_inferior_state *state) + { + if (state->inf == inf) + { + xfree (state); + return true; + } + else + return false; + }); } static void