]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
readelf: Handle line tables without line number statements correctly
authorMark Wielaard <mark@klomp.org>
Sat, 3 Jul 2021 22:08:32 +0000 (00:08 +0200)
committerMark Wielaard <mark@klomp.org>
Sat, 3 Jul 2021 22:08:32 +0000 (00:08 +0200)
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 <mark@klomp.org>
src/readelf.c
tests/Makefile.am
tests/run-readelf-multi-noline.sh [new file with mode: 0755]
tests/testfile_multi_noline.bz2 [new file with mode: 0755]

index 1f13f765154dc0358a3848ce43ba441e60d4792d..161d7e655c47d1643d068e542d945f9b36631eb0 100644 (file)
@@ -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:"));
index dc7517d903c2224d902a6976df170c579214a40c..7620427716eb0a3943e9578b9f12ba174f604f36 100644 (file)
@@ -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 (executable)
index 0000000..d72a9fd
--- /dev/null
@@ -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 <http://www.gnu.org/licenses/>.
+
+. $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 <main>
+ [    79] copy
+ [    7a] set column to 15
+ [    7c] special opcode 32: address+4 = +0x728 <main+0x4>, 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 <main>
+     1:15  S        0   0  0 +0x0000000000000728 <main+0x4>
+     1:15  S   *    0   0  0 +0x000000000000072b <main+0x7>
+
+EOF
+
+exit 0
diff --git a/tests/testfile_multi_noline.bz2 b/tests/testfile_multi_noline.bz2
new file mode 100755 (executable)
index 0000000..39320d1
Binary files /dev/null and b/tests/testfile_multi_noline.bz2 differ