binutils-gdb/gdb/testsuite/gdb.dwarf2
Andrew Burgess 17c89ffc0a gdb: only update m_last_subfile after writing a line table entry
While working on another patch which changes how we parse the line
DWARF line tables I noticed what I think is a minor bug in how we
process the line tables.

What I noticed is that my new line table parser was adding more END
markers into the parsed table than GDB's current approach.  This
difference was observed when processing the debug information for
libstdc++.

Here is the line table from the new test, this is a reasonable
reproduction of the problem case that I observed in the actual debug
line table:

  Contents of the .debug_line section:

  dw2-skipped-line-entries-1.c:
  File name                        Line number    Starting address    View    Stmt
  dw2-skipped-line-entries-1.c             101            0x40110a               x

  /tmp/dw2-skipped-line-entries-2.c:
  dw2-skipped-line-entries-2.c             201            0x401114               x

  /tmp/dw2-skipped-line-entries-3.c:
  dw2-skipped-line-entries-3.c             301            0x40111e               x

  /tmp/dw2-skipped-line-entries-1.c:
  dw2-skipped-line-entries-1.c             102            0x401128               x
  dw2-skipped-line-entries-1.c             103            0x401128               x
  dw2-skipped-line-entries-1.c             104            0x401128               x

  /tmp/dw2-skipped-line-entries-2.c:
  dw2-skipped-line-entries-2.c             211            0x401128

  /tmp/dw2-skipped-line-entries-3.c:
  dw2-skipped-line-entries-3.c             311            0x401132

  /tmp/dw2-skipped-line-entries-1.c:
  dw2-skipped-line-entries-1.c             104            0x40113c
  dw2-skipped-line-entries-1.c             105            0x401146               x
  dw2-skipped-line-entries-1.c               -            0x401150

The problem is caused by the entry for line 211.  Notice that this
entry is at the same address as the previous entries.  Further, the
entry for 211 is a non-statement entry, while the previous entries are
statement entries.

As the entry for line 211 is a non-statement entry, and the previous
entries at that address are statement entries in a different symtab,
it is thought that it is better to prefer the earlier entries (in
dw2-skipped-line-entries-1.c), and so the entry for line 211 will be
discarded.

As GDB parses the line table it switches between the 3 symtabs (based
on source filename) adding the relevant entries to each symtab.
Additionally, as GDB switches symtabs, it adds an END entry to the
previous symtab.

The problem then is that, for the line 211 entry, this is the only
entry in dw2-skipped-line-entries-2.c before we switch symtab again.
But the line 211 entry is discarded.  This means that GDB switches
from dw2-skipped-line-entries-1.c to dw2-skipped-line-entries-2.c, and
then on to dw2-skipped-line-entries-3.c without ever adding an entry
to dw2-skipped-line-entries-2.c.

And here then is the bug.  GDB updates its idea of the previous symtab
not when an entry is written into a symtab, but every time we change
symtab.

In this case, when we switch to dw2-skipped-line-entries-3.c we add
the END marker to dw2-skipped-line-entries-2.c, even though no entries
were written to dw2-skipped-line-entries-2.c.  At the same time, no
END marker is ever written into dw2-skipped-line-entries-1.c as the
dw2-skipped-line-entries-2.c entry (for line 211) was discarded.

Here is the 'maint info line-table' for dw2-skipped-line-entries-1.c
before this patch:

  INDEX  LINE   REL-ADDRESS        UNREL-ADDRESS      IS-STMT PROLOGUE-END EPILOGUE-BEGIN
  0      101    0x000000000040110a 0x000000000040110a Y
  1      END    0x0000000000401114 0x0000000000401114 Y
  2      102    0x0000000000401128 0x0000000000401128 Y
  3      103    0x0000000000401128 0x0000000000401128 Y
  4      104    0x0000000000401128 0x0000000000401128 Y
  5      104    0x000000000040113c 0x000000000040113c
  6      105    0x0000000000401146 0x0000000000401146 Y
  7      END    0x0000000000401150 0x0000000000401150 Y

And after this patch:

  INDEX  LINE   REL-ADDRESS        UNREL-ADDRESS      IS-STMT PROLOGUE-END EPILOGUE-BEGIN
  0      101    0x000000000040110a 0x000000000040110a Y
  1      END    0x0000000000401114 0x0000000000401114 Y
  2      102    0x0000000000401128 0x0000000000401128 Y
  3      103    0x0000000000401128 0x0000000000401128 Y
  4      104    0x0000000000401128 0x0000000000401128 Y
  5      END    0x0000000000401132 0x0000000000401132 Y
  6      104    0x000000000040113c 0x000000000040113c
  7      105    0x0000000000401146 0x0000000000401146 Y
  8      END    0x0000000000401150 0x0000000000401150 Y

Notice that we gained an extra entry, the END marker that was added at
position #5 in the table.

Now, does this matter?  I cannot find any bugs that trigger because of
this behaviour.

So why fix it?  First, the current behaviour is inconsistent, as we
switch symtabs, we usually get an END marker in the previous symtab.
But occasionally we don't.  I don't like things that are inconsistent
for no good reason.  And second, as I said, I want to change the line
table parsing.  To do this I want to check that my new parser creates
an identical table to the current parser.  But my new parser naturally
"fixes" this inconsistency, so I have two choices, do extra work to
make my new parser bug-compatible with the current one, or fix the
current one.  I'd prefer to just fix the current line table parser.

There's a test that includes the above example and checks that the END
markers are put in the correct place.  But as I said, I've not been
able to trigger any negative behaviour from the current solution, so
there's no test that exposes any broken behaviour.

Approved-By: Tom Tromey <tom@tromey.com>
2025-02-14 16:43:21 +00: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
cpp-linkage-name.c
cpp-linkage-name.exp
cu-empty-name.c
cu-empty-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 Use "require" a two gdb.dwarf2 test files 2025-01-30 22:51:49 -07:00
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-aranges.c
dw2-aranges.exp
dw2-bad-abstract-origin.c gdb: fix parsing of DIEs with both low/high pc AND ranges attributes 2024-12-04 23:24:12 +00:00
dw2-bad-abstract-origin.exp gdb: fix parsing of DIEs with both low/high pc AND ranges attributes 2024-12-04 23:24:12 +00:00
dw2-bad-elf-other.S
dw2-bad-elf.exp [gdb/contrib] Add "doens't->doesn't" to common-misspellings.txt 2024-11-13 21:06:58 +01:00
dw2-bad-mips-linkage-name.c
dw2-bad-mips-linkage-name.exp
dw2-bad-parameter-type.exp
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-pc.c gdb: fix handling of DW_AT_entry_pc of inlined subroutines 2024-11-13 13:41:27 +00:00
dw2-entry-pc.exp gdb: fix handling of DW_AT_entry_pc of inlined subroutines 2024-11-13 13:41:27 +00:00
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
dw2-error.S
dw2-filename.exp
dw2-filename.S
dw2-fixed-point.c
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 [gdb/contrib] Add two rules in common-misspellings.txt 2024-11-23 12:20:34 +01:00
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 [gdb/contrib] Add two rules in common-misspellings.txt 2024-11-23 12:20:34 +01:00
dw2-inline-stepping.exp
dw2-inline-with-lexical-scope.c
dw2-inline-with-lexical-scope.exp
dw2-inter-cu-error-2.exp
dw2-inter-cu-error.exp
dw2-inter-cu-forth-and-back.exp
dw2-inter-cu-symbol.exp
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
dw2-lines.c
dw2-lines.exp
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/contrib] Add two rules in common-misspellings.txt 2024-11-23 12:20:34 +01:00
dw2-modula2-self-type.exp
dw2-modula2-self-type.S
dw2-multiple-debug-info.c
dw2-multiple-debug-info.exp
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 [gdb/contrib] Add two rules in common-misspellings.txt 2024-11-23 12:20:34 +01:00
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-skipped-line-entries.c gdb: only update m_last_subfile after writing a line table entry 2025-02-14 16:43:21 +00:00
dw2-skipped-line-entries.exp gdb: only update m_last_subfile after writing a line table entry 2025-02-14 16:43:21 +00:00
dw2-stack-boundary.exp
dw2-stack-boundary.S
dw2-step-between-different-inline-functions.c gdb: stepping between inline functions with multiple ranges 2024-11-13 13:50:21 +00:00
dw2-step-between-different-inline-functions.exp gdb: stepping between inline functions with multiple ranges 2024-11-13 13:50:21 +00:00
dw2-step-between-inline-func-blocks.c gdb: stepping between inline functions with multiple ranges 2024-11-13 13:50:21 +00:00
dw2-step-between-inline-func-blocks.exp gdb: stepping between inline functions with multiple ranges 2024-11-13 13:50:21 +00:00
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-tu-dwarf-4-5-2.c [gdb/testsuite] Add gdb.dwarf2/dw2-tu-dwarf-4-5.exp 2024-11-27 18:48:43 +01:00
dw2-tu-dwarf-4-5.c [gdb/testsuite] Add gdb.dwarf2/dw2-tu-dwarf-4-5.exp 2024-11-27 18:48:43 +01:00
dw2-tu-dwarf-4-5.exp [gdb/testsuite] Add gdb.dwarf2/dw2-tu-dwarf-4-5.exp 2024-11-27 18:48:43 +01:00
dw2-undefined-ret-addr.c
dw2-undefined-ret-addr.exp
dw2-undefined-ret-addr.S
dw2-unexpected-entry-pc.c gdb: handle DW_AT_entry_pc pointing at an empty sub-range 2024-12-02 10:45:28 +00:00
dw2-unexpected-entry-pc.exp gdb: handle DW_AT_entry_pc pointing at an empty sub-range 2024-12-02 10:45:28 +00:00
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 Avoid "text file busy" in dw2-using-debug-str.exp 2025-02-02 10:44:17 -07: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
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
enum-type-c++.exp
enum-type.exp
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
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/testsuite] Use c++ flag in c++ test-cases 2025-02-04 13:53:20 +01:00
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 [gdb/testsuite] Fix gdb.dwarf2/implptr.exp regression 2025-01-16 15:00:11 +01:00
implptr.S
implptrconst.exp
implptrpiece.exp
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 Use "require" a two gdb.dwarf2 test files 2025-01-30 22:51:49 -07:00
imported-unit-c.exp
imported-unit-runto-main.exp
imported-unit.c
imported-unit.exp
index.cc
info-locals-optimized-out.exp [gdb/cli] Show LOC_CONST_BYTES var for info locals 2025-01-06 18:48:58 +01:00
inline.c
inline.exp
inlined_subroutine-inheritance.exp
intbits.c
intbits.exp
loc-sec-offset.c
loc-sec-offset.exp
local-var.exp
local-var.f90
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
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 [gdb/testsuite] Use c++ flag in c++ test-cases 2025-02-04 13:53:20 +01:00
missing-line-table.c
missing-line-table.exp
missing-sig-type.exp
missing-type-name-for-templates.cc
missing-type-name-for-templates.exp [gdb/testsuite] Use c++ flag in c++ test-cases 2025-02-04 13:53:20 +01:00
missing-type-name.exp
multidictionary.exp
nameless-enum.exp Fix crash in DWARF indexer 2025-01-07 07:43:22 -07:00
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
short-build-id.exp gdb/build-id: protect against weirdly short build-ids 2024-11-21 19:38:39 +00:00
shortpiece.exp
static-optimized-out.exp
staticvirtual.exp
struct-decl.exp
struct-with-sig-2.exp
struct-with-sig.exp
subrange-enum.exp
subrange.exp [gdb/testsuite] Use c++ flag in c++ test-cases 2025-02-04 13:53:20 +01:00
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