From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1726) id 1068D384D17C; Thu, 21 Jul 2022 18:20:32 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1068D384D17C Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Andrew Burgess To: gdb-cvs@sourceware.org Subject: [binutils-gdb] gdb: ensure the cast in gdbarch_tdep is valid X-Act-Checkin: binutils-gdb X-Git-Author: Andrew Burgess X-Git-Refname: refs/heads/master X-Git-Oldrev: 11da1b13b313ae46c84008ebf096ffed1701e3c1 X-Git-Newrev: c44885db3b56c83a12e88a176c03f2a2268428b8 Message-Id: <20220721182032.1068D384D17C@sourceware.org> Date: Thu, 21 Jul 2022 18:20:32 +0000 (GMT) X-BeenThere: gdb-cvs@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 21 Jul 2022 18:20:32 -0000 https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3Dc44885db3b56= c83a12e88a176c03f2a2268428b8 commit c44885db3b56c83a12e88a176c03f2a2268428b8 Author: Andrew Burgess Date: Thu May 19 13:55:41 2022 +0100 gdb: ensure the cast in gdbarch_tdep is valid =20 This commit makes use of gdb::checked_static_cast when casting the generic gdbarch_tdep pointer to a specific sub-class type. This means that, when compiled in developer mode, GDB will validate that the cast is correct. =20 In order to use gdb::checked_static_cast the types involved must have RTTI, which is why the gdbarch_tdep base class now has a virtual destructor. =20 Assuming there are no bugs in GDB where we cast a gdbarch_tdep pointer to the wrong type, then there should be no changes after this commit. =20 If any bugs do exist, then GDB will now assert (in a developer build). Diff: --- gdb/gdbarch.h | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/gdb/gdbarch.h b/gdb/gdbarch.h index b2c91db0c4f..16c73915c64 100644 --- a/gdb/gdbarch.h +++ b/gdb/gdbarch.h @@ -28,6 +28,7 @@ #include "infrun.h" #include "osabi.h" #include "displaced-stepping.h" +#include "gdbsupport/gdb-checked-static-cast.h" =20 struct floatformat; struct ui_file; @@ -58,7 +59,14 @@ struct inferior; =20 #include "regcache.h" =20 -struct gdbarch_tdep {}; +/* The base class for every architecture's tdep sub-class. The virtual + destructor ensures the class has RTTI information, which allows + gdb::checked_static_cast to be used, the gdbarch_tdep the function. */ + +struct gdbarch_tdep +{ + virtual ~gdbarch_tdep() =3D default; +}; =20 /* The architecture associated with the inferior through the connection to the target. @@ -157,7 +165,7 @@ static inline TDepType * gdbarch_tdep (struct gdbarch *gdbarch) { struct gdbarch_tdep *tdep =3D gdbarch_tdep_1 (gdbarch); - return static_cast (tdep); + return gdb::checked_static_cast (tdep); } =20 /* Mechanism for co-ordinating the selection of a specific