From: Mark Wielaard Date: Sat, 3 Jul 2021 22:08:32 +0000 (+0200) Subject: readelf: Handle line tables without line number statements correctly X-Git-Tag: elfutils-0.186~68 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=6648d378bd94f50b455a8550db5f43ef3690b451;p=thirdparty%2Felfutils.git readelf: Handle line tables without line number statements correctly When we see a line table without line number statements we need to continue with the next table. Add a testcase for this situation. https://sourceware.org/bugzilla/show_bug.cgi?id=28032 Signed-off-by: Mark Wielaard --- diff --git a/src/readelf.c b/src/readelf.c index 1f13f7651..161d7e655 100644 --- a/src/readelf.c +++ b/src/readelf.c @@ -8751,7 +8751,7 @@ print_debug_line_section (Dwfl_Module *dwflmod, Ebl *ebl, GElf_Ehdr *ehdr, if (linep == lineendp) { puts (_("\nNo line number statements.")); - return; + continue; } puts (_("\nLine number statements:")); diff --git a/tests/Makefile.am b/tests/Makefile.am index dc7517d90..762042771 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -158,6 +158,7 @@ TESTS = run-arextract.sh run-arsymtest.sh run-ar.sh newfile test-nlist \ run-backtrace-demangle.sh run-stack-d-test.sh run-stack-i-test.sh \ run-stack-demangled-test.sh run-readelf-zx.sh run-readelf-zp.sh \ run-readelf-addr.sh run-readelf-str.sh \ + run-readelf-multi-noline.sh \ run-readelf-types.sh \ run-readelf-dwz-multi.sh run-allfcts-multi.sh run-deleted.sh \ run-linkmap-cut.sh run-aggregate-size.sh run-peel-type.sh \ @@ -311,6 +312,7 @@ EXTRA_DIST = run-arextract.sh run-arsymtest.sh run-ar.sh \ testfile_multi.dwz.bz2 testfile_multi_main.bz2 \ testfile-dwzstr.bz2 testfile-dwzstr.multi.bz2 \ run-readelf-addr.sh run-readelf-str.sh \ + run-readelf-multi-noline.sh testfile_multi_noline.bz2 \ run-readelf-types.sh \ run-readelf-frames.sh \ run-readelf-n.sh \ diff --git a/tests/run-readelf-multi-noline.sh b/tests/run-readelf-multi-noline.sh new file mode 100755 index 000000000..d72a9fd4e --- /dev/null +++ b/tests/run-readelf-multi-noline.sh @@ -0,0 +1,170 @@ +#! /bin/sh +# Copyright (C) 2021 Red Hat, Inc. +# This file is part of elfutils. +# +# This file 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. +# +# elfutils 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 . + +. $srcdir/test-subr.sh + +# = a.c = +# int a; + +# = b.c = +# int b; + +# = m.c = +# int main () { } + +# gcc -g -o testfile_multi_noline a.c b.c m.c + +testfiles testfile_multi_noline + +testrun_compare ${abs_top_builddir}/src/readelf --debug-dump=line testfile_multi_noline <<\EOF + +DWARF section [29] '.debug_line' at offset 0x1221: + +Table at offset 0: + + Length: 32 + DWARF version: 3 + Prologue length: 26 + Address size: 8 + Segment selector size: 0 + Min instruction length: 4 + Max operations per instruction: 1 + Initial value if 'is_stmt': 1 + Line base: -5 + Line range: 14 + Opcode base: 13 + +Opcodes: + [ 1] 0 arguments + [ 2] 1 argument + [ 3] 1 argument + [ 4] 1 argument + [ 5] 1 argument + [ 6] 0 arguments + [ 7] 0 arguments + [ 8] 0 arguments + [ 9] 1 argument + [10] 0 arguments + [11] 0 arguments + [12] 1 argument + +Directory table: + +File name table: + Entry Dir Time Size Name + 1 0 0 0 a.c + +No line number statements. + +Table at offset 36: + + Length: 32 + DWARF version: 3 + Prologue length: 26 + Address size: 8 + Segment selector size: 0 + Min instruction length: 4 + Max operations per instruction: 1 + Initial value if 'is_stmt': 1 + Line base: -5 + Line range: 14 + Opcode base: 13 + +Opcodes: + [ 1] 0 arguments + [ 2] 1 argument + [ 3] 1 argument + [ 4] 1 argument + [ 5] 1 argument + [ 6] 0 arguments + [ 7] 0 arguments + [ 8] 0 arguments + [ 9] 1 argument + [10] 0 arguments + [11] 0 arguments + [12] 1 argument + +Directory table: + +File name table: + Entry Dir Time Size Name + 1 0 0 0 b.c + +No line number statements. + +Table at offset 72: + + Length: 54 + DWARF version: 3 + Prologue length: 26 + Address size: 8 + Segment selector size: 0 + Min instruction length: 4 + Max operations per instruction: 1 + Initial value if 'is_stmt': 1 + Line base: -5 + Line range: 14 + Opcode base: 13 + +Opcodes: + [ 1] 0 arguments + [ 2] 1 argument + [ 3] 1 argument + [ 4] 1 argument + [ 5] 1 argument + [ 6] 0 arguments + [ 7] 0 arguments + [ 8] 0 arguments + [ 9] 1 argument + [10] 0 arguments + [11] 0 arguments + [12] 1 argument + +Directory table: + +File name table: + Entry Dir Time Size Name + 1 0 0 0 m.c + +Line number statements: + [ 6c] set column to 13 + [ 6e] extended opcode 2: set address to +0x724
+ [ 79] copy + [ 7a] set column to 15 + [ 7c] special opcode 32: address+4 = +0x728 , line+0 = 1 + [ 7d] advance address by 4 to +0x72c + [ 7f] extended opcode 1: end of sequence +EOF + +testrun_compare ${abs_top_builddir}/src/readelf --debug-dump=decodedline testfile_multi_noline <<\EOF + +DWARF section [29] '.debug_line' at offset 0x1221: + + CU [b] a.c + line:col SBPE* disc isa op address (Statement Block Prologue Epilogue *End) + CU [44] b.c + line:col SBPE* disc isa op address (Statement Block Prologue Epilogue *End) + CU [7d] m.c + line:col SBPE* disc isa op address (Statement Block Prologue Epilogue *End) + /tmp/m.c (mtime: 0, length: 0) + 1:13 S 0 0 0 +0x0000000000000724
+ 1:15 S 0 0 0 +0x0000000000000728 + 1:15 S * 0 0 0 +0x000000000000072b + +EOF + +exit 0 diff --git a/tests/testfile_multi_noline.bz2 b/tests/testfile_multi_noline.bz2 new file mode 100755 index 000000000..39320d1f5 Binary files /dev/null and b/tests/testfile_multi_noline.bz2 differ