* [PATCH] gdb/dwarf: turn some errors into asserts
@ 2026-01-26 17:01 Simon Marchi
2026-02-02 17:42 ` Kevin Buettner
0 siblings, 1 reply; 3+ messages in thread
From: Simon Marchi @ 2026-01-26 17:01 UTC (permalink / raw)
To: gdb-patches; +Cc: Simon Marchi
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
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH] gdb/dwarf: turn some errors into asserts
2026-01-26 17:01 [PATCH] gdb/dwarf: turn some errors into asserts Simon Marchi
@ 2026-02-02 17:42 ` Kevin Buettner
2026-02-02 18:15 ` Simon Marchi
0 siblings, 1 reply; 3+ messages in thread
From: Kevin Buettner @ 2026-02-02 17:42 UTC (permalink / raw)
To: gdb-patches; +Cc: Simon Marchi, Simon Marchi
On Mon, 26 Jan 2026 12:01:17 -0500
Simon Marchi <simon.marchi@efficios.com> wrote:
> 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
>
> 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.
I agree with your reasoning.
Approved-by: Kevin Buettner <kevinb@redhat.com>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] gdb/dwarf: turn some errors into asserts
2026-02-02 17:42 ` Kevin Buettner
@ 2026-02-02 18:15 ` Simon Marchi
0 siblings, 0 replies; 3+ messages in thread
From: Simon Marchi @ 2026-02-02 18:15 UTC (permalink / raw)
To: Kevin Buettner, gdb-patches; +Cc: Simon Marchi
On 2026-02-02 12:42, Kevin Buettner wrote:
> On Mon, 26 Jan 2026 12:01:17 -0500
> Simon Marchi <simon.marchi@efficios.com> wrote:
>
>> 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
>>
>> 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.
>
> I agree with your reasoning.
>
> Approved-by: Kevin Buettner <kevinb@redhat.com>
>
Pushed, thanks!
Simon
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-02-02 18:15 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-01-26 17:01 [PATCH] gdb/dwarf: turn some errors into asserts Simon Marchi
2026-02-02 17:42 ` Kevin Buettner
2026-02-02 18:15 ` Simon Marchi
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox