From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2205) id E30FC38582A2; Tue, 25 Oct 2022 09:32:47 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E30FC38582A2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1666690369; bh=9Z3FaMtwy8dsvCKrap79OnILLGVwfqmEIjVCyBXT9dE=; h=From:To:Subject:Date:From; b=vXqFW/VD6fpe7ZNXoRb0tXEQKVLJsWpeoFwXzzz32+22ZSez239L7NWK8tCJSu68e q1cPlMV7IEtRrsEMT3LD4G/rDCHQtKNe5BdgLQmoj6RhIvp+d68zs4PulGGg+sC2CH NeZotf8MVHPIYRB+ZilIYavt0pvzb4zp/4ERfh6U= Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Tom de Vries To: gdb-cvs@sourceware.org Subject: [binutils-gdb] [gdb] Rewrite RETHROW_ON_TARGET_CLOSE_ERROR into function X-Act-Checkin: binutils-gdb X-Git-Author: Tom de Vries X-Git-Refname: refs/heads/master X-Git-Oldrev: a5a0a4fd0ff536a8dbd532864cfc095a306b678c X-Git-Newrev: 47e2c30aacff6c50a2557c86cc00f411b750805b Message-Id: <20221025093249.E30FC38582A2@sourceware.org> Date: Tue, 25 Oct 2022 09:32:47 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3D47e2c30aacff= 6c50a2557c86cc00f411b750805b commit 47e2c30aacff6c50a2557c86cc00f411b750805b Author: Tom de Vries Date: Tue Oct 25 11:32:41 2022 +0200 [gdb] Rewrite RETHROW_ON_TARGET_CLOSE_ERROR into function =20 Recent commit b2829fcf9b5 ("[gdb] Fix rethrow exception slicing in insert_bp_location") introduced macro RETHROW_ON_TARGET_CLOSE_ERROR. =20 I wrote this as a macro in order to have the rethrowing throw be part o= f the same function as the catch, but as it turns out that's not necessary. =20 Rewrite into a function. =20 Tested on x86_64-linux. Diff: --- gdb/breakpoint.c | 45 +++++++++++++++++++++++++-------------------- 1 file changed, 25 insertions(+), 20 deletions(-) diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c index a001e78cfb4..30826032360 100644 --- a/gdb/breakpoint.c +++ b/gdb/breakpoint.c @@ -2647,23 +2647,28 @@ breakpoint_kind (const struct bp_location *bl, CORE= _ADDR *addr) return gdbarch_breakpoint_kind_from_pc (bl->gdbarch, addr); } =20 -#define RETHROW_ON_TARGET_CLOSE_ERROR(E) \ - do \ - { \ - if ((E).reason !=3D 0) \ - { \ - /* Can't set the breakpoint. */ \ - \ - if ((E).error =3D=3D TARGET_CLOSE_ERROR) \ - /* If the target has closed then it will have deleted any \ - breakpoints inserted within the target inferior, as a \ - result any further attempts to interact with the \ - breakpoint objects is not possible. Just rethrow the \ - error. Don't use E to rethrow, to prevent object \ - slicing of the exception. */ \ - throw; \ - } \ - } while (0) +/* Rethrow the currently handled exception, if it's a TARGET_CLOSE_ERROR. + E is either the currently handled exception, or a copy, or a sliced cop= y, + so we can't rethrow that one, but we can use it to inspect the properti= es + of the currently handled exception. */ + +static void +rethrow_on_target_close_error (const gdb_exception &e) +{ + if (e.reason =3D=3D 0) + return; + /* Can't set the breakpoint. */ + + if (e.error !=3D TARGET_CLOSE_ERROR) + return; + + /* If the target has closed then it will have deleted any breakpoints + inserted within the target inferior, as a result any further attempts + to interact with the breakpoint objects is not possible. Just rethrow + the error. Don't use e to rethrow, to prevent object slicing of the + exception. */ + throw; +} =20 /* Insert a low-level "breakpoint" of some type. BL is the breakpoint location. Any error messages are printed to TMP_ERROR_STREAM; and @@ -2752,7 +2757,7 @@ insert_bp_location (struct bp_location *bl, } catch (gdb_exception &e) { - RETHROW_ON_TARGET_CLOSE_ERROR (e); + rethrow_on_target_close_error (e); bp_excpt =3D std::move (e); } } @@ -2792,7 +2797,7 @@ insert_bp_location (struct bp_location *bl, } catch (gdb_exception &e) { - RETHROW_ON_TARGET_CLOSE_ERROR (e); + rethrow_on_target_close_error (e); bp_excpt =3D std::move (e); } =20 @@ -2817,7 +2822,7 @@ insert_bp_location (struct bp_location *bl, } catch (gdb_exception &e) { - RETHROW_ON_TARGET_CLOSE_ERROR (e); + rethrow_on_target_close_error (e); bp_excpt =3D std::move (e); } }