Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Simon Marchi <simon.marchi@efficios.com>
To: gdb-patches@sourceware.org
Cc: Simon Marchi <simon.marchi@polymtl.ca>
Subject: [PATCH] gdb/dwarf: turn some errors into asserts
Date: Mon, 26 Jan 2026 12:01:17 -0500	[thread overview]
Message-ID: <20260126170120.268777-1-simon.marchi@efficios.com> (raw)

From: Simon Marchi <simon.marchi@polymtl.ca>

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


             reply	other threads:[~2026-01-26 17:01 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-01-26 17:01 Simon Marchi [this message]
2026-02-02 17:42 ` Kevin Buettner
2026-02-02 18:15   ` Simon Marchi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260126170120.268777-1-simon.marchi@efficios.com \
    --to=simon.marchi@efficios.com \
    --cc=gdb-patches@sourceware.org \
    --cc=simon.marchi@polymtl.ca \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox