diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 2f12ff15f0..d83ce81f9d 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,19 @@ +2020-03-13 Tom de Vries + + PR symtab/25646 + * psymtab.c (partial_symtab::partial_symtab): Don't set + globals_offset and statics_offset. Push element onto + current_global_psymbols and current_static_psymbols stacks. + (concat): New function. + (end_psymtab_common): Set globals_offset and statics_offset. Pop + element from current_global_psymbols and current_static_psymbols + stacks. Concat popped elements to global_psymbols and + static_symbols. + (add_psymbol_to_list): Use current_global_psymbols and + current_static_psymbols stacks. + * psymtab.h (class psymtab_storage): Add current_global_psymbols and + current_static_psymbols fields. + 2020-03-12 Christian Biesinger * corelow.c (sniff_core_bfd): Remove. diff --git a/gdb/psymtab.c b/gdb/psymtab.c index 93b7c77d1b..f77f6d5108 100644 --- a/gdb/psymtab.c +++ b/gdb/psymtab.c @@ -1490,8 +1490,20 @@ partial_symtab::partial_symtab (const char *filename, { set_text_low (textlow); set_text_high (raw_text_low ()); /* default */ - globals_offset = objfile->partial_symtabs->global_psymbols.size (); - statics_offset = objfile->partial_symtabs->static_psymbols.size (); + + auto *v1 = new std::vector; + objfile->partial_symtabs->current_global_psymbols.push_back (v1); + auto *v2 = new std::vector; + objfile->partial_symtabs->current_static_psymbols.push_back (v2); +} + +/* Concat vectors V1 and V2. */ + +static void +concat (std::vector *v1, std::vector *v2) +{ + v1->insert (v1->end (), v2->begin (), v2->end ()); + v2->clear (); } /* Perform "finishing up" operations of a partial symtab. */ @@ -1499,10 +1511,26 @@ partial_symtab::partial_symtab (const char *filename, void end_psymtab_common (struct objfile *objfile, struct partial_symtab *pst) { - pst->n_global_syms = (objfile->partial_symtabs->global_psymbols.size () - - pst->globals_offset); - pst->n_static_syms = (objfile->partial_symtabs->static_psymbols.size () - - pst->statics_offset); + pst->globals_offset = objfile->partial_symtabs->global_psymbols.size (); + pst->statics_offset = objfile->partial_symtabs->static_psymbols.size (); + + auto *current_global_psymbols + = objfile->partial_symtabs->current_global_psymbols.back (); + auto *current_static_psymbols + = objfile->partial_symtabs->current_static_psymbols.back (); + objfile->partial_symtabs->current_global_psymbols.pop_back (); + objfile->partial_symtabs->current_static_psymbols.pop_back (); + + pst->n_global_syms + = current_global_psymbols->size (); + pst->n_static_syms + = current_static_psymbols->size (); + + concat (&objfile->partial_symtabs->global_psymbols, current_global_psymbols); + concat (&objfile->partial_symtabs->static_psymbols, current_static_psymbols); + + delete current_global_psymbols; + delete current_static_psymbols; sort_pst_symbols (objfile, pst); } @@ -1621,8 +1649,8 @@ add_psymbol_to_list (gdb::string_view name, bool copy_name, /* Save pointer to partial symbol in psymtab, growing symtab if needed. */ std::vector *list = (where == psymbol_placement::STATIC - ? &objfile->partial_symtabs->static_psymbols - : &objfile->partial_symtabs->global_psymbols); + ? objfile->partial_symtabs->current_static_psymbols.back () + : objfile->partial_symtabs->current_global_psymbols.back ()); append_psymbol_to_list (list, psym, objfile); } diff --git a/gdb/psymtab.h b/gdb/psymtab.h index 040b973927..e8bafbe433 100644 --- a/gdb/psymtab.h +++ b/gdb/psymtab.h @@ -129,6 +129,12 @@ public: std::vector global_psymbols; std::vector static_psymbols; + /* Stack of vectors of partial symbols, using during psymtab + initialization. */ + + std::vector*> current_global_psymbols; + std::vector*> current_static_psymbols; + private: /* The obstack where allocations are made. This is lazily allocated diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog index 145e1e4913..97f891c99a 100644 --- a/gdb/testsuite/ChangeLog +++ b/gdb/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2020-03-13 Tom de Vries + + PR symtab/25646 + * gdb.dwarf2/imported-unit.exp: Add test. + 2020-03-13 Tom de Vries * gdb.mi/mi-sym-info-2.c (another_char_t, another_short_t): New typedef. diff --git a/gdb/testsuite/gdb.dwarf2/imported-unit.exp b/gdb/testsuite/gdb.dwarf2/imported-unit.exp index 2b50173bc6..80d6628357 100644 --- a/gdb/testsuite/gdb.dwarf2/imported-unit.exp +++ b/gdb/testsuite/gdb.dwarf2/imported-unit.exp @@ -149,6 +149,19 @@ if { [prepare_for_testing "failed to prepare" ${testfile} \ gdb_test_no_output "set language c++" +# Verify that the partial symtab for the unit importing the partial unit does +# not contain the static partial symbol int, which is defined in the partial +# unit. Test-case for PR25646. +gdb_test "main print psymbols" \ + [multi_line \ + " Depends on 1 other partial symtabs\." \ + "\[^\r\n\]*" \ + " Global partial symbols:" \ + " `main', function, $hex" \ + "" \ + ".*"] \ + "no static partial symbols in importing unit" + # Sanity check gdb_test "ptype main" "= int \\(void\\)"