From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id /qRRJfmdd2lvUhYAWB0awg (envelope-from ) for ; Mon, 26 Jan 2026 12:01:45 -0500 Received: by simark.ca (Postfix, from userid 112) id 87C6B1E0AD; Mon, 26 Jan 2026 12:01:45 -0500 (EST) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-2.3 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, 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 EC8F11E08D for ; Mon, 26 Jan 2026 12:01:44 -0500 (EST) Received: from vm01.sourceware.org (localhost [127.0.0.1]) by sourceware.org (Postfix) with ESMTP id 656464BA9030 for ; Mon, 26 Jan 2026 17:01:44 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 656464BA9030 Received: from simark.ca (simark.ca [158.69.221.121]) by sourceware.org (Postfix) with ESMTPS id EFE614BA2E06 for ; Mon, 26 Jan 2026 17:01:21 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org EFE614BA2E06 Authentication-Results: sourceware.org; dmarc=fail (p=none dis=none) header.from=efficios.com Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=efficios.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org EFE614BA2E06 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=158.69.221.121 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1769446882; cv=none; b=oSLAGurnDRs06YNn5hOIk8d1hN82xcHIP7c9vIG4ehcmlznLZRVUGYy/5s8+r/PRC059pfTtaVjU1cyghIWHIgQGmf4YP4v1Ydi+FWg/lGv8iYrIbNX9xf221G8WeBlgUHy3kxoLHFwJOe/w4X6l5PZiwXUWq0+sTuSgLpvD2MM= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1769446882; c=relaxed/simple; bh=LChHezguuPPQACv7X99gzNO1mXXJ46pjD3UpavS1zwA=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=jy0ujmaB3yCdiuA7r82qxAKjVa/Wv7IRjW0tv9h1W6lkM4Y2pfoVUfrxIRcSnl//5A8zlM4uPBfhehS6HVr3EyVR2IarFxEnmXfDshIf6LgAKhnVQL5uuq2qXykrPW3Si+UXGt2GU2rkJxkJcrDOrQfCMINLIx9JurCx9JZvXcI= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org EFE614BA2E06 Received: by simark.ca (Postfix) id 478BB1E08D; Mon, 26 Jan 2026 12:01:21 -0500 (EST) From: Simon Marchi To: gdb-patches@sourceware.org Cc: Simon Marchi Subject: [PATCH] gdb/dwarf: turn some errors into asserts Date: Mon, 26 Jan 2026 12:01:17 -0500 Message-ID: <20260126170120.268777-1-simon.marchi@efficios.com> X-Mailer: git-send-email 2.52.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 From: Simon Marchi There are some nullptr checks on the return value of load_cu that I think can't possibly ever be true. load_cu returns nullptr only if the CU is "dummy". A "dummy" CU is one that has a header but no DIE. The body (the part after the header, included in the unit reported by the header) is either empty or consists only of zeroes (null entries). In the various spots I modified we are doing some work (e.g. evaluating an expression) in the context of PER_CU, so PER_CU can't possibly be empty / dummy. Change those conditions to asserts. No behavior change expected, unless my reasoning is incorrect. Change-Id: Ic8b0614a15d82d0aaadb8182ee641662cc71dc54 --- gdb/dwarf2/read.c | 27 +++++++++------------------ 1 file changed, 9 insertions(+), 18 deletions(-) diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c index 036ec7e6337f..28a03ab1fbe8 100644 --- a/gdb/dwarf2/read.c +++ b/gdb/dwarf2/read.c @@ -17134,14 +17134,9 @@ dwarf2_fetch_die_loc_sect_off (sect_offset sect_off, dwarf2_per_cu *per_cu, if (cu == nullptr) cu = load_cu (per_cu, per_objfile, false); - if (cu == nullptr) - { - /* We shouldn't get here for a dummy CU, but don't crash on the user. - Instead just throw an error, not much else we can do. */ - error (_(DWARF_ERROR_PREFIX - "Dummy CU at %s referenced [in module %s]"), - sect_offset_str (sect_off), objfile_name (objfile)); - } + /* We know this can't be a dummy CU, since we're executing something from + it. */ + gdb_assert (cu != nullptr); die_info *die = follow_die_offset ({ &cu->section (), sect_off }, &cu); if (die == nullptr) @@ -17274,14 +17269,9 @@ dwarf2_fetch_constant_bytes (sect_offset sect_off, if (cu == nullptr) cu = load_cu (per_cu, per_objfile, false); - if (cu == nullptr) - { - /* We shouldn't get here for a dummy CU, but don't crash on the user. - Instead just throw an error, not much else we can do. */ - error (_(DWARF_ERROR_PREFIX - "Dummy CU at %s referenced [in module %s]"), - sect_offset_str (sect_off), objfile_name (objfile)); - } + /* We know this can't be a dummy CU, since we're executing something from + it. */ + gdb_assert (cu != nullptr); die_info *die = follow_die_offset ({ &cu->section (), sect_off }, &cu); if (!die) @@ -17377,8 +17367,9 @@ dwarf2_fetch_die_type_sect_off (sect_offset sect_off, dwarf2_per_cu *per_cu, if (cu == nullptr) cu = load_cu (per_cu, per_objfile, false); - if (cu == nullptr) - return nullptr; + /* We know this can't be a dummy CU, since we're executing something from + it. */ + gdb_assert (cu != nullptr); die_info *die = follow_die_offset ({ &cu->section (), sect_off }, &cu); if (!die) base-commit: 6660ba84d5484a51e09985c741091152f9febe5c -- 2.52.0