diff options
author | Keith Seitz <keiths@redhat.com> | 2019-01-16 11:38:06 -0800 |
---|---|---|
committer | Keith Seitz <keiths@redhat.com> | 2019-01-16 11:38:06 -0800 |
commit | c24bdb023c8e1fa969d6eb945059fa8ed0d490c7 (patch) | |
tree | b8980f7864acb6e4725d60481a680b261d053232 /gdb/testsuite | |
parent | 1fea0d5379be553f9bcee7c50fba4cff00176d1b (diff) | |
download | gdb-c24bdb023c8e1fa969d6eb945059fa8ed0d490c7.zip gdb-c24bdb023c8e1fa969d6eb945059fa8ed0d490c7.tar.gz gdb-c24bdb023c8e1fa969d6eb945059fa8ed0d490c7.tar.bz2 |
Introduce dwarf2_cu::get_builder
This patch is an attempt to deal with a variety of bugs reported where
GDB segfaults attempting to access a dwarf2_cu's builder. In certain
circumstances, this builder can be NULL. This is especially common
when inheriting DIEs via inlined subroutines in other CUs. The test
case demonstrates one such situation reported by users. See gdb/23773,
rhbz1638798, and dups for other concrete examples.
The approach taken here is to save the ancestor CU into the dwarf2_cu of
all CUs with DIEs that are "imported." This can happen whenever
follow_die_offset and friends are called. This essentially introduces a
chain of CUs that caused the importation of a DIE from a CU. Whenever
a builder is requested of a CU that has none, the ancestors are searched
for the first one with a builder.
A design side effect of this is that the builder can now only be
accessed by getter and setter methods because the builder itself
is private.
The bulk of the patch is relatively mindless text conversion from
"cu->builder" to "cu->get_builder ()". I've included one test which
was derived from one (of the many) bugs reported on the issue in both
sourceware and Fedora bugzillas.
gdb/ChangeLog:
PR gdb/23773
* dwarf2read.c (dwarf2_cu) <ancestor>: New field.
<builder>: Rename to ..
<m_builder>: ... this and make private.
(dwarf2_cu::get_builder): New method. Change all users of
`builder' to use this method.
(dwarf2_start_symtab): Move to ...
(dwarf2_cu::start_symtab): ... here. Update all callers
(setup_type_unit_groups): Move to ...
(dwarf2_cu::setup_type_unit_groups): ... here. Update all
callers.
(dwarf2_cu::reset_builder): New method.
(process_full_compunit, process_full_type_unit): Use
dwarf2_cu::reset_builder.
(follow_die_offset): Record the ancestor CU if it is different
from the followed DIE's CU.
(follow_die_sig_1): Likewise.
gdb/testsuite/ChangeLog:
PR gdb/23773
* gdb.dwarf2/inlined_subroutine-inheritance.exp: New file.
Diffstat (limited to 'gdb/testsuite')
-rw-r--r-- | gdb/testsuite/ChangeLog | 5 | ||||
-rw-r--r-- | gdb/testsuite/gdb.dwarf2/inlined_subroutine-inheritance.exp | 213 |
2 files changed, 218 insertions, 0 deletions
diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog index af132ff..71afd41 100644 --- a/gdb/testsuite/ChangeLog +++ b/gdb/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2019-01-16 Keith Seitz <keiths@redhat.com> + + PR gdb/23773 + * gdb.dwarf2/inlined_subroutine-inheritance.exp: New file. + 2019-01-14 Pedro Franco de Carvalho <pedromfc@linux.ibm.com> * gdb.arch/vsx-regs.exp: Add tests that use the vector register diff --git a/gdb/testsuite/gdb.dwarf2/inlined_subroutine-inheritance.exp b/gdb/testsuite/gdb.dwarf2/inlined_subroutine-inheritance.exp new file mode 100644 index 0000000..4250e39 --- /dev/null +++ b/gdb/testsuite/gdb.dwarf2/inlined_subroutine-inheritance.exp @@ -0,0 +1,213 @@ +# Copyright 2018 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/>. + +# This tests a segfault that occurs when reading inlined_subroutine DIEs +# with abstract_origins pointing to DIEs in other CUs. +# +# See https://bugzilla.redhat.com/show_bug.cgi?id=1638798 . + +load_lib dwarf.exp + +# This test can only be run on targets which support DWARF. +if {![dwarf2_support]} { + return 0 +} + +standard_testfile main.c .S + +# Create the DWARF. This is derived from the reproducer in the Fedora +# bugzila mentioned above. For clarity, some "superfluous" DIES have +# been left instead of simplifying/pruning the test further. +set asm_file [standard_output_file $srcfile2] +Dwarf::assemble $asm_file { + declare_labels Db D72f8 D736e + declare_labels D266465 D266477 D266483 D266496 D266498 D266ad3 D266ad9 \ + D266ade D26b227 D26b237 + declare_labels D26d8b1 D26d8c3 D26d8cf D26d944 D26d946 D26e103 D26e145 \ + D26e415 D26e48c D26df00 D26df06 D26df0b D272519 D274c1a D274c42 + + cu {} { + Db: compile_unit { + {language @DW_LANG_C99} + {name "<artificial>"} + } { + D72f8: subprogram { + {abstract_origin :$D272519} + {low_pc 0xb9e20 addr} + {high_pc 0x1f5 data4} + } { + D736e: inlined_subroutine { + {abstract_origin :$D26b227} + {low_pc 0xb9efc addr} + {high_pc 0xc data4} + } { + formal_parameter { + {abstract_origin :$D274c42} + } + } + } + } + } + + cu {} { + D266465: compile_unit { + {language @DW_LANG_C99} + } { + D266477: typedef { + {name "size_t"} + {type :$D266483} + } + + D266483: base_type { + {byte_size 8 sdata} + {encoding @DW_ATE_unsigned} + } + + D266496: pointer_type { + {byte_size 8 sdata} + } + + D266498: restrict_type { + {type :$D266496} + } + + D266ad3: pointer_type { + {byte_size 8 sdata} + {type :$D266ade} + } + + D266ad9: restrict_type { + {type :$D266ad3} + } + + D266ade: const_type {} + + D26b227: subprogram { + {external 1 flag} + {name "memcpy"} + {type :$D266496} + } { + D26b237: formal_parameter { + {name "__dest"} + {type :$D266498} + } + formal_parameter { + {name "__src"} + {type :$D266ad9} + } + formal_parameter { + {name "__len"} + {type :$D266477} + } + } + } + } + + cu {} { + D26d8b1: compile_unit { + {language @DW_LANG_C99} + } { + D26d8c3: typedef { + {name "size_t"} + {type :$D26d8cf} + } + + D26d8cf: base_type { + {byte_size 8 sdata} + {encoding @DW_ATE_unsigned} + {name "long unsigned int"} + } + + D26d944: pointer_type { + {byte_size 8 sdata} + } + + D26d946: restrict_type { + {type :$D26d944} + } + + D26e103: structure_type { + {name "__object"} + {byte_size 12 sdata} + } { + member { + {name "__ob_next"} + {type :$D26e145} + {data_member_location 0 sdata} + } + } + + D26e145: pointer_type { + {byte_size 8 sdata} + {type :$D26e103} + } + + D26e415: typedef { + {name "PyObject"} + {type :$D26e103} + } + + D26e48c: pointer_type { + {byte_size 8 sdata} + {type :$D26e415} + } + + D26df00: pointer_type { + {byte_size 8 sdata} + {type :$D26df0b} + } + + D26df06: restrict_type { + {type :$D26df00} + } + + D26df0b: const_type {} + + D272519: subprogram { + {name "bytes_repeat"} + {type :$D26e48c} + } + + D274c1a: subprogram { + {external 1 flag} + {name "memcpy"} + {type :$D26d944} + } { + formal_parameter { + {name "__dest"} + {type :$D26d946} + } + formal_parameter { + {name "__src"} + {type :$D26df06} + } + D274c42: formal_parameter { + {name "__len"} + {type :$D26d8c3} + } + } + } + } +} + +if {[prepare_for_testing "failed to prepare" $testfile \ + "${asm_file} ${srcfile}" {}]} { + return -1 +} + +# All we need to do is set a breakpoint, which causes the DWARF +# info to be read, to demonstrate the problem. + +gdb_breakpoint "bytes_repeat" message |