Re: [PATCH v2 00/42] Share DWARF partial symtabs between objfiles

Simon Marchi
2020-05-31T04:16:53Z

On 2020-05-29 6:23 a.m., Tom de Vries wrote:
> Seeing the repetition of file command in the cmd.gdb file (and how
> commenting out one of them made the test pass), I started suspecting
> this patch series, and wondered if I could reproduce the same or similar
> problems on master using a test-suite hack:
> ...
> diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp
> index 444cea01c3..fa2a999525 100644
> --- a/gdb/testsuite/lib/gdb.exp
> +++ b/gdb/testsuite/lib/gdb.exp
> @@ -4823,7 +4823,12 @@ proc gdb_load_shlib { file } {
> #
> proc gdb_load { arg } {
> if { $arg != "" } {
> - return [gdb_file_cmd $arg]
> + set res [gdb_file_cmd $arg]
> + if { $res != 0 } {
> + return $res
> + }
> + set res [gdb_file_cmd $arg]
> + return $res
> }
> return 0
> }
> ...
>
> And indeed, quite a few failures showed up. I picked one:
> gdb.base/langs.exp.
>
> So, on master, after this patch series, with target board
> cc-with-gdb-index, we have:
> ...
> Running /data/gdb_versions/devel/src/gdb/testsuite/gdb.base/langs.exp ...
> FAIL: gdb.base/langs.exp: up to foo in langs.exp
> FAIL: gdb.base/langs.exp: show language at foo in langs.exp
> FAIL: gdb.base/langs.exp: up to cppsub_ in langs.exp
> FAIL: gdb.base/langs.exp: show language at cppsub_ in langs.exp
> FAIL: gdb.base/langs.exp: up to fsub in langs.exp
> FAIL: gdb.base/langs.exp: show language at fsub in langs.exp

I'm looking at this failure right now because it's easier to tackle. I think I
see the problem. In the index case, we never set per_bfd->partial_symtabs, like
we do at the end of dwarf2_build_psymtabs for the non-index case. Then, for the
second objfile using the same BFD, we never take that per_bfd->partial_symtabs
to install it in objfile->partial_symtabs, like we do in the beginning of
dwarf2_build_psymtabs. So objfile->partial_symtabs->psymtabs_addrmap stays NULL,
and all pc -> symbol lookups fail.

See this proof of concept fix, which sets per_bfd->partial_symtabs in
dwarf2_read_gdb_index (when parsing the first objfile), and reads it back
in dwarf2_initialize_objfile (when parsing the second objfile).

The same will need to be done for debug_names.

From d5334c2c61408c4cd815eb54898f442502d5fd66 Mon Sep 17 00:00:00 2001
From: Simon Marchi <simon.marchi@efficios.com>
Date: Sun, 31 May 2020 00:10:33 -0400
Subject: [PATCH] the fix

---
gdb/dwarf2/read.c | 5 +++++
1 file changed, 5 insertions(+)

diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index 4724738363b..85fd41745f4 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -3068,6 +3068,7 @@ dwarf2_read_gdb_index
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);
@@ -3138,6 +3139,9 @@ dwarf2_read_gdb_index
per_objfile->per_bfd->quick_file_names_table =
create_quick_file_names_table (per_objfile->per_bfd->all_comp_units.size ());

+ gdb_assert (per_bfd->partial_symtabs == nullptr);
+ per_bfd->partial_symtabs = objfile->partial_symtabs;
+
return 1;
}

@@ -5981,6 +5985,7 @@ dwarf2_initialize_objfile (struct objfile *objfile, dw_index_kind *index_kind)
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;
}
--
2.26.2