diff options
author | Andrew Burgess <andrew.burgess@embecosm.com> | 2020-03-23 12:40:24 +0000 |
---|---|---|
committer | Andrew Burgess <andrew.burgess@embecosm.com> | 2020-04-02 17:44:03 +0100 |
commit | c90d28ac8903c5781b1a82e487072081383fd7b9 (patch) | |
tree | c736279b1f48a4eb01c1f43d866d84fbfb4ee3b5 /gdb/testsuite/gdb.opt/inline-small-func.exp | |
parent | 34e9a9fa0a18fc544bc8ec3dc9e02096be1e4335 (diff) | |
download | binutils-gdb-c90d28ac8903c5781b1a82e487072081383fd7b9.tar.gz |
gdb: Don't remove duplicate entries from the line table
In this commit:
commit 8c95582da858ac981f689a6f599acacb8c5c490f
Date: Mon Dec 30 21:04:51 2019 +0000
gdb: Add support for tracking the DWARF line table is-stmt field
A change was made in buildsym_compunit::record_line to remove
duplicate line table entries in some cases. This was an invalid
change, as these duplicate line table entries are used in _some_ cases
as part of prologue detection (see skip_prologue_using_sal).
It might be possible to identify those line table entries that are
required by skip_prologue_using_sal and only keep those duplicates
around, however, I have not done this here. The original duplicate
removal was done because (a) it was easy to implement, and (b) it
seemed obviously harmless.
As (b) is now known to be false, and implementation would be more
complex, and so (a) is also false. As such, it seems better to keep
all duplicates until an actual reason presents itself for why we
should remove any.
The original regression was spotted on RISC-V, which makes use of
skip_prologue_using_sal as part of riscv_skip_prologue. Originally I
created the test gdb.dwarf2/dw2-inline-small-func.exp, however, this
test will not compile on RISC-V as this target doesn't support
.uleb128 or .sleb128 assembler directives containing complex
expressions. As a result I added the gdb.opt/inline-small-func.exp
test, which exposes the bug on RISC-V, but obviously depends on the
compiler to produce specific DWARF information in order to expose the
bug. Still this test does ensure we always get the desired result,
even if the DWARF changes.
Originally the gdb.dwarf2/dw2-inline-small-func.exp test passed on
x86-64 even with the duplicate line table entries incorrectly
removed. The reason for this is that when a compilation unit doesn't
have a 'producer' string then skip_prologue_using_sal is not used,
instead the prologue is always skipped using analysis of the assembler
code.
However, for Clang on x86-64 skip_prologue_using_sal is used, so I
modified the gdb.dwarf2/dw2-inline-small-func.exp test to include a
'producer' string that names the Clang compiler. With this done the
test would fail on x86-64.
One thing to note is that the gdb.opt/inline-small-func.exp test might
fail on some targets. For example, if we compare sparc to risc-v by
looking at sparc32_skip_prologue we see that this function doesn't use
skip_prologue_using_sal, but instead uses find_pc_partial_function
directly. I don't know the full history behind why the code is like
it is, but it feels like sparc32_skip_prologue is an attempt to
duplicate some of the functionality of skip_prologue_using_sal, but
without all of the special cases. If this is true then the new test
could easily fail on this target, this would suggest that sparc should
consider switching to use skip_prologue_using_sal like risc-v does.
gdb/ChangeLog:
* buildsym.c (buildsym_compunit::record_line): Remove
deduplication code.
gdb/testsuite/ChangeLog:
* gdb.dwarf2/dw2-inline-small-func-lbls.c: New file.
* gdb.dwarf2/dw2-inline-small-func.c: New file.
* gdb.dwarf2/dw2-inline-small-func.exp: New file.
* gdb.dwarf2/dw2-inline-small-func.h: New file.
* gdb.opt/inline-small-func.c: New file.
* gdb.opt/inline-small-func.exp: New file.
* gdb.opt/inline-small-func.h: New file.
Diffstat (limited to 'gdb/testsuite/gdb.opt/inline-small-func.exp')
-rw-r--r-- | gdb/testsuite/gdb.opt/inline-small-func.exp | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/gdb/testsuite/gdb.opt/inline-small-func.exp b/gdb/testsuite/gdb.opt/inline-small-func.exp new file mode 100644 index 00000000000..dfe046ad723 --- /dev/null +++ b/gdb/testsuite/gdb.opt/inline-small-func.exp @@ -0,0 +1,60 @@ +# Copyright 2020 Free Software Foundation, Inc. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. + +# Check for an issue in GDB where buildsym_compunit::record_line was +# removing duplicate line table entries, but skip_prologue_using_sal +# depends on these duplicates to spot the end of the prologue. +# +# When the de-duplication was added this regression was not spotted as +# it requires a particular combination of a (very) small function +# being inlined into an also very small outer function. +# +# See also gdb.dwarf/dw2-inline-small-func.exp for a version of this +# test that makes use of the Dejagnu DWARF compiler. +# +# This test simply compiles with optimization and checks that GDB can +# do something suitable with the compiled binary. Problems with this +# test are most likely to occur when GDB asks the target specific code +# to skip the prologue (gdbarch_skip_prologue). Some targets make use +# of skip_prologue_using_sal, which should be fine, however, some +# targets make a poor attempt to duplicate parts of +# skip_prologue_using_sal, these targets could easily fail this test. +# This is not (necessarily) a problem with this test, but could +# indicate a weakness with the target in question. + +standard_testfile inline-small-func.c inline-small-func.h + +if { [prepare_for_testing "failed to prepare" ${testfile} \ + [list $srcfile] {debug optimize=-O1}] } { + return -1 +} + +if ![runto_main] { + return -1 +} + +# Delete all breakpoints so that the output of "info breakpoints" +# below will only contain a single breakpoint. +delete_breakpoints + +# Place a breakpoint within the function in the header file. +set linenum [gdb_get_line_number "callee: body" $srcfile2] +gdb_breakpoint "${srcfile2}:${linenum}" + +# Check that the breakpoint was placed where we expected. It should +# appear at the requested line. When the bug in GDB was present the +# breakpoint would be placed on one of the following lines instead. +gdb_test "info breakpoints" \ + ".* in callee at \[^\r\n\]+${srcfile2}:${linenum}\\y.*" |