Révision | 915ef8b18e28e6418216a582067b9fbdd6395e6a (tree) |
---|---|
l'heure | 2015-11-19 23:32:53 |
Auteur | Pedro Alves <palves@redh...> |
Commiter | Pedro Alves |
[C++] remote.c: Avoid enum arithmetic
Fixes:
from src/gdb/remote.c:25:
I used to carry a patch in the C++ branch that just did:
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.
@@ -1,3 +1,13 @@ | ||
1 | +2015-11-19 Pedro Alves <palves@redhat.com> | |
2 | + | |
3 | + * remote.c (remote_unpush_target): Use | |
4 | + pop_all_targets_at_and_above instead of pop_all_targets_above. | |
5 | + * target.c (unpush_target_and_assert): New function, factored out | |
6 | + from ... | |
7 | + (pop_all_targets_above): ... here. | |
8 | + (pop_all_targets_at_and_above): New function. | |
9 | + * target.h (pop_all_targets_at_and_above): Declare. | |
10 | + | |
1 | 11 | 2015-11-18 Simon Marchi <simon.marchi@ericsson.com> |
2 | 12 | |
3 | 13 | * valops.c (value_string): Constify 'ptr' parameter. |
@@ -4607,7 +4607,7 @@ remote_query_supported (void) | ||
4607 | 4607 | static void |
4608 | 4608 | remote_unpush_target (void) |
4609 | 4609 | { |
4610 | - pop_all_targets_above (process_stratum - 1); | |
4610 | + pop_all_targets_at_and_above (process_stratum); | |
4611 | 4611 | } |
4612 | 4612 | |
4613 | 4613 | static void |
@@ -746,21 +746,35 @@ unpush_target (struct target_ops *t) | ||
746 | 746 | return 1; |
747 | 747 | } |
748 | 748 | |
749 | +/* Unpush TARGET and assert that it worked. */ | |
750 | + | |
751 | +static void | |
752 | +unpush_target_and_assert (struct target_ops *target) | |
753 | +{ | |
754 | + if (!unpush_target (target)) | |
755 | + { | |
756 | + fprintf_unfiltered (gdb_stderr, | |
757 | + "pop_all_targets couldn't find target %s\n", | |
758 | + target->to_shortname); | |
759 | + internal_error (__FILE__, __LINE__, | |
760 | + _("failed internal consistency check")); | |
761 | + } | |
762 | +} | |
763 | + | |
749 | 764 | void |
750 | 765 | pop_all_targets_above (enum strata above_stratum) |
751 | 766 | { |
752 | 767 | while ((int) (current_target.to_stratum) > (int) above_stratum) |
753 | - { | |
754 | - if (!unpush_target (target_stack)) | |
755 | - { | |
756 | - fprintf_unfiltered (gdb_stderr, | |
757 | - "pop_all_targets couldn't find target %s\n", | |
758 | - target_stack->to_shortname); | |
759 | - internal_error (__FILE__, __LINE__, | |
760 | - _("failed internal consistency check")); | |
761 | - break; | |
762 | - } | |
763 | - } | |
768 | + unpush_target_and_assert (target_stack); | |
769 | +} | |
770 | + | |
771 | +/* See target.h. */ | |
772 | + | |
773 | +void | |
774 | +pop_all_targets_at_and_above (enum strata stratum) | |
775 | +{ | |
776 | + while ((int) (current_target.to_stratum) >= (int) stratum) | |
777 | + unpush_target_and_assert (target_stack); | |
764 | 778 | } |
765 | 779 | |
766 | 780 | void |
@@ -2294,6 +2294,10 @@ extern void target_preopen (int); | ||
2294 | 2294 | /* Does whatever cleanup is required to get rid of all pushed targets. */ |
2295 | 2295 | extern void pop_all_targets (void); |
2296 | 2296 | |
2297 | +/* Like pop_all_targets, but pops only targets whose stratum is at or | |
2298 | + above STRATUM. */ | |
2299 | +extern void pop_all_targets_at_and_above (enum strata stratum); | |
2300 | + | |
2297 | 2301 | /* Like pop_all_targets, but pops only targets whose stratum is |
2298 | 2302 | strictly above ABOVE_STRATUM. */ |
2299 | 2303 | extern void pop_all_targets_above (enum strata above_stratum); |