Revisão | 47e2c30aacff6c50a2557c86cc00f411b750805b (tree) |
---|---|
Hora | 2022-10-25 18:32:41 |
Autor | Tom de Vries <tdevries@suse...> |
Commiter | Tom de Vries |
[gdb] Rewrite RETHROW_ON_TARGET_CLOSE_ERROR into function
Recent commit b2829fcf9b5 ("[gdb] Fix rethrow exception slicing in
insert_bp_location") introduced macro RETHROW_ON_TARGET_CLOSE_ERROR.
I wrote this as a macro in order to have the rethrowing throw be part of the
same function as the catch, but as it turns out that's not necessary.
Rewrite into a function.
Tested on x86_64-linux.
@@ -2647,23 +2647,28 @@ breakpoint_kind (const struct bp_location *bl, CORE_ADDR *addr) | ||
2647 | 2647 | return gdbarch_breakpoint_kind_from_pc (bl->gdbarch, addr); |
2648 | 2648 | } |
2649 | 2649 | |
2650 | -#define RETHROW_ON_TARGET_CLOSE_ERROR(E) \ | |
2651 | - do \ | |
2652 | - { \ | |
2653 | - if ((E).reason != 0) \ | |
2654 | - { \ | |
2655 | - /* Can't set the breakpoint. */ \ | |
2656 | - \ | |
2657 | - if ((E).error == TARGET_CLOSE_ERROR) \ | |
2658 | - /* If the target has closed then it will have deleted any \ | |
2659 | - breakpoints inserted within the target inferior, as a \ | |
2660 | - result any further attempts to interact with the \ | |
2661 | - breakpoint objects is not possible. Just rethrow the \ | |
2662 | - error. Don't use E to rethrow, to prevent object \ | |
2663 | - slicing of the exception. */ \ | |
2664 | - throw; \ | |
2665 | - } \ | |
2666 | - } while (0) | |
2650 | +/* Rethrow the currently handled exception, if it's a TARGET_CLOSE_ERROR. | |
2651 | + E is either the currently handled exception, or a copy, or a sliced copy, | |
2652 | + so we can't rethrow that one, but we can use it to inspect the properties | |
2653 | + of the currently handled exception. */ | |
2654 | + | |
2655 | +static void | |
2656 | +rethrow_on_target_close_error (const gdb_exception &e) | |
2657 | +{ | |
2658 | + if (e.reason == 0) | |
2659 | + return; | |
2660 | + /* Can't set the breakpoint. */ | |
2661 | + | |
2662 | + if (e.error != TARGET_CLOSE_ERROR) | |
2663 | + return; | |
2664 | + | |
2665 | + /* If the target has closed then it will have deleted any breakpoints | |
2666 | + inserted within the target inferior, as a result any further attempts | |
2667 | + to interact with the breakpoint objects is not possible. Just rethrow | |
2668 | + the error. Don't use e to rethrow, to prevent object slicing of the | |
2669 | + exception. */ | |
2670 | + throw; | |
2671 | +} | |
2667 | 2672 | |
2668 | 2673 | /* Insert a low-level "breakpoint" of some type. BL is the breakpoint |
2669 | 2674 | location. Any error messages are printed to TMP_ERROR_STREAM; and |
@@ -2752,7 +2757,7 @@ insert_bp_location (struct bp_location *bl, | ||
2752 | 2757 | } |
2753 | 2758 | catch (gdb_exception &e) |
2754 | 2759 | { |
2755 | - RETHROW_ON_TARGET_CLOSE_ERROR (e); | |
2760 | + rethrow_on_target_close_error (e); | |
2756 | 2761 | bp_excpt = std::move (e); |
2757 | 2762 | } |
2758 | 2763 | } |
@@ -2792,7 +2797,7 @@ insert_bp_location (struct bp_location *bl, | ||
2792 | 2797 | } |
2793 | 2798 | catch (gdb_exception &e) |
2794 | 2799 | { |
2795 | - RETHROW_ON_TARGET_CLOSE_ERROR (e); | |
2800 | + rethrow_on_target_close_error (e); | |
2796 | 2801 | bp_excpt = std::move (e); |
2797 | 2802 | } |
2798 | 2803 |
@@ -2817,7 +2822,7 @@ insert_bp_location (struct bp_location *bl, | ||
2817 | 2822 | } |
2818 | 2823 | catch (gdb_exception &e) |
2819 | 2824 | { |
2820 | - RETHROW_ON_TARGET_CLOSE_ERROR (e); | |
2825 | + rethrow_on_target_close_error (e); | |
2821 | 2826 | bp_excpt = std::move (e); |
2822 | 2827 | } |
2823 | 2828 | } |