From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 91147 invoked by alias); 18 Nov 2015 16:40:08 -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 91113 invoked by uid 89); 18 Nov 2015 16:40:07 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.1 required=5.0 tests=AWL,BAYES_00,RP_MATCHES_RCVD,SPF_HELO_PASS autolearn=ham version=3.3.2 X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Wed, 18 Nov 2015 16:40:06 +0000 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) by mx1.redhat.com (Postfix) with ESMTPS id 80F1965667; Wed, 18 Nov 2015 16:40:05 +0000 (UTC) Received: from brno.lan (ovpn01.gateway.prod.ext.ams2.redhat.com [10.39.146.11]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id tAIGe2Q8030267; Wed, 18 Nov 2015 11:40:04 -0500 From: Pedro Alves To: gdb-patches@sourceware.org Cc: Simon Marchi Subject: [PATCH 1/6] [C++] remote.c: Avoid enum arithmetic Date: Wed, 18 Nov 2015 16:40:00 -0000 Message-Id: <1447864802-24016-2-git-send-email-palves@redhat.com> In-Reply-To: <1447864802-24016-1-git-send-email-palves@redhat.com> References: <1447864802-24016-1-git-send-email-palves@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-SW-Source: 2015-11/txt/msg00369.txt.bz2 Fixes: src/gdb/remote.c: In function ‘void remote_unpush_target()’: src/gdb/remote.c:4610:45: error: invalid conversion from ‘int’ to ‘strata’ [-fpermissive] pop_all_targets_above (process_stratum - 1); ^ In file included from src/gdb/inferior.h:38:0, from src/gdb/remote.c:25: src/gdb/target.h:2299:13: error: initializing argument 1 of ‘void pop_all_targets_above(strata)’ [-fpermissive] extern void pop_all_targets_above (enum strata above_stratum); ^ I used to carry a patch in the C++ branch that just did: - pop_all_targets_above (process_stratum - 1); + pop_all_targets_above ((enum strata) (process_stratum - 1)); But then thought that maybe adding a routine that does exactly what we need results in clearer code. This is the result. gdb/ChangeLog: 2015-11-18 Pedro Alves * remote.c (remote_unpush_target): Use pop_all_targets_at_and_above instead of pop_all_targets_above. * target.c (unpush_target_and_assert): New function, factored out from ... (pop_all_targets_above): ... here. (pop_all_targets_at_and_above): New function. * target.h (pop_all_targets_at_and_above): Declare. --- gdb/remote.c | 2 +- gdb/target.c | 36 +++++++++++++++++++++++++----------- gdb/target.h | 4 ++++ 3 files changed, 30 insertions(+), 12 deletions(-) diff --git a/gdb/remote.c b/gdb/remote.c index fed397a..6c86ab2 100644 --- a/gdb/remote.c +++ b/gdb/remote.c @@ -4607,7 +4607,7 @@ remote_query_supported (void) static void remote_unpush_target (void) { - pop_all_targets_above (process_stratum - 1); + pop_all_targets_at_and_above (process_stratum); } static void diff --git a/gdb/target.c b/gdb/target.c index 93786c3..0ae6708 100644 --- a/gdb/target.c +++ b/gdb/target.c @@ -746,21 +746,35 @@ unpush_target (struct target_ops *t) return 1; } +/* Unpush TARGET and assert that it worked. */ + +static void +unpush_target_and_assert (struct target_ops *target) +{ + if (!unpush_target (target)) + { + fprintf_unfiltered (gdb_stderr, + "pop_all_targets couldn't find target %s\n", + target->to_shortname); + internal_error (__FILE__, __LINE__, + _("failed internal consistency check")); + } +} + void pop_all_targets_above (enum strata above_stratum) { while ((int) (current_target.to_stratum) > (int) above_stratum) - { - if (!unpush_target (target_stack)) - { - fprintf_unfiltered (gdb_stderr, - "pop_all_targets couldn't find target %s\n", - target_stack->to_shortname); - internal_error (__FILE__, __LINE__, - _("failed internal consistency check")); - break; - } - } + unpush_target_and_assert (target_stack); +} + +/* See target.h. */ + +void +pop_all_targets_at_and_above (enum strata stratum) +{ + while ((int) (current_target.to_stratum) >= (int) stratum) + unpush_target_and_assert (target_stack); } void diff --git a/gdb/target.h b/gdb/target.h index 0105db2..e80bee5 100644 --- a/gdb/target.h +++ b/gdb/target.h @@ -2294,6 +2294,10 @@ extern void target_preopen (int); /* Does whatever cleanup is required to get rid of all pushed targets. */ extern void pop_all_targets (void); +/* Like pop_all_targets, but pops only targets whose stratum is at or + above STRATUM. */ +extern void pop_all_targets_at_and_above (enum strata stratum); + /* Like pop_all_targets, but pops only targets whose stratum is strictly above ABOVE_STRATUM. */ extern void pop_all_targets_above (enum strata above_stratum); -- 1.9.3