From 6648d378bd94f50b455a8550db5f43ef3690b451 Mon Sep 17 00:00:00 2001 From: Mark Wielaard Date: Sun, 4 Jul 2021 00:08:32 +0200 Subject: [PATCH] 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 --- src/readelf.c | 2 +- tests/Makefile.am | 2 + tests/run-readelf-multi-noline.sh | 170 ++++++++++++++++++++++++++++++ tests/testfile_multi_noline.bz2 | Bin 0 -> 3155 bytes 4 files changed, 173 insertions(+), 1 deletion(-) create mode 100755 tests/run-readelf-multi-noline.sh create mode 100755 tests/testfile_multi_noline.bz2 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 0000000000000000000000000000000000000000..39320d1f57f82d5633f2892fb559b1cad8976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