public inbox for gdb-prs@sourceware.org
help / color / mirror / Atom feed
* [Bug symtab/25941] New: [debug_names] Don't assume complete CU list
@ 2020-05-07 14:56 vries at gcc dot gnu.org
  2020-05-07 14:56 ` [Bug symtab/25941] " vries at gcc dot gnu.org
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: vries at gcc dot gnu.org @ 2020-05-07 14:56 UTC (permalink / raw)
  To: gdb-prs

https://sourceware.org/bugzilla/show_bug.cgi?id=25941

            Bug ID: 25941
           Summary: [debug_names] Don't assume complete CU list
           Product: gdb
           Version: HEAD
            Status: NEW
          Severity: normal
          Priority: P2
         Component: symtab
          Assignee: unassigned at sourceware dot org
          Reporter: vries at gcc dot gnu.org
  Target Milestone: ---

Consider the patch and test-case submitted in
https://sourceware.org/pipermail/gdb-patches/2020-May/168179.html .

That is, test-case test.c:
...
int
main (void)
{
 int sum,a,b;
 sum = a + b;
 return sum;
}
...

Compiled liked so:
...
$ clang-10 test.c -gdwarf-5 -o test.out -gpubnames 
..

Without patch, I have:
...
$ gdb \
    -batch -q \
    -iex "set auto-solib-add off" \
    test.out \
    -ex "set complaints 1" \
    -ex "start"

warning: Section .debug_aranges in /data/gdb_versions/devel/test.out entry at
offset 0 debug_info_offset 0 does not exists, ignoring .debug_aranges.
During symbol reading: Unsupported .debug_names form DW_FORM_ref4 [in module
/data/gdb_versions/devel/test.out]
Temporary breakpoint 1 at 0x4004a4
During symbol reading: Unsupported .debug_names form DW_FORM_ref4 [in module
/data/gdb_versions/devel/test.out]

Temporary breakpoint 1, 0x00000000004004a4 in main ()
...

With the patch, I have:
...
warning: Section .debug_aranges in /data/gdb_versions/devel/test.out entry at
offset 0 debug_info_offset 0 does not exists, ignoring .debug_aranges.
/data/gdb_versions/devel/src/gdb/dwarf2/read.c:6949: internal-error:
cutu_reader::cutu_reader(dwarf2_per_cu_data*, abbrev_table*, int, bool):
Assertion `this_cu->length == cu->header.get_length ()' failed.
A problem internal to GDB has been detected,
further debugging may prove unreliable.
...

I tracked the problem down to this. We have DWARF for a bunch of CUs:
...
$ llvm-dwarfdump test.out | grep "Compile Unit"
0x00000000: Compile Unit: length = 0x0000002a version = 0x0002 abbr_offset =
0x0000 addr_size = 0x08 (next unit at 0x0000002e)
0x0000002e: Compile Unit: length = 0x00000073 version = 0x0004 abbr_offset =
0x0014 addr_size = 0x08 (next unit at 0x000000a5)
0x000000a5: Compile Unit: length = 0x0000001e version = 0x0002 abbr_offset =
0x0052 addr_size = 0x08 (next unit at 0x000000c7)
0x000000c7: Compile Unit: length = 0x00000055 version = 0x0005 unit_type =
DW_UT_compile abbr_offset = 0x0064 addr_size = 0x08 (next unit at 0x00000120)
0x00000120: Compile Unit: length = 0x000001b4 version = 0x0004 abbr_offset =
0x00ad addr_size = 0x08 (next unit at 0x000002d8)
0x000002d8: Compile Unit: length = 0x0000001e version = 0x0002 abbr_offset =
0x01c5 addr_size = 0x08 (next unit at 0x000002fa)
...
but we only have the .debug_names index for the one at 0xc7:
...
.debug_names contents:
Name Index @ 0x0 {
  Header {
    Length: 0x6C
    Version: 5
    Padding: 0x0
    CU count: 1
    Local TU count: 0
    Foreign TU count: 0
    Bucket count: 2
    Name count: 2
    Abbreviations table size: 0xD
    Augmentation: 'LLVM0700'
  }
  Compilation Unit offsets [
    CU[0]: 0x000000c7
  ]
...

When creating the CUs from the .debug_names index in
create_cus_from_debug_names_list, we create the CU at 0xc7 with a size as if it
fills the rest of the .debug_info section (so, with size 0x2fa-0xc7).

The following patch fixes this:
...
diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index 0bb8135e09b..d4bde2d5576 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -5035,7 +5035,7 @@ create_cus_from_debug_names_list (struct
dwarf2_per_objfile *dwarf2_per_objfile,
                              map.dwarf5_byte_order));
        }
       else
-       sect_off_next = (sect_offset) section.size;
+       sect_off_next = sect_off_prev;
       if (i >= 1)
        {
          const ULONGEST length = sect_off_next - sect_off_prev;
@@ -6946,7 +6946,10 @@ cutu_reader::cutu_reader (struct dwarf2_per_cu_data
*this_cu,
                                                    rcuh_kind::COMPILE);

          gdb_assert (this_cu->sect_off == cu->header.sect_off);
-         gdb_assert (this_cu->length == cu->header.get_length ());
+         if (this_cu->length == 0)
+           this_cu->length = cu->header.get_length ();
+         else
+           gdb_assert (this_cu->length == cu->header.get_length ());
          this_cu->dwarf_version = cu->header.version;
        }
     }
...

With that patch, we have:
...
$ gdb -batch -q -iex "set auto-solib-add off" test.out -ex "set complaints 1"
-ex "start"

warning: Section .debug_aranges in /data/gdb_versions/devel/test.out entry at
offset 0 debug_info_offset 0 does not exists, ignoring .debug_aranges.
Temporary breakpoint 1 at 0x4004ab: file test.c, line 5.

Temporary breakpoint 1, main () at test.c:5
5        sum = a + b;
...

I looked at the .debug_aranges warning, and it triggers because the
.debug_aranges section contains one entry:
...
debug_aranges contents:
Address Range Header: length = 0x0000002c, version = 0x0002, cu_offset =
0x00000000, addr_size = 0x08, seg_size = 0x00
[0x00000000004003c0,  0x00000000004003eb)
...
which refers to the CU at offset 0, but the CU list only contains the one at
0xc7, so we fail to find it.

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug symtab/25941] [debug_names] Don't assume complete CU list
  2020-05-07 14:56 [Bug symtab/25941] New: [debug_names] Don't assume complete CU list vries at gcc dot gnu.org
@ 2020-05-07 14:56 ` vries at gcc dot gnu.org
  2020-05-10 10:45 ` vries at gcc dot gnu.org
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: vries at gcc dot gnu.org @ 2020-05-07 14:56 UTC (permalink / raw)
  To: gdb-prs

https://sourceware.org/bugzilla/show_bug.cgi?id=25941

Tom de Vries <vries at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |tromey at sourceware dot org

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug symtab/25941] [debug_names] Don't assume complete CU list
  2020-05-07 14:56 [Bug symtab/25941] New: [debug_names] Don't assume complete CU list vries at gcc dot gnu.org
  2020-05-07 14:56 ` [Bug symtab/25941] " vries at gcc dot gnu.org
@ 2020-05-10 10:45 ` vries at gcc dot gnu.org
  2020-05-11  9:12 ` vries at gcc dot gnu.org
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: vries at gcc dot gnu.org @ 2020-05-10 10:45 UTC (permalink / raw)
  To: gdb-prs

https://sourceware.org/bugzilla/show_bug.cgi?id=25941

--- Comment #1 from Tom de Vries <vries at gcc dot gnu.org> ---
Created attachment 12524
  --> https://sourceware.org/bugzilla/attachment.cgi?id=12524&action=edit
Patch with test-case that triggers assert on ubuntu

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug symtab/25941] [debug_names] Don't assume complete CU list
  2020-05-07 14:56 [Bug symtab/25941] New: [debug_names] Don't assume complete CU list vries at gcc dot gnu.org
  2020-05-07 14:56 ` [Bug symtab/25941] " vries at gcc dot gnu.org
  2020-05-10 10:45 ` vries at gcc dot gnu.org
@ 2020-05-11  9:12 ` vries at gcc dot gnu.org
  2020-05-11 13:03 ` cvs-commit at gcc dot gnu.org
  2020-05-11 13:06 ` vries at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: vries at gcc dot gnu.org @ 2020-05-11  9:12 UTC (permalink / raw)
  To: gdb-prs

https://sourceware.org/bugzilla/show_bug.cgi?id=25941

--- Comment #2 from Tom de Vries <vries at gcc dot gnu.org> ---
(In reply to Tom de Vries from comment #0)
> I looked at the .debug_aranges warning, and it triggers because the
> .debug_aranges section contains one entry:
> ...
> debug_aranges contents:
> Address Range Header: length = 0x0000002c, version = 0x0002, cu_offset =
> 0x00000000, addr_size = 0x08, seg_size = 0x00
> [0x00000000004003c0,  0x00000000004003eb)
> ...
> which refers to the CU at offset 0, but the CU list only contains the one at
> 0xc7, so we fail to find it.

Filed as PR25969.

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug symtab/25941] [debug_names] Don't assume complete CU list
  2020-05-07 14:56 [Bug symtab/25941] New: [debug_names] Don't assume complete CU list vries at gcc dot gnu.org
                   ` (2 preceding siblings ...)
  2020-05-11  9:12 ` vries at gcc dot gnu.org
@ 2020-05-11 13:03 ` cvs-commit at gcc dot gnu.org
  2020-05-11 13:06 ` vries at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2020-05-11 13:03 UTC (permalink / raw)
  To: gdb-prs

https://sourceware.org/bugzilla/show_bug.cgi?id=25941

--- Comment #3 from cvs-commit at gcc dot gnu.org <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Tom de Vries <vries@sourceware.org>:

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

commit 3ee6bb113afd87a408dd8551768d801d04556ffd
Author: Tom de Vries <tdevries@suse.de>
Date:   Mon May 11 15:03:54 2020 +0200

    [gdb/symtab] Fix incomplete CU list assert in .debug_names

    Consider the following two-file test-case:
    ...
    $ cat main.c
    extern int foo (void);

    int
    main (void)
    {
      int sum, a, b;
      sum = a + b + foo ();
      return sum;
    }
    $ cat foo.c
    int
    foo (void)
    {
      return 3;
    }
    ...

    Compiled like this:
    ...
    $ clang-10 -gdwarf-5 -gpubnames -c main.c
    $ clang-10 -gdwarf-5 -c foo.c
    $ clang-10 -gdwarf-5 -gpubnames main.o foo.o
    ...

    When loading this exec into gdb, we run into this assert:
    ...
    $ gdb a.out
    Reading symbols from a.out...

    warning: Section .debug_aranges in a.out entry at offset 0 \
      debug_info_offset 0 does not exists, ignoring .debug_aranges.
    src/gdb/dwarf2/read.c:6949: \
      internal-error: cutu_reader::cutu_reader(dwarf2_per_cu_data*, \
                                               abbrev_table*, int, bool): \
      Assertion `this_cu->length == cu->header.get_length ()' failed.
    ...

    The problem is that the determined length of the CU:
    ...
    (gdb) p /x this_cu->length
    $4 = 0x26a
    ...
    does not match the actual length:
    ...
    (gdb) p /x cu->header.get_length ()
    $5 = 0x59
    ...

    The length of the CU is determined in create_cus_from_debug_names_list, and
    set based on this list in the .debug_names section:
    ...
      Compilation Unit offsets [
        CU[0]: 0x000000c7
      ]
    ...
    and it is assumed that this is a complete list, so the size of the CU is
    calculated using the end of the .debug_section at 0x331, making it 0x331 -
    0xc7 == 0x26a.

    However, the CU list is not complete:
    ...
    $ llvm-dwarfdump -debug-info a.out \
      | grep "Compile Unit" \
      | sed 's/Compile Unit.*//'
    0x00000000:
    0x0000002e:
    0x000000a5:
    0x000000c7:
    0x00000120:
    0x00000157:
    0x0000030f:
    ...
    In particular, because the CU for foo.c is there at 0x120 (the rest of the
CUs
    is due to openSUSE having debug info for various linked in objects).

    Fix the assert by not assuming to know the length of CUs in
    create_cus_from_debug_names_list (if the .debug_names is not produced by
GDB),
    and setting it to 0, and setting it later to the actual length.

    Note that this does not fix the .debug_aranges warning, that's PR25969.

    Build and tested on x86_64-linux, with native and debug-names.

    gdb/ChangeLog:

    2020-05-11  Tom de Vries  <tdevries@suse.de>

            PR symtab/25941
            * dwarf2/read.c (create_cus_from_debug_names_list): Initialize CUs
            with length 0, if not gdb-produced.
            (cutu_reader::cutu_reader): Set CU length to actual length if 0.

    gdb/testsuite/ChangeLog:

    2020-05-11  Tom de Vries  <tdevries@suse.de>

            PR symtab/25941
            * gdb.dwarf2/clang-debug-names.exp.in: New include exp file,
factored
            out of ...
            * gdb.dwarf2/clang-debug-names.exp: ... here.
            * gdb.dwarf2/clang-debug-names-2.exp: New file.  Include
            clang-debug-names.exp.in.
            * gdb.dwarf2/clang-debug-names-2-foo.c: New test.
            * gdb.dwarf2/clang-debug-names-2.c: New test.

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug symtab/25941] [debug_names] Don't assume complete CU list
  2020-05-07 14:56 [Bug symtab/25941] New: [debug_names] Don't assume complete CU list vries at gcc dot gnu.org
                   ` (3 preceding siblings ...)
  2020-05-11 13:03 ` cvs-commit at gcc dot gnu.org
@ 2020-05-11 13:06 ` vries at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: vries at gcc dot gnu.org @ 2020-05-11 13:06 UTC (permalink / raw)
  To: gdb-prs

https://sourceware.org/bugzilla/show_bug.cgi?id=25941

Tom de Vries <vries at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |FIXED
             Status|NEW                         |RESOLVED

--- Comment #4 from Tom de Vries <vries at gcc dot gnu.org> ---
Patch with test-case committed, marking resolved-fixed.

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2020-05-11 13:06 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-07 14:56 [Bug symtab/25941] New: [debug_names] Don't assume complete CU list vries at gcc dot gnu.org
2020-05-07 14:56 ` [Bug symtab/25941] " vries at gcc dot gnu.org
2020-05-10 10:45 ` vries at gcc dot gnu.org
2020-05-11  9:12 ` vries at gcc dot gnu.org
2020-05-11 13:03 ` cvs-commit at gcc dot gnu.org
2020-05-11 13:06 ` vries at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).