* [PATCH][gdb/testsuite] Fix error message test in dw2-error.exp
@ 2018-06-19 9:03 Tom de Vries
2018-07-03 14:21 ` [PING][PATCH][gdb/testsuite] " Tom de Vries
2018-07-03 14:59 ` [PATCH][gdb/testsuite] " Pedro Alves
0 siblings, 2 replies; 5+ messages in thread
From: Tom de Vries @ 2018-06-19 9:03 UTC (permalink / raw)
To: gdb-patches
Hi,
the executable used in dw2-error.exp is compiled from a .s that was generated
with dwarf2 debug information but has been hand-edited to set the version in
the compilation unit header to 0x99:
...
.Ldebug_info0:
.long 0x4e # Length of Compilation Unit Info
.value 0x99 # DWARF version number
.long .Ldebug_abbrev0 # Offset Into Abbrev. Section
...
Consequently, dwarf2read.c:read_comp_unit_head() interprets the compilation
unit header as dwarf5, which starts with fields unit_length (4 or 12 byte
unsigned), version (uhalf), and unit_type (ubyte). So, the unit_type
field is initialized from the first byte of .Ldebug_abbrev0 offset.
Using objdump, we find that the value of that byte is 0x64.
...
Contents of section .debug_info:
...
00c0 00450000 0001804e 00000099 00640000 .E.....N.....d..
...
And indeed gdb errors out accordingly (note: 0x64 == 100):
...
(gdb) file outputs/gdb.dwarf2/dw2-error/dw2-error
Reading symbols from outputs/gdb.dwarf2/dw2-error/dw2-error...
Dwarf Error: wrong unit_type in compilation unit header
(is 100, should be 1 or 2)
[in module outputs/gdb.dwarf2/dw2-error/dw2-error]
(no debugging symbols found)...done.
...
The test fails however because it expects the error message to contain 0
instead of the 100 we're seeing.
This patch fixes the failure by allowing any value for the unit_type in the
error message.
Tested on x86_64-linux.
OK for trunk?
Thanks,
- Tom
[gdb/testsuite] Fix error message test in dw2-error.exp
2018-06-19 Tom de Vries <tdevries@suse.de>
* gdb.dwarf2/dw2-error.exp: Allowing any value for the unit_type in
the "wrong unit_type in compilation unit header" error message.
---
gdb/testsuite/gdb.dwarf2/dw2-error.exp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/gdb/testsuite/gdb.dwarf2/dw2-error.exp b/gdb/testsuite/gdb.dwarf2/dw2-error.exp
index e22667dea5..441e0f8db5 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 unit_type in compilation unit header \(is [0-9]+, should be 1 or 2\).*} \
"file $testfile"
# Now check that we can still break given the minimal symbol.
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PING][PATCH][gdb/testsuite] Fix error message test in dw2-error.exp
2018-06-19 9:03 [PATCH][gdb/testsuite] Fix error message test in dw2-error.exp Tom de Vries
@ 2018-07-03 14:21 ` Tom de Vries
2018-07-03 14:59 ` [PATCH][gdb/testsuite] " Pedro Alves
1 sibling, 0 replies; 5+ messages in thread
From: Tom de Vries @ 2018-07-03 14:21 UTC (permalink / raw)
To: gdb-patches
On 06/19/2018 11:00 AM, Tom de Vries wrote:
> Hi,
>
> the executable used in dw2-error.exp is compiled from a .s that was generated
> with dwarf2 debug information but has been hand-edited to set the version in
> the compilation unit header to 0x99:
> ...
> .Ldebug_info0:
> .long 0x4e # Length of Compilation Unit Info
> .value 0x99 # DWARF version number
> .long .Ldebug_abbrev0 # Offset Into Abbrev. Section
> ...
>
> Consequently, dwarf2read.c:read_comp_unit_head() interprets the compilation
> unit header as dwarf5, which starts with fields unit_length (4 or 12 byte
> unsigned), version (uhalf), and unit_type (ubyte). So, the unit_type
> field is initialized from the first byte of .Ldebug_abbrev0 offset.
>
> Using objdump, we find that the value of that byte is 0x64.
> ...
> Contents of section .debug_info:
> ...
> 00c0 00450000 0001804e 00000099 00640000 .E.....N.....d..
> ...
>
> And indeed gdb errors out accordingly (note: 0x64 == 100):
> ...
> (gdb) file outputs/gdb.dwarf2/dw2-error/dw2-error
> Reading symbols from outputs/gdb.dwarf2/dw2-error/dw2-error...
> Dwarf Error: wrong unit_type in compilation unit header
> (is 100, should be 1 or 2)
> [in module outputs/gdb.dwarf2/dw2-error/dw2-error]
> (no debugging symbols found)...done.
> ...
>
> The test fails however because it expects the error message to contain 0
> instead of the 100 we're seeing.
>
> This patch fixes the failure by allowing any value for the unit_type in the
> error message.
>
> Tested on x86_64-linux.
>
> OK for trunk?
>
> Thanks,
> - Tom
>
> [gdb/testsuite] Fix error message test in dw2-error.exp
>
> 2018-06-19 Tom de Vries <tdevries@suse.de>
>
> * gdb.dwarf2/dw2-error.exp: Allowing any value for the unit_type in
> the "wrong unit_type in compilation unit header" error message.
>
> ---
> gdb/testsuite/gdb.dwarf2/dw2-error.exp | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/gdb/testsuite/gdb.dwarf2/dw2-error.exp b/gdb/testsuite/gdb.dwarf2/dw2-error.exp
> index e22667dea5..441e0f8db5 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 unit_type in compilation unit header \(is [0-9]+, should be 1 or 2\).*} \
> "file $testfile"
>
> # Now check that we can still break given the minimal symbol.
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH][gdb/testsuite] Fix error message test in dw2-error.exp
2018-06-19 9:03 [PATCH][gdb/testsuite] Fix error message test in dw2-error.exp Tom de Vries
2018-07-03 14:21 ` [PING][PATCH][gdb/testsuite] " Tom de Vries
@ 2018-07-03 14:59 ` Pedro Alves
2018-07-04 6:54 ` [PATCH][gdb/symtab] Fix version check in dwarf compilation unit header Tom de Vries
1 sibling, 1 reply; 5+ messages in thread
From: Pedro Alves @ 2018-07-03 14:59 UTC (permalink / raw)
To: Tom de Vries, gdb-patches
On 06/19/2018 10:00 AM, Tom de Vries wrote:
> the executable used in dw2-error.exp is compiled from a .s that was generated
> with dwarf2 debug information but has been hand-edited to set the version in
> the compilation unit header to 0x99:
> ...
> .Ldebug_info0:
> .long 0x4e # Length of Compilation Unit Info
> .value 0x99 # DWARF version number
> .long .Ldebug_abbrev0 # Offset Into Abbrev. Section
> ...
>
> Consequently, dwarf2read.c:read_comp_unit_head() interprets the compilation
> unit header as dwarf5,
That right there looks like the real bug to me.
I went looking for the history behind the testcase, and
got surprised that the testcase is expecting that "wrong unit_type in
compilation unit header" error instead of the same error that had been
reported in the original bug report at
<https://sourceware.org/bugzilla/show_bug.cgi?id=14931>:
~~~~~
Dwarf Error: wrong version in compilation unit header (is 4, should be 2) [in module ....build/gdb/gdb]
~~~~~
read_and_check_comp_unit_head calls error_check_comp_unit_head
after calling read_comp_unit_head, and thus AFAICT error_check_comp_unit_head
would error out with the "wrong version" error, the one that had been
reported in the original bug report. That seems like a much better
error to me.
static void
error_check_comp_unit_head (struct dwarf2_per_objfile *dwarf2_per_objfile,
struct comp_unit_head *header,
struct dwarf2_section_info *section,
struct dwarf2_section_info *abbrev_section)
{
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);
So it seems to me that read_comp_unit_head shouldn't be
trying to interpret contents of a dwarf version that
gdb doesn't understand. Seems like that error_check_comp_unit_head
version check is too late? How about moving it into
read_and_check_comp_unit_head? Of course, the testcase would then
be adjusted to expect the new message, and it would expect 153/0x99
exactly instead of any number, which ensures that gdb reads and
prints the version number correctly.
Thanks,
Pedro Alves
> which starts with fields unit_length (4 or 12 byte
> unsigned), version (uhalf), and unit_type (ubyte). So, the unit_type
> field is initialized from the first byte of .Ldebug_abbrev0 offset.
>
> Using objdump, we find that the value of that byte is 0x64.
> ...
> Contents of section .debug_info:
> ...
> 00c0 00450000 0001804e 00000099 00640000 .E.....N.....d..
> ...
>
> And indeed gdb errors out accordingly (note: 0x64 == 100):
> ...
> (gdb) file outputs/gdb.dwarf2/dw2-error/dw2-error
> Reading symbols from outputs/gdb.dwarf2/dw2-error/dw2-error...
> Dwarf Error: wrong unit_type in compilation unit header
> (is 100, should be 1 or 2)
> [in module outputs/gdb.dwarf2/dw2-error/dw2-error]
> (no debugging symbols found)...done.
> ...
>
> The test fails however because it expects the error message to contain 0
> instead of the 100 we're seeing.
>
> This patch fixes the failure by allowing any value for the unit_type in the
> error message.
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH][gdb/symtab] Fix version check in dwarf compilation unit header
2018-07-03 14:59 ` [PATCH][gdb/testsuite] " Pedro Alves
@ 2018-07-04 6:54 ` Tom de Vries
2018-07-04 9:36 ` Pedro Alves
0 siblings, 1 reply; 5+ messages in thread
From: Tom de Vries @ 2018-07-04 6:54 UTC (permalink / raw)
To: Pedro Alves; +Cc: gdb-patches
[ was: Subject: Re: [PATCH][gdb/testsuite] Fix error message test in
dw2-error.exp ]
On Tue, Jul 03, 2018 at 03:59:17PM +0100, Pedro Alves wrote:
> On 06/19/2018 10:00 AM, Tom de Vries wrote:
>
> > the executable used in dw2-error.exp is compiled from a .s that was generated
> > with dwarf2 debug information but has been hand-edited to set the version in
> > the compilation unit header to 0x99:
> > ...
> > .Ldebug_info0:
> > .long 0x4e # Length of Compilation Unit Info
> > .value 0x99 # DWARF version number
> > .long .Ldebug_abbrev0 # Offset Into Abbrev. Section
> > ...
> >
> > Consequently, dwarf2read.c:read_comp_unit_head() interprets the compilation
> > unit header as dwarf5,
>
>
> That right there looks like the real bug to me.
>
> I went looking for the history behind the testcase, and
> got surprised that the testcase is expecting that "wrong unit_type in
> compilation unit header" error instead of the same error that had been
> reported in the original bug report at
> <https://sourceware.org/bugzilla/show_bug.cgi?id=14931>:
>
> ~~~~~
> Dwarf Error: wrong version in compilation unit header (is 4, should be 2) [in module ....build/gdb/gdb]
> ~~~~~
>
> read_and_check_comp_unit_head calls error_check_comp_unit_head
> after calling read_comp_unit_head, and thus AFAICT error_check_comp_unit_head
> would error out with the "wrong version" error, the one that had been
> reported in the original bug report. That seems like a much better
> error to me.
>
> static void
> error_check_comp_unit_head (struct dwarf2_per_objfile *dwarf2_per_objfile,
> struct comp_unit_head *header,
> struct dwarf2_section_info *section,
> struct dwarf2_section_info *abbrev_section)
> {
> 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);
>
>
>
> So it seems to me that read_comp_unit_head shouldn't be
> trying to interpret contents of a dwarf version that
> gdb doesn't understand. Seems like that error_check_comp_unit_head
> version check is too late? How about moving it into
> read_and_check_comp_unit_head? Of course, the testcase would then
> be adjusted to expect the new message, and it would expect 153/0x99
> exactly instead of any number, which ensures that gdb reads and
> prints the version number correctly.
>
Agreed, that analysis makes sense.
OK for trunk?
Thanks,
- Tom
[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.
---
gdb/dwarf2read.c | 9 ++++-----
gdb/testsuite/gdb.dwarf2/dw2-error.exp | 2 +-
2 files changed, 5 insertions(+), 6 deletions(-)
diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c
index 9f6d34f1fe..372f45ee17 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/gdb.dwarf2/dw2-error.exp b/gdb/testsuite/gdb.dwarf2/dw2-error.exp
index e22667dea5..8c162a0898 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.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH][gdb/symtab] Fix version check in dwarf compilation unit header
2018-07-04 6:54 ` [PATCH][gdb/symtab] Fix version check in dwarf compilation unit header Tom de Vries
@ 2018-07-04 9:36 ` Pedro Alves
0 siblings, 0 replies; 5+ messages in thread
From: Pedro Alves @ 2018-07-04 9:36 UTC (permalink / raw)
To: Tom de Vries; +Cc: gdb-patches
On 07/04/2018 07:54 AM, Tom de Vries wrote:
> Agreed, that analysis makes sense.
>
> OK for trunk?
OK.
Thanks,
Pedro Alves
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2018-07-04 9:36 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-06-19 9:03 [PATCH][gdb/testsuite] Fix error message test in dw2-error.exp Tom de Vries
2018-07-03 14:21 ` [PING][PATCH][gdb/testsuite] " Tom de Vries
2018-07-03 14:59 ` [PATCH][gdb/testsuite] " Pedro Alves
2018-07-04 6:54 ` [PATCH][gdb/symtab] Fix version check in dwarf compilation unit header Tom de Vries
2018-07-04 9:36 ` Pedro Alves
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).