Bug 25801 - Filename of shared psymtab is ignored
Summary: Filename of shared psymtab is ignored
Status: RESOLVED FIXED
Alias: None
Product: gdb
Classification: Unclassified
Component: symtab (show other bugs)
Version: HEAD
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-04-08 09:01 UTC by Tom de Vries
Modified: 2020-04-22 06:24 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Tom de Vries 2020-04-08 09:01:31 UTC
Consider test-case gdb.ada/dgopt.exp.

The test-case uses gnatmake option -gnatDG, which translates to:
...
-gnatD
    Create expanded source files for source level debugging. This switch also suppresses generation of cross-reference information (see -gnatx). Note that this switch is not allowed if a previous -gnatR switch has been given, since these two switches are not compatible. 

-gnateG
    Save result of preprocessing in a text file. 
...

This causes the file x.adb to be expanded into x.adb.dg, which is then compiled.

The effect of this is described in the .exp file:
...
# the
# .adb file did not end up in the file table, but did show up in the
# DWARF
...

We can confirm this by looking at the DWARF:
...
 <0><7f1>: Abbrev Number: 1 (DW_TAG_compile_unit)
    <7f7>   DW_AT_name        : gdb/testsuite/gdb.ada/dgopt/x.adb
...
with corresponding file table:
...
 The File Name Table (offset 0x1ce):
  Entry Dir     Time    Size    Name
  1     0       0       0       x.adb.dg
...

With gcc-7, and target board unix/-flto/-O0/-flto-partition=none/-ffat-lto-objects, we run into:
...
(gdb) list x.adb:16, 16^M
No source file named x.adb.^M
(gdb) FAIL: gdb.ada/dgopt.exp: list x.adb:16, 16
...
because the corresponding CU has been renamed to <artificial>:
...
 <0><d2>: Abbrev Number: 1 (DW_TAG_compile_unit)
    <d8>   DW_AT_name        : <artificial>
...

This FAIL is fixed in gcc-8, gcc-9 and gcc-10, where we have instead:
...
 <0><15a5>: Abbrev Number: 1 (DW_TAG_compile_unit)
    <15ab>   DW_AT_name        : <artificial>
 <1><15c7>: Abbrev Number: 2 (DW_TAG_imported_unit)
    <15c8>   DW_AT_import      : <0x15ef>       [Abbrev Number: 1]
 <0><15ef>: Abbrev Number: 1 (DW_TAG_compile_unit)
    <15f5>   DW_AT_name        : gdb/testsuite/gdb.ada/dgopt/x.adb
...

However, with the tentative fix for PR25700 at PR25700 comment 3, we again run into:
...
(gdb) list x.adb:16, 16^M
No source file named x.adb.^M
(gdb) FAIL: gdb.ada/dgopt.exp: list x.adb:16, 16
...
which we can fix by using -readnow.

The explanation is that without the tentative fix for PR25700, we have an unshared psymtab:
...
  { psymtab gdb/testsuite/gdb.ada/dgopt/x.adb ((struct partial_symtab *) 0x37e3600)^M
    readin no^M
    fullname (null)^M
    text addresses 0x0 -- 0x0^M
    psymtabs_addrmap_supported yes^M
    globals (none)^M
    statics (none)^M
    dependencies (none)^M
  }^M
...
and a shared psymtab (with user test):
...
  { psymtab gdb/testsuite/gdb.ada/dgopt/x.adb ((struct partial_symtab *) 0x36d56f0)^M
    readin no^M
    fullname (null)^M
    text addresses 0x0 -- 0x0^M
    psymtabs_addrmap_supported yes^M
    globals (none)^M
    statics (none)^M
    user <artificial>@0x159a ((struct partial_symtab *) 0x37b57c0)^M
    dependencies (none)^M
  }^M
...

The tentative fix for PR25700 removes the unshared psymtab.

Then when trying to find a psymtab matching x.adb in psym_map_symtabs_matching_filename, we run into this continue for the shared psymtab:
...
  for (partial_symtab *pst : require_partial_symbols (objfile, true))
    {
      /* We can skip shared psymtabs here, because any file name will be
        attached to the unshared psymtab.  */
      if (pst->user != NULL)
       continue;
...
and consequently cannot find the file.
Comment 1 Tom de Vries 2020-04-08 09:03:09 UTC
This tentative patch fixes things:
...
diff --git a/gdb/psymtab.c b/gdb/psymtab.c
index d952f453d9..5e4e7d116f 100644
--- a/gdb/psymtab.c
+++ b/gdb/psymtab.c
@@ -157,17 +157,15 @@ psym_map_symtabs_matching_filename
 
   for (partial_symtab *pst : require_partial_symbols (objfile, true))
     {
-      /* We can skip shared psymtabs here, because any file name will be
-        attached to the unshared psymtab.  */
-      if (pst->user != NULL)
-       continue;
-
       /* Anonymous psymtabs don't have a file name.  */
       if (pst->anonymous)
        continue;
 
       if (compare_filenames_for_search (pst->filename, name))
        {
+         while (pst->user)
+           pst = pst->user;
+
          if (partial_map_expand_apply (objfile, name, real_path,
                                        pst, callback))
            return true;
...
Comment 2 Tom de Vries 2020-04-08 11:04:04 UTC
Submitted patch: https://sourceware.org/pipermail/gdb-patches/2020-April/167452.html
Comment 3 Lucille F. Parham 2020-04-15 07:18:56 UTC Comment hidden (spam)
Comment 4 Sourceware Commits 2020-04-22 06:24:16 UTC
The master branch has been updated by Tom de Vries <vries@sourceware.org>:

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=eea9e35758138f83e8c44e0e5a5e47e351f8f31a

commit eea9e35758138f83e8c44e0e5a5e47e351f8f31a
Author: Tom de Vries <tdevries@suse.de>
Date:   Wed Apr 22 08:24:11 2020 +0200

    [gdb/symtab] Find filename in shared psymtab
    
    When running test-case gdb.ada/dgopt.exp with target board
    unix/-flto/-O0/-flto-partition=none/-ffat-lto-objects and gcc-8, gcc-9 or
    gcc-10, and the fix for PR25700, we run into this regression:
    ...
    (gdb) list x.adb:16, 16^M
    No source file named x.adb.^M
    (gdb) FAIL: gdb.ada/dgopt.exp: list x.adb:16, 16
    ...
    
    The reason for the failure is that without the fix for PR25700, we
    have an unshared psymtab:
    ...
      { psymtab gdb.ada/dgopt/x.adb ((struct partial_symtab *) $hex)^M
        readin no^M
        fullname (null)^M
        text addresses 0x0 -- 0x0^M
        psymtabs_addrmap_supported yes^M
        globals (none)^M
        statics (none)^M
        dependencies (none)^M
      }^M
    ...
    and a shared psymtab (with user field set):
    ...
      { psymtab gdb.ada/dgopt/x.adb ((struct partial_symtab *) $hex)^M
        readin no^M
        fullname (null)^M
        text addresses 0x0 -- 0x0^M
        psymtabs_addrmap_supported yes^M
        globals (none)^M
        statics (none)^M
        user <artificial>@0x159a ((struct partial_symtab *) 0x37b57c0)^M
        dependencies (none)^M
      }^M
    ...
    
    The fix for PR25700 removes the unshared psymtab.
    
    Then when trying to find a psymtab matching x.adb in
    psym_map_symtabs_matching_filename, we run into this continue for the shared
    psymtab:
    ...
      for (partial_symtab *pst : require_partial_symbols (objfile, true))
        {
          /* We can skip shared psymtabs here, because any file name will be
            attached to the unshared psymtab.  */
          if (pst->user != NULL)
           continue;
    ...
    and consequently cannot find the file.
    
    Fix this by not skipping the shared symtab in
    psym_map_symtabs_matching_filename.
    
    Build and reg-tested on x86_64-linux.
    
    gdb/ChangeLog:
    
    2020-04-22  Tom de Vries  <tdevries@suse.de>
    
            PR symtab/25801
            * psymtab.c (psym_map_symtabs_matching_filename): Don't skip shared
            symtabs.
    
    gdb/testsuite/ChangeLog:
    
    2020-04-22  Tom de Vries  <tdevries@suse.de>
    
            PR symtab/25801
            * gdb.dwarf2/imported-unit.exp: Test that we can get imported_unit.c
            in "info source" output.
Comment 5 Tom de Vries 2020-04-22 06:24:58 UTC
Patch with test-case committed, marking resolved-fixed.