offset_type cu_list_elements, types_list_elements, dwz_list_elements = 0;
struct dwz_file *dwz;
struct objfile *objfile = per_objfile->objfile;
+ dwarf2_per_bfd *per_bfd = per_objfile->per_bfd;
gdb::array_view<const gdb_byte> main_index_contents
- = get_gdb_index_contents (objfile, per_objfile->per_bfd);
+ = get_gdb_index_contents (objfile, per_bfd);
if (main_index_contents.empty ())
return 0;
/* If there is a .dwz file, read it so we can get its CU list as
well. */
- dwz = dwarf2_get_dwz_file (per_objfile->per_bfd);
+ dwz = dwarf2_get_dwz_file (per_bfd);
if (dwz != NULL)
{
struct mapped_index dwz_map;
}
}
- create_cus_from_index (per_objfile->per_bfd, cu_list, cu_list_elements,
- dwz_list, dwz_list_elements);
+ create_cus_from_index (per_bfd, cu_list, cu_list_elements, dwz_list,
+ dwz_list_elements);
if (types_list_elements)
{
/* We can only handle a single .debug_types when we have an
index. */
- if (per_objfile->per_bfd->types.size () != 1)
+ if (per_bfd->types.size () != 1)
return 0;
- dwarf2_section_info *section = &per_objfile->per_bfd->types[0];
+ dwarf2_section_info *section = &per_bfd->types[0];
- create_signatured_type_table_from_index (per_objfile->per_bfd,
- section, types_list,
+ create_signatured_type_table_from_index (per_bfd, section, types_list,
types_list_elements);
}
create_addrmap_from_index (per_objfile, map.get ());
- per_objfile->per_bfd->index_table = std::move (map);
- per_objfile->per_bfd->using_index = 1;
- per_objfile->per_bfd->quick_file_names_table =
- create_quick_file_names_table (per_objfile->per_bfd->all_comp_units.size ());
+ per_bfd->index_table = std::move (map);
+ per_bfd->using_index = 1;
+ per_bfd->quick_file_names_table =
+ create_quick_file_names_table (per_bfd->all_comp_units.size ());
+
+ /* Save partial symtabs in the per_bfd object, for the benefit of subsequent
+ objfiles using the same BFD. */
+ gdb_assert (per_bfd->partial_symtabs == nullptr);
+ per_bfd->partial_symtabs = objfile->partial_symtabs;
return 1;
}
std::unique_ptr<mapped_debug_names> map (new mapped_debug_names);
mapped_debug_names dwz_map;
struct objfile *objfile = per_objfile->objfile;
+ dwarf2_per_bfd *per_bfd = per_objfile->per_bfd;
if (!read_debug_names_from_section (objfile, objfile_name (objfile),
&per_objfile->per_bfd->debug_names, *map))
/* If there is a .dwz file, read it so we can get its CU list as
well. */
- dwz_file *dwz = dwarf2_get_dwz_file (per_objfile->per_bfd);
+ dwz_file *dwz = dwarf2_get_dwz_file (per_bfd);
if (dwz != NULL)
{
if (!read_debug_names_from_section (objfile,
}
}
- create_cus_from_debug_names (per_objfile->per_bfd, *map, dwz_map);
+ create_cus_from_debug_names (per_bfd, *map, dwz_map);
if (map->tu_count != 0)
{
/* We can only handle a single .debug_types when we have an
index. */
- if (per_objfile->per_bfd->types.size () != 1)
+ if (per_bfd->types.size () != 1)
return false;
- dwarf2_section_info *section = &per_objfile->per_bfd->types[0];
+ dwarf2_section_info *section = &per_bfd->types[0];
create_signatured_type_table_from_debug_names
- (per_objfile, *map, section, &per_objfile->per_bfd->abbrev);
+ (per_objfile, *map, section, &per_bfd->abbrev);
}
- create_addrmap_from_aranges (per_objfile,
- &per_objfile->per_bfd->debug_aranges);
+ create_addrmap_from_aranges (per_objfile, &per_bfd->debug_aranges);
- per_objfile->per_bfd->debug_names_table = std::move (map);
- per_objfile->per_bfd->using_index = 1;
- per_objfile->per_bfd->quick_file_names_table =
+ per_bfd->debug_names_table = std::move (map);
+ per_bfd->using_index = 1;
+ per_bfd->quick_file_names_table =
create_quick_file_names_table (per_objfile->per_bfd->all_comp_units.size ());
+ /* Save partial symtabs in the per_bfd object, for the benefit of subsequent
+ objfiles using the same BFD. */
+ gdb_assert (per_bfd->partial_symtabs == nullptr);
+ per_bfd->partial_symtabs = objfile->partial_symtabs;
+
return true;
}
if (per_bfd->debug_names_table != nullptr)
{
*index_kind = dw_index_kind::DEBUG_NAMES;
+ per_objfile->objfile->partial_symtabs = per_bfd->partial_symtabs;
per_objfile->resize_symtabs ();
return true;
}
if (per_bfd->index_table != nullptr)
{
*index_kind = dw_index_kind::GDB_INDEX;
+ per_objfile->objfile->partial_symtabs = per_bfd->partial_symtabs;
per_objfile->resize_symtabs ();
return true;
}
--- /dev/null
+# Copyright 2020 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/>.
+
+# Test that a backtrace is shown correctly for an objfile that uses partial
+# symtabs created by another objfile sharing the same BFD.
+#
+# It mimics how a bug with psymtab sharing was initially found:
+#
+# 1. Load the test file twice, such that the second objfile re-uses the
+# per_bfd object created for the first objfile.
+# 2. Run to some point where in the backtrace there is a frame for a
+# function that's in a CU that's not yet read in.
+# 3. Check that this frame's information is complete in the "backtrace"
+# output.
+
+standard_testfile .c share-psymtabs-bt-2.c
+
+if { [prepare_for_testing "failed to prepare" $testfile "$srcfile $srcfile2" \
+ {debug}] } {
+ untested "failed to compile"
+ return -1
+}
+
+# Load $binfile a second time. The second created objfile will re-use the
+# partial symtabs created by the first one.
+if { [gdb_file_cmd $binfile] != 0 } {
+ fail "file command failed"
+ return -1
+}
+
+gdb_breakpoint "bar"
+if { ![runto "bar"] } {
+ fail "failed to run to bar"
+ return -1
+}
+
+# A buggy GDB would fail to find the full symbol associated to this frame's
+# address, so would just show "foo ()" (from the minimal symbol).
+gdb_test "bt" "foo \\(x=12345\\).*"