]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commit - gdb/symtab.c
[gdb/symtab] Fix language of frame without debug info
authorTom de Vries <tdevries@suse.de>
Wed, 28 Oct 2020 20:04:12 +0000 (21:04 +0100)
committerTom de Vries <tdevries@suse.de>
Wed, 28 Oct 2020 20:04:12 +0000 (21:04 +0100)
commit1b00ef063f8230a1f110cc5aeef04d3dc1338358
tree14c95a9c02df46e515a30c21f0571e34e7c5fb4f
parentce04ca31231138105fae3b0dda1670c6ec0e2dcb
[gdb/symtab] Fix language of frame without debug info

On openSUSE Leap 15.2, I run into this FAIL with target board readnow and
test-case gdb.dwarf2/dw2-align.exp:
...
(gdb) set lang c++^M
Warning: the current language does not match this frame.^M
(gdb) FAIL: gdb.dwarf2/dw2-align.exp: set lang c++
...

Adding some extra debugging shows that the current language differs without
and with readnow:
...
 Breakpoint 1, 0x00000000004004ab in main ()^M
 (gdb) show lang^M
-The current source language is "auto; currently c".^M
+The current source language is "auto; currently asm".^M
...

This is explained by find_pc_compunit_symtab (0x4004ab) called from
select_frame, which:
- without readnow: returns NULL, and
- with readnow: returns the symtab for the CU crtn.S, wich has language
  "MIPS assembler".

In the former case, the symtab for crtn.S is not expanded, and
find_pc_compunit_symtab hits the default NULL return.  In the latter case, the
symtab for crtn.S is expanded, and the "best match" loop in
find_pc_compunit_symtab returns that symtab as its best match.

The GLOBAL_BLOCK for crtn.S has these outer limits of the address range:
...
(gdb) p /x b.startaddr
$6 = 0x4003c2
(gdb) p /x b.endaddr
$7 = 0x40053d
...
and 0x4004ab indeed fits in that range, which explains why the CU is
considered a match.

However, the actual address ranges for the CU are:
...
    00000040 ffffffffffffffff 0000000000000000 (base address)
    00000040 00000000004003c2 00000000004003c7
    00000040 0000000000400538 000000000040053d
    00000040 <End of list>
...
which confirms that the CU should not be considered a match.

The problem is that the "best match" loop is based on the assumption that a
symtab with a better match will be found, but in this case we don't find a
better match because there's no debug info describing main.

Fix this by preferring to use the addres map in the "best match" loop, which
will accurately tell us that addrmap_find (bv.map, 0x4004ab) == NULL.

Tested on x86_64-linux (that is, openSUSE Leap 15.2), with and without
readnow.  In the case of a readnow run, brings down the number of unexpected
failures from 66 to 38.

The FAIL does not reproduce on f.i. Ubuntu 18.04.5, because there the exec
does not contain debug info for crtn.S.  The dwarf assembly test-case mimics
the scenario described above, and reproduces the FAIL with and without
-readnow, for both mentioned OS configurations.

Also fixes PR25980 - "Overlapping Dwarf Compile Units with non-overlapping
subranges gives incorrect line information".

gdb/ChangeLog:

2020-10-28  Tom de Vries  <tdevries@suse.de>

PR symtab/26772
* symtab.c (find_pc_sect_compunit_symtab): In case there's an address
map, check it in the "best match" loop.

gdb/testsuite/ChangeLog:

2020-10-28  Tom de Vries  <tdevries@suse.de>

PR symtab/26772
* gdb.dwarf2/dw2-ranges-overlap.c: New test.
* gdb.dwarf2/dw2-ranges-overlap.exp: New file.
gdb/ChangeLog
gdb/symtab.c
gdb/testsuite/ChangeLog
gdb/testsuite/gdb.dwarf2/dw2-ranges-overlap.c [new file with mode: 0644]
gdb/testsuite/gdb.dwarf2/dw2-ranges-overlap.exp [new file with mode: 0644]