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

Simon Marchi
2020-06-10T03:43:19Z

On 2020-06-04 2:04 p.m., Simon Marchi wrote:
> On 2020-06-04 1:55 p.m., Tom de Vries wrote:
>> I've also tested this with the gdb_cmd_file-twice patch with these two
>> target boards, and everything looks good.
>
> Thanks for testing.
>> [ FWIW, the gdb.base/index-cache.exp with the gdb_cmd_file-twice patch
>> and native is still there. ]
>
> I'll take a look at that now.

Just an update. I haven't had much time to take a look, but the problem seems simple.

The sequence of events is:

1. Load binary, create psymtabs, fill per-bfd
2. Because index-cache is on, generate index in the cache
3. Load binary a second time, in dwarf2_initialize_objfile we check: was an index
already loaded for this BFD? No, so we try to read the index and fill the per-bfd.
However, the per-bfd's comp units vector was already filled when creating psymtabs.
The assert is there because it doesn't make sense to read an index for a per_bfd
that already has comp units, it means either some psymtabs were created for it or
another index was already read.

So this is a situation I hadn't accounted for: a BFD for which we have built the partial
symtabs the first time, but has an index the second time. We probably just need a check
for psymtabs in dwarf2_initialize_objfile, something like the patch below. I included
the change to lib/gdb.exp just to make it easier to test / reproduce the issue, but it
won't be included in the final patch, a proper test will be included instead.

From a3d0d98961fb26fa8582efeb0f078e6231269380 Mon Sep 17 00:00:00 2001
From: Simon Marchi <simon.marchi@polymtl.ca>
Date: Tue, 9 Jun 2020 23:38:00 -0400
Subject: [PATCH] gdb: fix loading file twice with index-cache on

Change-Id: I458c6f05abb1a05fd3d177e9c9002225e0deee0c
---
gdb/dwarf2/read.c | 7 +++++++
gdb/testsuite/lib/gdb.exp | 7 ++++++-
2 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index 97d1771a6295..27ce9092cd31 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -5997,6 +5997,13 @@ dwarf2_initialize_objfile (struct objfile *objfile, dw_index_kind *index_kind)
return true;
}

+ if (per_bfd->partial_symtabs != nullptr)
+ {
+ /* Partial symbols were already read, the objfile/per_objfile
+ initialization will be completed in dwarf2_build_psymtabs. */
+ return false;
+ }
+
if (dwarf2_read_debug_names (per_objfile))
{
*index_kind = dw_index_kind::DEBUG_NAMES;
diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp
index 9a0620a2bf18..103e883ed417 100644
--- a/gdb/testsuite/lib/gdb.exp
+++ b/gdb/testsuite/lib/gdb.exp
@@ -4820,7 +4820,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
}
--
2.27.0