cutu_reader new_reader (per_cu, per_objfile, nullptr, nullptr, false,
m_index_storage->get_abbrev_cache ());
+ if (new_reader.dummy_p || new_reader.comp_unit_die == nullptr
+ || !new_reader.comp_unit_die->has_children)
+ return nullptr;
+
prepare_one_comp_unit (new_reader.cu, new_reader.comp_unit_die,
language_minimal);
std::unique_ptr<cutu_reader> copy
result = m_index_storage->preserve (std::move (copy));
}
- if (result->dummy_p || !result->comp_unit_die->has_children)
+ if (result->dummy_p || result->comp_unit_die == nullptr
+ || !result->comp_unit_die->has_children)
return nullptr;
if (for_scanning)
cutu_reader *new_reader
= ensure_cu_exists (reader, reader->cu->per_objfile, origin_offset,
origin_is_dwz, false);
- if (new_reader != nullptr)
- {
- const gdb_byte *new_info_ptr = (new_reader->buffer
- + to_underlying (origin_offset));
+ if (new_reader == nullptr)
+ error (_(DWARF_ERROR_PREFIX
+ "cannot follow reference to DIE at %s"
+ " [in module %s]"),
+ sect_offset_str (origin_offset),
+ bfd_get_filename (reader->abfd));
- if (*parent_entry == nullptr)
- {
- /* We only perform immediate lookups of parents for DIEs
- from earlier in this CU. This avoids any problem
- with a NULL result when when we see a reference to a
- DIE in another CU that we may or may not have
- imported locally. */
- parent_map::addr_type addr
- = parent_map::form_addr (origin_offset, origin_is_dwz);
- if (new_reader->cu != reader->cu || new_info_ptr > watermark_ptr)
- *maybe_defer = addr;
- else
- *parent_entry = m_die_range_map->find (addr);
- }
+ const gdb_byte *new_info_ptr = (new_reader->buffer
+ + to_underlying (origin_offset));
- unsigned int bytes_read;
- const abbrev_info *new_abbrev = peek_die_abbrev (*new_reader,
- new_info_ptr,
- &bytes_read);
+ if (*parent_entry == nullptr)
+ {
+ /* We only perform immediate lookups of parents for DIEs
+ from earlier in this CU. This avoids any problem
+ with a NULL result when when we see a reference to a
+ DIE in another CU that we may or may not have
+ imported locally. */
+ parent_map::addr_type addr
+ = parent_map::form_addr (origin_offset, origin_is_dwz);
+ if (new_reader->cu != reader->cu || new_info_ptr > watermark_ptr)
+ *maybe_defer = addr;
+ else
+ *parent_entry = m_die_range_map->find (addr);
+ }
- if (new_abbrev == nullptr)
- error (_(DWARF_ERROR_PREFIX
- "Unexpected null DIE at offset %s [in module %s]"),
- sect_offset_str (origin_offset),
- bfd_get_filename (new_reader->abfd));
+ unsigned int bytes_read;
+ const abbrev_info *new_abbrev = peek_die_abbrev (*new_reader,
+ new_info_ptr,
+ &bytes_read);
- new_info_ptr += bytes_read;
+ if (new_abbrev == nullptr)
+ error (_(DWARF_ERROR_PREFIX
+ "Unexpected null DIE at offset %s [in module %s]"),
+ sect_offset_str (origin_offset),
+ bfd_get_filename (new_reader->abfd));
- if (new_reader->cu == reader->cu && new_info_ptr == watermark_ptr)
- {
- /* Self-reference, we're done. */
- }
- else
- scan_attributes (scanning_per_cu, new_reader, new_info_ptr,
- new_info_ptr, new_abbrev, name, linkage_name,
- flags, nullptr, parent_entry, maybe_defer,
- is_enum_class, true);
+ new_info_ptr += bytes_read;
+
+ if (new_reader->cu == reader->cu && new_info_ptr == watermark_ptr)
+ {
+ /* Self-reference, we're done. */
}
+ else
+ scan_attributes (scanning_per_cu, new_reader, new_info_ptr,
+ new_info_ptr, new_abbrev, name, linkage_name,
+ flags, nullptr, parent_entry, maybe_defer,
+ is_enum_class, true);
}
if (!for_specification)
false, cu->lang ());
target_cu = per_objfile->get_cu (per_cu);
- gdb_assert (target_cu != nullptr);
+ if (target_cu == nullptr)
+ error (_(DWARF_ERROR_PREFIX
+ "cannot follow reference to DIE at %s"
+ " [in module %s]"),
+ sect_offset_str (sect_off),
+ objfile_name (per_objfile->objfile));
}
else if (cu->dies == NULL)
{
--- /dev/null
+# Copyright 2024 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+# Check that GDB doesn't crash on invalid dwarf, specifically an inter-CU
+# reference pointing to a dummy CU.
+
+load_lib dwarf.exp
+
+# This test can only be run on targets which support DWARF-2 and use gas.
+require dwarf2_support
+
+standard_testfile main.c .S
+
+# Create the DWARF.
+set asm_file [standard_output_file $srcfile2]
+Dwarf::assemble $asm_file {
+ declare_labels label1
+
+ cu {} {
+ compile_unit {{language @DW_LANG_C}} {
+ subprogram {
+ {MACRO_AT_range { main }}
+ {DW_AT_specification %$label1}
+ }
+ }
+ }
+
+ label1: cu {} {
+ }
+}
+
+if [prepare_for_testing "failed to prepare" $testfile \
+ [list $asm_file $srcfile] {nodebug}] {
+ return -1
+}
+
+gdb_assert \
+ { [regexp "DWARF Error: cannot follow reference" $gdb_file_cmd_msg] } \
+ "Error message"