From dbfd92856a3cda8fd08a06c150e5c8f5cf8990be Mon Sep 17 00:00:00 2001 From: Simon Marchi Date: Thu, 24 Apr 2025 16:01:47 -0400 Subject: [PATCH] gdb/dwarf: clean up some cutu_reader::is_dummy() calls This patch tries to standardize the places where we check if units are dummy. When checking if a unit is dummy, it is not necessary to check for some other conditions. - cutu_reader::is_dummy() is a superset of cutu_reader::cu() returning nullptr, so it's not necessary to check if the cu method return nullptr if also checking if the unit is dummy. - cutu_reader::is_dummy() is a superset of cutu_reader::top_level_die() returning nullptr, so same deal. Remove some spots that check for these conditions in addition to cutu_reader::is_dummy(). In addition, also remove the checks for: !new_reader->top_level_die ()->has_children in cooked_indexer::ensure_cu_exists. IMO, it is not useful to special case the units having a single DIE. Especially in this function, which deals with importing things from another unit, a unit with a single DIE would be an edge case that should not happen with good debug info. I think it's preferable to have simpler code. Change-Id: I4529d7b3a0bd2891a60f41671de8cfd3114adb4a Approved-By: Tom Tromey --- gdb/dwarf2/cooked-indexer.c | 6 ++---- gdb/dwarf2/read.c | 4 ++-- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/gdb/dwarf2/cooked-indexer.c b/gdb/dwarf2/cooked-indexer.c index 5776dc5e956..c093984bae0 100644 --- a/gdb/dwarf2/cooked-indexer.c +++ b/gdb/dwarf2/cooked-indexer.c @@ -116,15 +116,13 @@ cooked_indexer::ensure_cu_exists (cutu_reader *reader, nullptr, false, language_minimal, &abbrev_table_cache); - if (new_reader->is_dummy () || new_reader->top_level_die () == nullptr - || !new_reader->top_level_die ()->has_children) + if (new_reader->is_dummy ()) return nullptr; result = m_index_storage->preserve (std::move (new_reader)); } - if (result->is_dummy () || result->top_level_die () == nullptr - || !result->top_level_die ()->has_children) + if (result->is_dummy ()) return nullptr; if (for_scanning) diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c index aa830d402c4..3219bbae7b3 100644 --- a/gdb/dwarf2/read.c +++ b/gdb/dwarf2/read.c @@ -3203,13 +3203,13 @@ process_psymtab_comp_unit (dwarf2_per_cu *this_cu, language_minimal, &abbrev_table_cache); - if (new_reader->cu () == nullptr || new_reader->is_dummy ()) + if (new_reader->is_dummy ()) return; reader = storage->preserve (std::move (new_reader)); } - if (reader->top_level_die () == nullptr || reader->is_dummy ()) + if (reader->is_dummy ()) return; if (this_cu->is_debug_types) -- 2.39.5