From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lndn.lancelotsix.com (vps-42846194.vps.ovh.net [IPv6:2001:41d0:801:2000::2400]) by sourceware.org (Postfix) with ESMTPS id ED9623858D39 for ; Wed, 20 Oct 2021 20:05:56 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org ED9623858D39 Received: from Plymouth.lan (unknown [IPv6:2a02:390:9086:0:b54d:5442:bf49:23dd]) by lndn.lancelotsix.com (Postfix) with ESMTPSA id B4D7884383; Wed, 20 Oct 2021 20:05:55 +0000 (UTC) From: Lancelot SIX To: gdb-patches@sourceware.org Cc: Lancelot SIX Subject: [PATCH 0/2] Improve constraints on gdb::array_view::array_view Date: Wed, 20 Oct 2021 21:05:23 +0100 Message-Id: <20211020200525.122108-1-lsix@lancelotsix.com> X-Mailer: git-send-email 2.33.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Greylist: Sender succeeded SMTP AUTH, not delayed by milter-greylist-4.5.11 (lndn.lancelotsix.com [0.0.0.0]); Wed, 20 Oct 2021 20:05:55 +0000 (UTC) X-Spam-Status: No, score=-5.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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: Wed, 20 Oct 2021 20:05:58 -0000 Hi, Wile reading around, I realized that the gdb::array_view interface has a potential of being miss-used. No worry, it is not miss-used in practice in the current codebase, but fixing this might save debugging time in the future. It is possible to create a gdb::array_view to refer to data inside a std::vector (or any contiguous container of U) if a U* is convertible to a T*. If U is a class that inherits from T this condition holds but U and T most likely do not have the same memory layout. In such situation the array_view will get it wrong (the second patch gives an example of a miss-use of a gdb::array_view). In this series I propose to change slightly the requirements on the gdb::array_view::array_view constructor so this scenario cannot compile. No change is expected from this series. The first patch just adds a const version of gdb_argv::as_array_view that will be used in the second patch. The second patch implements the change on the gdb::array_view and makes minor adjustments so everything still compiles. All feedback are welcome. Best, Lancelot. P.S. Since I started this series, Simon Marchi have sent another series dealing with array_view[1]. I have applied this series on top of mine and check that everything still compiles. [1] https://sourceware.org/pipermail/gdb-patches/2021-October/182657.html Lancelot SIX (2): Add a const version of gdb_argv:as_array_view Improve gdb::array_view ctor from contiguous containers gdb/dwarf2/read.c | 2 +- gdb/maint.c | 2 +- gdb/utils.h | 10 ++++++++++ gdbsupport/array-view.h | 7 ++++--- 4 files changed, 16 insertions(+), 5 deletions(-) -- 2.33.0