public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Pedro Alves <palves@redhat.com>
To: gdb-patches@sourceware.org
Cc: Simon Marchi <simon.marchi@ericsson.com>
Subject: [PATCH 1/6] [C++] remote.c: Avoid enum arithmetic
Date: Wed, 18 Nov 2015 16:40:00 -0000	[thread overview]
Message-ID: <1447864802-24016-2-git-send-email-palves@redhat.com> (raw)
In-Reply-To: <1447864802-24016-1-git-send-email-palves@redhat.com>

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  <palves@redhat.com>

	* 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

  parent reply	other threads:[~2015-11-18 16:40 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-11-18 16:40 [PATCH 0/6] [C++] Drop -fpermissive hack, enable -Werror Pedro Alves
2015-11-18 16:40 ` [PATCH 2/6] [C++] linux-thread-db.c: dladdr cast Pedro Alves
2015-11-18 16:40 ` Pedro Alves [this message]
2015-11-18 16:40 ` [PATCH 3/6] [C++] s390: Fix enum gdb_syscall conversion Pedro Alves
2015-11-18 16:40 ` [PATCH 5/6] [C++] Drop -fpermissive hack Pedro Alves
2015-11-18 16:40 ` [PATCH 4/6] [C++] breakpoint.c: "no memory" software watchpoints and enum casts Pedro Alves
2015-11-18 16:48 ` [PATCH 0/6] [C++] Drop -fpermissive hack, enable -Werror Simon Marchi
2015-11-18 16:49 ` [PATCH 6/6] [C++] Default to -Werror in C++ mode too Pedro Alves
2015-11-18 17:44 ` [PATCH 0/6] [C++] Drop -fpermissive hack, enable -Werror Yao Qi
2015-11-18 17:53   ` Pedro Alves
2015-11-19 11:28     ` Yao Qi
2015-11-19 15:14       ` Pedro Alves
2015-11-20  9:46         ` Yao Qi
2015-11-20 11:21           ` Pedro Alves
2015-11-24 11:01             ` Yao Qi
2015-11-24 13:17               ` Pedro Alves
2015-11-24 14:37                 ` Joel Brobecker
2015-11-24 13:19             ` Pedro Alves
2015-11-19 15:17       ` Pedro Alves

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1447864802-24016-2-git-send-email-palves@redhat.com \
    --to=palves@redhat.com \
    --cc=gdb-patches@sourceware.org \
    --cc=simon.marchi@ericsson.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).