binutils-gdb/gdb/testsuite/gdb.dwarf2
Tom de Vries 6848938272 [gdb/symtab] Fix segfault on invalid debug info
While looking at PR symtab/31478 (a problem in the cooked indexer with invalid
dwarf) it occurred to me that I could trigger a similar problem using:
...
  Compilation Unit @ offset 0xb2:
   Length:        0x1f (32-bit)
   Version:       4
   Abbrev Offset: 0x6c
   Pointer Size:  8
 <0><bd>: Abbrev Number: 1 (DW_TAG_compile_unit)
    <be>   DW_AT_language    : 2	(non-ANSI C)
 <1><bf>: Abbrev Number: 2 (DW_TAG_subprogram)
    <c0>   DW_AT_low_pc      : 0x4004a7
    <c8>   DW_AT_high_pc     : 0x4004b2
    <d0>   DW_AT_specification: <0xd5>
 <1><d4>: Abbrev Number: 0
  Compilation Unit @ offset 0xd5:
   Length:        0x7 (32-bit)
   Version:       4
   Abbrev Offset: 0x7f
   Pointer Size:  8
...
and indeed I get:
...
$ gdb -q -batch outputs/gdb.dwarf2/dw2-inter-cu-error-2/dw2-inter-cu-error-2

Fatal signal: Segmentation fault
...

The problem is that we're calling prepare_one_comp_unit with cu == nullptr and
comp_unit_die == nullptr here in cooked_indexer::ensure_cu_exists:
...
      cutu_reader new_reader (per_cu, per_objfile, nullptr, nullptr, false,
                              m_index_storage->get_abbrev_cache ());

      prepare_one_comp_unit (new_reader.cu, new_reader.comp_unit_die,
                             language_minimal);
...

Fix this by bailing out for various types of dummy CUs:
...
      if (new_reader.dummy_p || new_reader.comp_unit_die == nullptr
	  || !new_reader.comp_unit_die->has_children)
	return nullptr;
...

Also make sure in scan_attributes that this triggers a dwarf error:
...
$ gdb -q -batch dw2-inter-cu-error-2
DWARF Error: cannot follow reference to DIE at 0xd5 \
  [in module dw2-inter-cu-error-2]
...

With target board readnow, the test-case triggers an assertion failure in
follow_die_offset, so fix this by throwing the same dwarf error.

While we're at it, make the other check for dummy CUs in
cooked_indexer::ensure_cu_exists more robust by adding an intermediate test
for comp_unit_die:
...
-  if (result->dummy_p || !result->comp_unit_die->has_children)
+  if (result->dummy_p || result->comp_unit_die == nullptr
+      || !result->comp_unit_die->has_children)
     return nullptr;
...

Tested on x86_64-linux.

Approved-By: Tom Tromey <tom@tromey.com>
2024-09-24 10:50:44 +02:00
..
_start.c
ada-cold-name.exp
ada-linkage-name.c
ada-linkage-name.exp
ada-thick-pointer.exp
ada-valprint-error.c
ada-valprint-error.exp
anon-ns-fn.cc
anon-ns-fn.exp
arr-opt-out.c
arr-opt-out.exp
arr-stride.exp
arr-subrange.exp
assign-variable-value-to-register.exp
atomic-type.c
atomic-type.exp
backward-spec-inter-cu.exp
bad-regnum.exp
bitfield-parent-optimized-out.exp
break-inline-psymtab-2.c
break-inline-psymtab.c
break-inline-psymtab.exp
callframecfa.exp
callframecfa.S
calling-convention.c
calling-convention.exp
clang-cli-macro.c
clang-cli-macro.exp
clztest.c
clztest.exp
clztest.S
comp-unit-lang.c
comp-unit-lang.exp
corrupt.exp
count.exp [gdb/testsuite] Drop -readnow in three gdb.dwarf2 test-cases 2024-09-21 05:55:18 +02:00
cpp-linkage-name.c
cpp-linkage-name.exp
cu-no-addrs.exp
data-loc.c
data-loc.exp
debug-aranges-duplicate-offset-warning.c
debug-aranges-duplicate-offset-warning.exp
debug-names-bad-cu-index.exp
debug-names-duplicate-cu.exp
debug-names-missing-cu.exp
debug-names-non-ascending-cu.exp
debug-names-tu-dwarf5.exp
debug-names-tu.exp
debug-names-tu.exp.tcl
debug-names.exp
dup-psym.exp
dup-psym.S
dw2-abs-hi-pc-hello-dbg.S
dw2-abs-hi-pc-hello.c
dw2-abs-hi-pc-world-dbg.S
dw2-abs-hi-pc-world.c
dw2-abs-hi-pc.c
dw2-abs-hi-pc.exp
dw2-ada-ffffffff.exp
dw2-ada-ffffffff.S
dw2-align.exp
dw2-anon-mptr.exp
dw2-anon-mptr.S
dw2-anonymous-func.exp
dw2-anonymous-func.S
dw2-bad-elf-other.S
dw2-bad-elf.exp
dw2-bad-mips-linkage-name.c
dw2-bad-mips-linkage-name.exp
dw2-bad-parameter-type.exp [gdb/symtab] Change DWARF_ERROR from Dwarf Error to DWARF Error 2024-08-27 09:08:41 +02:00
dw2-bad-parameter-type.S
dw2-bad-unresolved.c
dw2-bad-unresolved.exp
dw2-basic.exp
dw2-basic.S
dw2-bfloat16.c
dw2-bfloat16.exp
dw2-canonicalize-type.exp
dw2-canonicalize-type.S
dw2-case-insensitive-debug.S
dw2-case-insensitive.c
dw2-case-insensitive.exp
dw2-common-block.exp
dw2-common-block.S
dw2-compdir-oldgcc.exp
dw2-compdir-oldgcc.S
dw2-complex-parts.exp
dw2-compressed.exp
dw2-compressed.S
dw2-const.exp
dw2-const.S
dw2-cp-infcall-ref-static-main.c
dw2-cp-infcall-ref-static.exp
dw2-cp-infcall-ref-static.S
dw2-cu-size.exp
dw2-cu-size.S
dw2-dir-file-name.c
dw2-dir-file-name.exp
dw2-disasm-over-non-stmt.exp
dw2-dos-drive.exp
dw2-dos-drive.S
dw2-double-set-die-type.exp
dw2-double-set-die-type.S
dw2-dummy-cu.exp
dw2-dummy-cu.S
dw2-dup-frame.c
dw2-dup-frame.exp
dw2-dup-frame.S
dw2-empty-file-name.exp
dw2-empty-namespace.exp
dw2-empty-namespace.S
dw2-empty-pc-range.exp
dw2-empty-pc-range.S
dw2-entry-points.c
dw2-entry-points.exp
dw2-entry-value-main.c
dw2-entry-value.exp
dw2-entry-value.S
dw2-epilogue-begin-2.exp
dw2-epilogue-begin.c
dw2-epilogue-begin.c.inc
dw2-epilogue-begin.exp
dw2-epilogue-begin.exp.tcl
dw2-error.c
dw2-error.exp [gdb/symtab] Change DWARF_ERROR from Dwarf Error to DWARF Error 2024-08-27 09:08:41 +02:00
dw2-error.S
dw2-filename.exp
dw2-filename.S
dw2-fixed-point.c [gdb/testsuite] Fix gdb.dwarf2/dw2-fixed-point.exp on arm-linux 2024-08-16 14:22:46 +02:00
dw2-fixed-point.exp
dw2-gas-workaround.exp
dw2-icc-opaque.exp
dw2-icc-opaque.S
dw2-icycle.exp
dw2-icycle.S
dw2-ifort-parameter.c
dw2-ifort-parameter.exp
dw2-inheritance.exp
dw2-inheritance.S
dw2-inline-break.exp
dw2-inline-break.S
dw2-inline-header-1.exp
dw2-inline-header-2.exp
dw2-inline-header-3.exp
dw2-inline-header-lbls.c
dw2-inline-header.c
dw2-inline-header.h
dw2-inline-many-frames.c
dw2-inline-many-frames.exp
dw2-inline-param-main.c
dw2-inline-param.exp
dw2-inline-param.S
dw2-inline-small-func-lbls.c
dw2-inline-small-func.c
dw2-inline-small-func.exp
dw2-inline-small-func.h
dw2-inline-stepping.c
dw2-inline-stepping.exp
dw2-inline-with-lexical-scope.c
dw2-inline-with-lexical-scope.exp
dw2-inter-cu-error-2.exp [gdb/symtab] Fix segfault on invalid debug info 2024-09-24 10:50:44 +02:00
dw2-inter-cu-error.exp [gdb/testsuite] Fix regexp in gdb.dwarf2/dw2-inter-cu-error.exp 2024-08-27 11:49:34 +02:00
dw2-inter-cu-forth-and-back.exp [gdb/symtab] Return correct reader for top-level CU in cooked_indexer::ensure_cu_exists 2024-08-22 10:00:27 +02:00
dw2-intercu.exp
dw2-intercu.S
dw2-intermix.exp
dw2-intermix.S
dw2-is-stmt-2.c
dw2-is-stmt-2.exp
dw2-is-stmt.c
dw2-is-stmt.exp
dw2-lexical-block-bare.exp
dw2-line-number-zero.c
dw2-line-number-zero.exp [gdb/testsuite] Fix gdb.dwarf2/dw2-lines.exp on arm-linux 2024-09-04 10:07:19 +02:00
dw2-lines.c [gdb/testsuite] Fix gdb.dwarf2/dw2-lines.exp on arm-linux 2024-09-04 10:07:19 +02:00
dw2-lines.exp [gdb/testsuite] Fix gdb.dwarf2/dw2-lines.exp on arm-linux 2024-09-04 10:07:19 +02:00
dw2-linkage-name-trust-main.cc
dw2-linkage-name-trust.exp
dw2-linkage-name-trust.S
dw2-main-no-line-number.exp
dw2-minsym-in-cu.exp
dw2-minsym-in-cu.S
dw2-missing-cu-tag.c
dw2-missing-cu-tag.exp [gdb/symtab] Change DWARF_ERROR from Dwarf Error to DWARF Error 2024-08-27 09:08:41 +02:00
dw2-modula2-self-type.exp
dw2-modula2-self-type.S
dw2-namespaceless-anonymous.c
dw2-namespaceless-anonymous.exp
dw2-no-code-cu.c
dw2-no-code-cu.exp
dw2-noloc.c
dw2-noloc.exp
dw2-objfile-overlap-inner.S
dw2-objfile-overlap-outer.S
dw2-objfile-overlap.exp
dw2-op-call.exp
dw2-op-call.S
dw2-op-out-param.exp
dw2-op-out-param.S
dw2-op-stack-value.exp
dw2-op-stack-value.S
dw2-opt-structptr.c
dw2-opt-structptr.exp
dw2-out-of-range-end-of-seq.exp
dw2-param-error-main.c
dw2-param-error.exp
dw2-param-error.S
dw2-producer.exp
dw2-producer.S
dw2-prologue-end-2.c
dw2-prologue-end-2.exp
dw2-prologue-end.c
dw2-prologue-end.exp
dw2-ranges-2.c
dw2-ranges-3.c
dw2-ranges-base.c
dw2-ranges-base.exp
dw2-ranges-func-hi-cold.c
dw2-ranges-func-lo-cold.c
dw2-ranges-func.exp
dw2-ranges-overlap.c
dw2-ranges-overlap.exp
dw2-ranges-psym-warning-main.c
dw2-ranges-psym-warning.c
dw2-ranges-psym-warning.exp
dw2-ranges-psym.c
dw2-ranges-psym.exp
dw2-ranges.c
dw2-ranges.exp
dw2-ref-missing-frame-func.c
dw2-ref-missing-frame-main.c
dw2-ref-missing-frame.exp
dw2-ref-missing-frame.S
dw2-reg-undefined.c
dw2-reg-undefined.exp
dw2-reg-undefined.S
dw2-regno-invalid.exp
dw2-restore.exp
dw2-restore.S
dw2-restrict.c
dw2-restrict.exp
dw2-restrict.S
dw2-simple-locdesc.exp
dw2-simple-locdesc.S
dw2-single-line-discriminators.c
dw2-single-line-discriminators.exp
dw2-single-line-discriminators.S
dw2-skip-prologue.c
dw2-skip-prologue.exp
dw2-skip-prologue.S
dw2-stack-boundary.exp
dw2-stack-boundary.S
dw2-step-out-of-function-no-stmt.c
dw2-step-out-of-function-no-stmt.exp
dw2-strp.exp
dw2-strp.S
dw2-symtab-includes-lookup.exp
dw2-symtab-includes.exp
dw2-undefined-ret-addr.c
dw2-undefined-ret-addr.exp
dw2-undefined-ret-addr.S
dw2-unresolved-main.c
dw2-unresolved.exp
dw2-unresolved.S
dw2-unspecified-type-foo.c
dw2-unspecified-type.c
dw2-unspecified-type.exp
dw2-unusual-field-names.c
dw2-unusual-field-names.exp
dw2-using-debug-str.c
dw2-using-debug-str.exp [gdb/symtab] Change DWARF_ERROR from Dwarf Error to DWARF Error 2024-08-27 09:08:41 +02:00
dw2-var-zero-addr.exp
dw2-var-zero-addr.S
dw2-vendor-extended-opcode.c
dw2-vendor-extended-opcode.exp
dw2-weird-type-len.c
dw2-weird-type-len.exp
dw2-wrong-mangled-name.c
dw2-wrong-mangled-name.exp
dw2-zero-range-shlib.c
dw2-zero-range.c
dw2-zero-range.exp
dw4-sig-type-unused.exp
dw4-sig-type-unused.S
dw4-sig-types-b.cc
dw4-sig-types.cc
dw4-sig-types.exp
dw4-sig-types.h
dw4-toplevel-types.cc
dw4-toplevel-types.exp
dw5-rnglist-test.cc
dw5-rnglist-test.exp
DW_OP_piece_with_DW_OP_GNU_uninit.exp
dwp-sepdebug.c
dwp-sepdebug.exp
dwp-symlink.c
dwp-symlink.exp
dwz-unused-pu.exp [gdb/testsuite] Add gdb.dwarf2/dwz-unused-pu.exp 2024-09-24 10:32:41 +02:00
dwz.exp
dwzbuildid.exp
dwznolink.exp
dyn-type-unallocated.c
dyn-type-unallocated.exp
dynarr-ptr.c
dynarr-ptr.exp
enqueued-cu-base-addr.exp
entry-value-typedef-aarch64.S
entry-value-typedef-amd64.S
entry-value-typedef.cpp
entry-value-typedef.exp
enum-type-c++.cc [gdb/testsuite] Add regression test for PR32158 2024-09-14 14:09:35 +02:00
enum-type-c++.exp [gdb/symtab] Revert "Change handling of DW_TAG_enumeration_type in DWARF scanner" 2024-09-14 14:09:35 +02:00
enum-type.exp [gdb/symtab] Revert "Change handling of DW_TAG_enumeration_type in DWARF scanner" 2024-09-14 14:09:35 +02:00
file1.txt
fission-absolute-dwo.c
fission-absolute-dwo.exp
fission-base.c
fission-base.exp
fission-base.S
fission-loclists-pie.exp
fission-loclists-pie.S
fission-loclists.exp
fission-loclists.S
fission-mix-2.c
fission-mix.c
fission-mix.exp
fission-mix.h
fission-multi-cu.c
fission-multi-cu.exp
fission-relative-dwo.c
fission-relative-dwo.exp
fission-reread.exp
fission-reread.S
formdata16.exp
fortran-var-string.c
fortran-var-string.exp
forward-spec-inter-cu.exp
forward-spec.exp [gdb/testsuite] Simplify gdb.dwarf2/forward-spec.exp 2024-09-11 17:56:34 +02:00
frame-inlined-in-outer-frame.exp
frame-inlined-in-outer-frame.S
gdb-add-index-symlink.exp
gdb-add-index.exp
gdb-index-cxx.exp
gdb-index-nodebug.exp
gdb-index-tilde.exp
gdb-index-types-dwarf5.c
gdb-index-types-dwarf5.exp
gdb-index.exp
implptr-64bit.exp
implptr-optimized-out.exp
implptr.c
implptr.exp
implptr.S
implptrconst.exp [gdb/testsuite] Drop -readnow in three gdb.dwarf2 test-cases 2024-09-21 05:55:18 +02:00
implptrpiece.exp [gdb/testsuite] Drop -readnow in three gdb.dwarf2 test-cases 2024-09-21 05:55:18 +02:00
implref-array.c
implref-array.exp
implref-const.exp
implref-global.c
implref-global.exp
implref-struct.c
implref-struct.exp
imported-unit-abstract-const-value.exp
imported-unit-bp-alt.c
imported-unit-bp-c.exp
imported-unit-bp-c++.exp
imported-unit-bp-main.c
imported-unit-bp.exp.tcl
imported-unit-c.exp
imported-unit-runto-main.exp
imported-unit.c
imported-unit.exp
index.cc
info-locals-optimized-out.exp
inline.c
inline.exp
inlined_subroutine-inheritance.exp
intbits.c
intbits.exp
loc-sec-offset.c
loc-sec-offset.exp
locexpr-data-member-location-lib.c
locexpr-data-member-location-main.c
locexpr-data-member-location.exp
locexpr-data-member-location.h
loclists-multiple-cus.c
loclists-multiple-cus.exp
loclists-sec-offset.c
loclists-sec-offset.exp
loclists-start-end.c
loclists-start-end.exp
mac-fileno.exp
mac-fileno.S
macro-complaints.exp [gdb/symtab] Emit malformed macro definition complaint once 2024-07-30 16:56:31 +02:00
macro-source-path.c
macro-source-path.exp
main-foo.c
main-subprogram.c
main-subprogram.exp
main.c
mega-enum.exp
member-ptr-forwardref.exp
member-ptr-forwardref.S
method-ptr.cc
method-ptr.exp
missing-line-table.c
missing-line-table.exp
missing-sig-type.exp
missing-type-name-for-templates.cc
missing-type-name-for-templates.exp
missing-type-name.exp
multidictionary.exp
negative-data-member-location.c
negative-data-member-location.exp
no-gnu-debuglink.exp
nonvar-access.exp
nostaticblock.exp
nullptr_t.cc
nullptr_t.exp
opaque-type-lookup-2.c
opaque-type-lookup.exp
opt-out-not-implptr.exp
per-bfd-sharing.c
per-bfd-sharing.exp
pieces-optimized-out.c
pieces-optimized-out.exp
pieces-optimized-out.S
pieces.c
pieces.exp
pieces.S
pr10770.c
pr10770.exp
pr11465.exp
pr11465.S
pr13961.exp
pr13961.S
rnglists-multiple-cus.exp
rnglists-sec-offset.exp
rust-enum.exp
self-spec.exp
shortpiece.exp
static-optimized-out.exp
staticvirtual.exp
struct-decl.exp
struct-with-sig-2.exp [gdb/symtab] Change DWARF_ERROR from Dwarf Error to DWARF Error 2024-08-27 09:08:41 +02:00
struct-with-sig.exp
subrange-enum.exp
subrange.exp
symbol_needs_eval_fail.exp
symbol_needs_eval_timeout.exp
symbol_needs_eval.c
symtab-producer.exp
template-specification-full-name.exp
trace-crash.exp
trace-crash.S
typeddwarf-amd64.S
typeddwarf.c
typeddwarf.exp
typeddwarf.S
typedef-void-finish.exp
utf-rust.exp
valop.exp
valop.S
var-access.c
var-access.exp
variant.c
variant.exp
varval.c
varval.exp
void-type.c
void-type.exp
watch-notconst2.c
watch-notconst2.S
watch-notconst.c
watch-notconst.exp