From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id +RdwG0On6GmYjTMAWB0awg (envelope-from ) for ; Wed, 22 Apr 2026 06:47:31 -0400 Authentication-Results: simark.ca; dkim=pass (2048-bit key; unprotected) header.d=vrany.io header.i=@vrany.io header.a=rsa-sha256 header.s=protonmail3 header.b=muVlos3X; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 6D29B1E0C3; Wed, 22 Apr 2026 06:47:31 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-2.4 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED,RCVD_IN_VALIDITY_CERTIFIED_BLOCKED, RCVD_IN_VALIDITY_RPBL_BLOCKED,RCVD_IN_VALIDITY_SAFE_BLOCKED autolearn=ham autolearn_force=no version=4.0.1 Received: from vm01.sourceware.org (vm01.sourceware.org [38.145.34.32]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 7B9F81E067 for ; Wed, 22 Apr 2026 06:47:30 -0400 (EDT) Received: from vm01.sourceware.org (localhost [127.0.0.1]) by sourceware.org (Postfix) with ESMTP id C83914BC0575 for ; Wed, 22 Apr 2026 10:47:29 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C83914BC0575 Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=vrany.io header.i=@vrany.io header.a=rsa-sha256 header.s=protonmail3 header.b=muVlos3X Received: from mail-4318.protonmail.ch (mail-4318.protonmail.ch [185.70.43.18]) by sourceware.org (Postfix) with ESMTPS id 8E95D48FDEFE for ; Wed, 22 Apr 2026 10:30:37 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 8E95D48FDEFE Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=vrany.io Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=vrany.io ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 8E95D48FDEFE Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=185.70.43.18 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1776853837; cv=none; b=h0xvbagB0bLKkBMG40sfrqfI/UZ85DoaWLfFCYRYHXy8gBbqFoZykh3RWNxIyJ0nBvXuuDnPkr+oxyjxzCciUPgIfLzUSKiw7+76i8cZHT3d0LYWC/oO2hUMipWSuAPOYWtqB8dS2DnH7p9wUhZchPwgGKlALWq9hO5GAgYR3Ko= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1776853837; c=relaxed/simple; bh=8zLBhRHdmyyAWmpIYJyC4WWBAFfq5vOtjFkKWN65UQ0=; h=DKIM-Signature:Date:To:From:Subject:Message-ID:MIME-Version; b=Gn10KZojeV9e4fjaAdcTz+Ed1cmKkMU5IPJ8SFjgxM5zyPJDf2zh3xqpO/OhmeLYZRr0VUCi2U2WG113tYvoij+U9GLQ2o+G2K9JIyFv8KlYtpeJL6CGNcWSH1Lw5Py9dgIu8VOw7QxN+/XCCJ9UPr+yKmrdDyiv+kvHB2wj41M= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8E95D48FDEFE DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vrany.io; s=protonmail3; t=1776853834; x=1777113034; bh=bg4G7EbX8JrxIVLEV4jpOwt2uBHCyCHU6Ytu0Al8Khk=; h=Date:To:From:Cc:Subject:Message-ID:In-Reply-To:References: Feedback-ID:From:To:Cc:Date:Subject:Reply-To:Feedback-ID: Message-ID:BIMI-Selector; b=muVlos3XzcvwZ1MGv9VJ/m5KyK//L3n1yjV1Ufl1Kk1BxcB6kSvhs5vulhewejmJc OcEm08ldFfFWNII8Ds/0WJjUBQhfPRjwI9z5RcTPLOGP2p/taY1nsLcHNc3zfWDWZu ZULxYkqV5INfdrrpdMhy7O//boVF8fRacV7FRAURBjETyBpbe3JaLs9eYkqhJKkwmr Za/r+PXS0jxXe8Nc3os4FTqSSjONxRGtoK03QGVKxTkF6xbXZoQ+/v8n0tMlJOZbqM HAgYdhvzIyG3A7cM34YXnV4NGUPHuRB1CT63vpo+8ArLFiQ5uhRIf3mT+QEtK4Zk+h ynLW0fRgjib0w== Date: Wed, 22 Apr 2026 10:30:28 +0000 To: gdb-patches@sourceware.org From: Jan Vrany Cc: Jan Vrany Subject: [PATCH v3 7/7] gdb: add unit test for blockvector::lookup of non-contiguous blocks Message-ID: <20260422102923.1185738-8-jan@vrany.io> In-Reply-To: <20260304165914.3209106-1-jan.vrany@labware.com> References: <20260304165914.3209106-1-jan.vrany@labware.com> Feedback-ID: 40767693:user:proton X-Pm-Message-ID: b712f0068b16571eef4e10d265339208118d0ada MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces~public-inbox=simark.ca@sourceware.org This commit add a new unit test that tests block lookup when blocks are non-contiguous. --- gdb/block-selftests.c | 72 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) diff --git a/gdb/block-selftests.c b/gdb/block-selftests.c index 77b8d67ded8..c41a9ac7e82 100644 --- a/gdb/block-selftests.c +++ b/gdb/block-selftests.c @@ -81,6 +81,75 @@ test_blockvector_lookup_contains () SELF_CHECK (bv->contains (0x4000) =3D=3D false); } =20 +/* Create and return struct blockranges* from 2 ranges. */ +static struct blockranges * +make_blockranges_2 (struct obstack &ob, CORE_ADDR start0, CORE_ADDR end0, +=09=09 CORE_ADDR start1, CORE_ADDR end1) +{ + struct blockranges *ranges =3D (struct blockranges *) obstack_alloc + (&ob, sizeof (struct blockranges) + (2 - 1) * sizeof (struct blockrang= e)); + + ranges->nranges =3D 2; + ranges->range[0].set_start (start0); + ranges->range[0].set_end (end0); + ranges->range[1].set_start (start1); + ranges->range[1].set_end (end1); + + return ranges; +} + +static void +test_blockvector_lookup_non_continuguous () +{ + /* Create blockvector with following blocks: + +=09B0 0x1000 - 0x8000 (global block) +=09B1 0x1000 - 0x8000 (static block) +=09 B2 0x1000 - 0x2000 (B2's range 1) +=09 B3 0x2000 - 0x3000 (B3's range 1) +=09=09=09=09 (hole 1) +=09 B4 0x5000 - 0x5500 +=09=09=09=09 (hole 2) +=09 (B2) 0x6000 - 0x7000 (B2's range 2) +=09 (B3) 0x7000 - 0x8000 (B3's range 2) + + Blocks B2 and B3 are non-continguous (consist of two + disjoint ranges) and interleaved. + */ + auto_obstack ob; + blockvector_up bv =3D std::make_unique (0); + + auto global_block =3D make_block (*bv.get (), ob, 0x1000, 0x8000); + auto static_block =3D make_block (*bv.get (), ob, 0x1000, 0x8000, +=09=09=09=09 global_block); + auto b2 =3D make_block (*bv.get (), ob, 0x1000, 0x7000, static_block); + b2->set_ranges (make_blockranges_2 (ob, 0x1000, 0x2000, 0x6000, 0x7000))= ; + auto b3 =3D make_block (*bv.get (), ob, 0x2000, 0x8000, static_block); + b3->set_ranges (make_blockranges_2 (ob, 0x2000, 0x3000, 0x7000, 0x8000))= ; + auto b4 =3D make_block (*bv.get (), ob, 0x5000, 0x5500, static_block); + + /* Test address falling into range 1 of B2. */ + SELF_CHECK (bv->lookup (0x1500) =3D=3D b2); + + /* Test address falling into range 2 of B2. */ + SELF_CHECK (bv->lookup (0x6000) =3D=3D b2); + + /* Test address falling into range 1 of B3. */ + SELF_CHECK (bv->lookup (0x2500) =3D=3D b3); + + /* Test address falling into range 2 of B3. */ + SELF_CHECK (bv->lookup (0x7999) =3D=3D b3); + + /* Test address falling into B4. */ + SELF_CHECK (bv->lookup (0x5250) =3D=3D b4); + + /* Test address falling into hole 1. */ + SELF_CHECK (bv->lookup (0x4000) =3D=3D static_block); + + /* Test address falling into hole 2. */ + SELF_CHECK (bv->lookup (0x5750) =3D=3D static_block); +} + } /* namespace selftests */ =20 =20 @@ -88,4 +157,7 @@ INIT_GDB_FILE (block_selftest) { selftests::register_test ("blockvector-lookup-contains", =09=09=09 selftests::test_blockvector_lookup_contains); + selftests::register_test + ("blockvector-lookup-non-contiguous", + selftests::test_blockvector_lookup_non_continuguous); } --=20 2.53.0