[C++] remote.c: Avoid enum arithmetic
authorPedro Alves <palves@redhat.com>
Thu, 19 Nov 2015 14:32:53 +0000 (14:32 +0000)
committerPedro Alves <palves@redhat.com>
Thu, 19 Nov 2015 14:32:53 +0000 (14:32 +0000)
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-19  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/ChangeLog
gdb/remote.c
gdb/target.c
gdb/target.h

index d1b40b8f7a803dd3e11628924d8b7ba583f36c2c..e6d7aac7be4c1effc34bc6ff114d5d8c94d1dc70 100644 (file)
@@ -1,3 +1,13 @@
+2015-11-19  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.
+
 2015-11-18  Simon Marchi  <simon.marchi@ericsson.com>
 
        * valops.c (value_string): Constify 'ptr' parameter.
index fed397affeabe1e0716324bebd9fb4db7f91bebd..6c86ab2224b50288e84a601779b27a607acd3766 100644 (file)
@@ -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
index 93786c3e214299bff485147633e545ceda4e269a..0ae6708f81ff9b43aea8f73f0eee6fe743f07166 100644 (file)
@@ -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
index 0105db2e5418b4274354ba9840bed9534f83d9cc..e80bee5d494ccf4de74e4eb9cb03efaa4449382b 100644 (file)
@@ -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);