Skip to content

Commit 1ea5da0

Browse files
committed
[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.
1 parent f51e0e2 commit 1ea5da0

File tree

4 files changed

+15
-6
lines changed

4 files changed

+15
-6
lines changed

gdb/ChangeLog

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
2018-07-04 Tom de Vries <tdevries@suse.de>
2+
3+
* dwarf2read.c (error_check_comp_unit_head): Move dwarf version
4+
check ...
5+
(read_comp_unit_head): ... here.
6+
17
2018-07-03 Tom Tromey <tom@tromey.com>
28

39
* tracepoint.c (process_tracepoint_on_disconnect, start_tracing)

gdb/dwarf2read.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6308,6 +6308,10 @@ read_comp_unit_head (struct comp_unit_head *cu_header,
63086308
cu_header->offset_size = (bytes_read == 4) ? 4 : 8;
63096309
info_ptr += bytes_read;
63106310
cu_header->version = read_2_bytes (abfd, info_ptr);
6311+
if (cu_header->version < 2 || cu_header->version > 5)
6312+
error (_("Dwarf Error: wrong version in compilation unit header "
6313+
"(is %d, should be 2, 3, 4 or 5) [in module %s]"),
6314+
cu_header->version, filename);
63116315
info_ptr += 2;
63126316
if (cu_header->version < 5)
63136317
switch (section_kind)
@@ -6410,11 +6414,6 @@ error_check_comp_unit_head (struct dwarf2_per_objfile *dwarf2_per_objfile,
64106414
{
64116415
const char *filename = get_section_file_name (section);
64126416

6413-
if (header->version < 2 || header->version > 5)
6414-
error (_("Dwarf Error: wrong version in compilation unit header "
6415-
"(is %d, should be 2, 3, 4 or 5) [in module %s]"), header->version,
6416-
filename);
6417-
64186417
if (to_underlying (header->abbrev_sect_off)
64196418
>= dwarf2_section_size (dwarf2_per_objfile->objfile, abbrev_section))
64206419
error (_("Dwarf Error: bad offset (%s) in compilation unit header "

gdb/testsuite/ChangeLog

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
2018-07-04 Tom de Vries <tdevries@suse.de>
2+
3+
* gdb.dwarf2/dw2-error.exp: Update expected error message.
4+
15
2018-07-02 Maciej W. Rozycki <macro@mips.com>
26

37
PR tdep/8282

gdb/testsuite/gdb.dwarf2/dw2-error.exp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ gdb_test_no_output "set breakpoint pending off"
4141

4242
# First test that reading symbols fails.
4343
gdb_test "file $binfile" \
44-
{Reading symbols.*Dwarf Error: wrong unit_type in compilation unit header \(is 0, should be 1 or 2\).*} \
44+
{Reading symbols.*Dwarf Error: wrong version in compilation unit header \(is 153, should be 2, 3, 4 or 5\).*} \
4545
"file $testfile"
4646

4747
# Now check that we can still break given the minimal symbol.

0 commit comments

Comments
 (0)