From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 8FF7C39213C8 for ; Tue, 28 Jun 2022 14:29:14 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 8FF7C39213C8 Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-112-ktJh-re6PV-YWVZ8NV0Cjw-1; Tue, 28 Jun 2022 10:29:13 -0400 X-MC-Unique: ktJh-re6PV-YWVZ8NV0Cjw-1 Received: by mail-wm1-f69.google.com with SMTP id v184-20020a1cacc1000000b0039c7efa3e95so5168213wme.3 for ; Tue, 28 Jun 2022 07:29:12 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=iQ74dGiSYS7f69oF5TAZ0ES5N0vz1aklwfAg3Issa6M=; b=Q2Tsjr33UXed+tc3kOrrMxct2HN6oQN4AFGhZ0j+zzBbQmfrzb53qnrEvoMVTbyLGZ isoTXSZpMqm4LEDjQHivFjYI8iLMxSTsqCWmjiEXdDp9aPsDoAI8JFvfhfg3eIhg+5a7 vN+SF7nioVNQTwfcv68jJjSrHhXdVT2/Ec6dzaI0uSHpSFwpQ0rcejCnEwE/mz8wEPcE vFlWDJ6xRa5J/Jj1J92yPQpGBXO9hugBVZwpphQiTG14XQEr9vyak9GOAC3Z2oGexLl4 ZooqTrl6ZlG4pafx1pjLnfsWzKHaBJu3DYjWNJI0qnSFNAi+Xc7HoGOaVMoq+G101qwp P0LQ== X-Gm-Message-State: AJIora+znYJtSCGLQ6kYmMXKfExRoME8l7SiuXAjHyfFQ0p6vupURMkv tkBP+A78HyXTjDPwOev+xtzvrVY8BK83Qwmt4YkTz3EoRnsSUHtchtQd27GCVfLaY0On02oTWXd f2kRsAhGbGWxa4JY5soJDrtPPiM4xa7wVJtavElEe44eLBeLt+ZFPkwCwRc/G49YAPHwtc4IG0w == X-Received: by 2002:adf:ee4c:0:b0:21b:81ae:79cf with SMTP id w12-20020adfee4c000000b0021b81ae79cfmr17705388wro.121.1656426551710; Tue, 28 Jun 2022 07:29:11 -0700 (PDT) X-Google-Smtp-Source: AGRyM1uNKvFccqozNvcgk6xOeZQAG445Q8BVquNoFwOOBs6GiyQ6yj5b3nSb8SZYu7bjrs7lSyJjGw== X-Received: by 2002:adf:ee4c:0:b0:21b:81ae:79cf with SMTP id w12-20020adfee4c000000b0021b81ae79cfmr17705368wro.121.1656426551478; Tue, 28 Jun 2022 07:29:11 -0700 (PDT) Received: from localhost (15.72.115.87.dyn.plus.net. [87.115.72.15]) by smtp.gmail.com with ESMTPSA id l1-20020a5d4bc1000000b00219e77e489fsm13551293wrt.17.2022.06.28.07.29.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Jun 2022 07:29:10 -0700 (PDT) From: Andrew Burgess To: gdb-patches@sourceware.org Cc: Andrew Burgess Subject: [PATCHv4 6/6] gdb: ensure the cast in gdbarch_tdep is valid Date: Tue, 28 Jun 2022 15:28:57 +0100 Message-Id: <8fadee96195098aee85b81e7302549309f914cee.1656426157.git.aburgess@redhat.com> X-Mailer: git-send-email 2.25.4 In-Reply-To: References: MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true X-Spam-Status: No, score=-10.5 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_BARRACUDACENTRAL, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 28 Jun 2022 14:29:15 -0000 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. 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. 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. If any bugs do exist, then GDB will now assert (in a developer build). --- 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" struct floatformat; struct ui_file; @@ -58,7 +59,14 @@ struct inferior; #include "regcache.h" -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() = default; +}; /* 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 = gdbarch_tdep_1 (gdbarch); - return static_cast (tdep); + return gdb::checked_static_cast (tdep); } /* Mechanism for co-ordinating the selection of a specific -- 2.25.4