This is the mail archive of the
gdb-cvs@sourceware.org
mailing list for the GDB project.
[binutils-gdb] [gdb/symtab] Fix version check in dwarf compilation unit header
- From: Tom de Vries <vries at sourceware dot org>
- To: gdb-cvs at sourceware dot org
- Date: 4 Jul 2018 09:58:44 -0000
- Subject: [binutils-gdb] [gdb/symtab] Fix version check in dwarf compilation unit header
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=1ea5da02629b4bf9c4cea50aee189f94fa7d1a3b
commit 1ea5da02629b4bf9c4cea50aee189f94fa7d1a3b
Author: Tom de Vries <tdevries@suse.de>
Date: Wed Jul 4 00:07:30 2018 +0200
[gdb/symtab] Fix version check in dwarf compilation unit header
The version check of the dwarf compilation unit header in
error_check_comp_unit_head is done too late, and consequently dwarf code with
an unsupported version in the compilation unit header is interpreted as dwarf5
code in read_comp_unit_head.
Fixed by moving the check earlier.
Build and reg-tested on x86_64-linux.
2018-07-04 Tom de Vries <tdevries@suse.de>
* dwarf2read.c (error_check_comp_unit_head): Move dwarf version
check ...
(read_comp_unit_head): ... here.
* gdb.dwarf2/dw2-error.exp: Update expected error message.
Diff:
---
gdb/ChangeLog | 6 ++++++
gdb/dwarf2read.c | 9 ++++-----
gdb/testsuite/ChangeLog | 4 ++++
gdb/testsuite/gdb.dwarf2/dw2-error.exp | 2 +-
4 files changed, 15 insertions(+), 6 deletions(-)
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index a471149..ea1e7e3 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,9 @@
+2018-07-04 Tom de Vries <tdevries@suse.de>
+
+ * dwarf2read.c (error_check_comp_unit_head): Move dwarf version
+ check ...
+ (read_comp_unit_head): ... here.
+
2018-07-03 Tom Tromey <tom@tromey.com>
* tracepoint.c (process_tracepoint_on_disconnect, start_tracing)
diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c
index 9f6d34f..372f45e 100644
--- a/gdb/dwarf2read.c
+++ b/gdb/dwarf2read.c
@@ -6308,6 +6308,10 @@ read_comp_unit_head (struct comp_unit_head *cu_header,
cu_header->offset_size = (bytes_read == 4) ? 4 : 8;
info_ptr += bytes_read;
cu_header->version = read_2_bytes (abfd, info_ptr);
+ if (cu_header->version < 2 || cu_header->version > 5)
+ error (_("Dwarf Error: wrong version in compilation unit header "
+ "(is %d, should be 2, 3, 4 or 5) [in module %s]"),
+ cu_header->version, filename);
info_ptr += 2;
if (cu_header->version < 5)
switch (section_kind)
@@ -6410,11 +6414,6 @@ error_check_comp_unit_head (struct dwarf2_per_objfile *dwarf2_per_objfile,
{
const char *filename = get_section_file_name (section);
- if (header->version < 2 || header->version > 5)
- error (_("Dwarf Error: wrong version in compilation unit header "
- "(is %d, should be 2, 3, 4 or 5) [in module %s]"), header->version,
- filename);
-
if (to_underlying (header->abbrev_sect_off)
>= dwarf2_section_size (dwarf2_per_objfile->objfile, abbrev_section))
error (_("Dwarf Error: bad offset (%s) in compilation unit header "
diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog
index e802927..a9e1618 100644
--- a/gdb/testsuite/ChangeLog
+++ b/gdb/testsuite/ChangeLog
@@ -1,3 +1,7 @@
+2018-07-04 Tom de Vries <tdevries@suse.de>
+
+ * gdb.dwarf2/dw2-error.exp: Update expected error message.
+
2018-07-02 Maciej W. Rozycki <macro@mips.com>
PR tdep/8282
diff --git a/gdb/testsuite/gdb.dwarf2/dw2-error.exp b/gdb/testsuite/gdb.dwarf2/dw2-error.exp
index e22667d..8c162a0 100644
--- a/gdb/testsuite/gdb.dwarf2/dw2-error.exp
+++ b/gdb/testsuite/gdb.dwarf2/dw2-error.exp
@@ -41,7 +41,7 @@ gdb_test_no_output "set breakpoint pending off"
# First test that reading symbols fails.
gdb_test "file $binfile" \
- {Reading symbols.*Dwarf Error: wrong unit_type in compilation unit header \(is 0, should be 1 or 2\).*} \
+ {Reading symbols.*Dwarf Error: wrong version in compilation unit header \(is 153, should be 2, 3, 4 or 5\).*} \
"file $testfile"
# Now check that we can still break given the minimal symbol.