diff options
Diffstat (limited to 'gdb')
-rw-r--r-- | gdb/dwarf2/read.c | 35 | ||||
-rw-r--r-- | gdb/testsuite/gdb.dwarf2/dw2-inter-cu-forth-and-back.exp | 60 |
2 files changed, 80 insertions, 15 deletions
diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c index f9f34fd..04a5398 100644 --- a/gdb/dwarf2/read.c +++ b/gdb/dwarf2/read.c @@ -4532,28 +4532,35 @@ process_psymtab_comp_unit (dwarf2_per_cu_data *this_cu, dwarf2_per_objfile *per_objfile, cooked_index_storage *storage) { - cutu_reader reader (this_cu, per_objfile, nullptr, nullptr, false, - storage->get_abbrev_cache ()); + cutu_reader *reader = storage->get_reader (this_cu); + if (reader == nullptr) + { + cutu_reader new_reader (this_cu, per_objfile, nullptr, nullptr, false, + storage->get_abbrev_cache ()); - if (reader.comp_unit_die == nullptr) - return; + if (new_reader.comp_unit_die == nullptr || new_reader.dummy_p) + return; - if (reader.dummy_p) - { - /* Nothing. */ + std::unique_ptr<cutu_reader> copy + (new cutu_reader (std::move (new_reader))); + reader = storage->preserve (std::move (copy)); } - else if (this_cu->is_debug_types) - build_type_psymtabs_reader (&reader, storage); - else if (reader.comp_unit_die->tag != DW_TAG_partial_unit) + + if (reader->comp_unit_die == nullptr || reader->dummy_p) + return; + + if (this_cu->is_debug_types) + build_type_psymtabs_reader (reader, storage); + else if (reader->comp_unit_die->tag != DW_TAG_partial_unit) { bool nope = false; if (this_cu->scanned.compare_exchange_strong (nope, true)) { - prepare_one_comp_unit (reader.cu, reader.comp_unit_die, + prepare_one_comp_unit (reader->cu, reader->comp_unit_die, language_minimal); gdb_assert (storage != nullptr); - cooked_indexer indexer (storage, this_cu, reader.cu->lang ()); - indexer.make_index (&reader); + cooked_indexer indexer (storage, this_cu, reader->cu->lang ()); + indexer.make_index (reader); } } } @@ -16030,8 +16037,6 @@ cooked_indexer::ensure_cu_exists (cutu_reader *reader, if (!per_cu->scanned.compare_exchange_strong (nope, true)) return nullptr; } - if (per_cu == m_per_cu) - return reader; cutu_reader *result = m_index_storage->get_reader (per_cu); if (result == nullptr) diff --git a/gdb/testsuite/gdb.dwarf2/dw2-inter-cu-forth-and-back.exp b/gdb/testsuite/gdb.dwarf2/dw2-inter-cu-forth-and-back.exp new file mode 100644 index 0000000..62674bd --- /dev/null +++ b/gdb/testsuite/gdb.dwarf2/dw2-inter-cu-forth-and-back.exp @@ -0,0 +1,60 @@ +# 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 the cooked index reader can handle inter-CU references: +# - DIE1@CU1 -> DIE2@CU2 +# - DIE2@CU2 -> DIE3@CU1. + +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 label2 + + cu {} { + compile_unit {{language @DW_LANG_C}} { + subprogram { + {MACRO_AT_range { main }} + {DW_AT_specification %$label1} + } + + label2: subprogram { + {DW_AT_name main} + } + } + } + + cu {} { + compile_unit {{language @DW_LANG_C}} { + label1: subprogram { + {DW_AT_specification %$label2} + } + } + } +} + +if [prepare_for_testing "failed to prepare" $testfile \ + [list $asm_file $srcfile] {nodebug}] { + return -1 +} + +# Regression test for PR32081. +gdb_assert { ![regexp -nocase "error:" $gdb_file_cmd_msg] } "No Error message" |