* [RFA] Fix size check in dwarf2_evaluate_loc_desc_full
@ 2017-05-29 16:25 Tom Tromey
2017-05-29 20:55 ` Simon Marchi
0 siblings, 1 reply; 6+ messages in thread
From: Tom Tromey @ 2017-05-29 16:25 UTC (permalink / raw)
To: gdb-patches; +Cc: Tom Tromey
This Rust bug report:
https://github.com/rust-lang/rust/issues/41970
noted an error from gdb. What is happening here (for me, the original
report had a different error) is that a pieced DWARF expression is not
writing to every byte in the resulting value. GDB errors in this
case. However, it seems to me that it is always valid to write fewer
bytes; the issue comes from writing too many -- that is, the test is
reversed. The test was also checking the sub-object, but this also
seems incorrect, as it's expected for the expression to write the
entirety of the enclosing object. So, this patch reverses the test
and applies it to the outer type, not the subobject type.
Regtested on the buildbot.
ChangeLog
2017-05-29 Tom Tromey <tom@tromey.com>
* dwarf2loc.c (dwarf2_evaluate_loc_desc_full): Reverse size
check and apply to outer type.
testsuite/ChangeLog
2017-05-29 Tom Tromey <tom@tromey.com>
* gdb.dwarf2/shortpiece.exp: New file.
---
gdb/ChangeLog | 5 ++
gdb/dwarf2loc.c | 4 +-
gdb/testsuite/ChangeLog | 4 ++
gdb/testsuite/gdb.dwarf2/shortpiece.exp | 84 +++++++++++++++++++++++++++++++++
4 files changed, 96 insertions(+), 1 deletion(-)
create mode 100644 gdb/testsuite/gdb.dwarf2/shortpiece.exp
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index c0fcb22..24d261f 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,8 @@
+2017-05-29 Tom Tromey <tom@tromey.com>
+
+ * dwarf2loc.c (dwarf2_evaluate_loc_desc_full): Reverse size
+ check and apply to outer type.
+
2017-05-21 Tom Tromey <tom@tromey.com>
PR rust/21466:
diff --git a/gdb/dwarf2loc.c b/gdb/dwarf2loc.c
index 127167d..9ffe197 100644
--- a/gdb/dwarf2loc.c
+++ b/gdb/dwarf2loc.c
@@ -2407,7 +2407,9 @@ dwarf2_evaluate_loc_desc_full (struct type *type, struct frame_info *frame,
for (i = 0; i < ctx.num_pieces; ++i)
bit_size += ctx.pieces[i].size;
- if (8 * (subobj_byte_offset + TYPE_LENGTH (subobj_type)) > bit_size)
+ /* Complain if the expression is larger than the size of the
+ outer type. */
+ if (bit_size > 8 * TYPE_LENGTH (type))
invalid_synthetic_pointer ();
c = allocate_piece_closure (per_cu, ctx.num_pieces, ctx.pieces,
diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog
index c16f201..d31679a 100644
--- a/gdb/testsuite/ChangeLog
+++ b/gdb/testsuite/ChangeLog
@@ -1,3 +1,7 @@
+2017-05-29 Tom Tromey <tom@tromey.com>
+
+ * gdb.dwarf2/shortpiece.exp: New file.
+
2017-05-21 Tom Tromey <tom@tromey.com>
PR rust/21466:
diff --git a/gdb/testsuite/gdb.dwarf2/shortpiece.exp b/gdb/testsuite/gdb.dwarf2/shortpiece.exp
new file mode 100644
index 0000000..588f6a1
--- /dev/null
+++ b/gdb/testsuite/gdb.dwarf2/shortpiece.exp
@@ -0,0 +1,84 @@
+# Copyright 2017 Free Software Foundation, Inc.
+
+# This program 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.
+#
+# This program 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/>.
+
+load_lib dwarf.exp
+
+# This test can only be run on targets which support DWARF-2 and use gas.
+if {![dwarf2_support]} {
+ return 0
+}
+
+standard_testfile main.c shortpiece-dw.S
+
+# Make some DWARF for the test.
+set asm_file [standard_output_file $srcfile2]
+Dwarf::assemble $asm_file {
+ global pair
+
+ cu { addr_size 4 } {
+ compile_unit {} {
+ declare_labels int_label ushort_label struct_label
+
+ int_label: DW_TAG_base_type {
+ {DW_AT_byte_size 4 DW_FORM_udata}
+ {DW_AT_encoding @DW_ATE_unsigned}
+ {DW_AT_name "myint"}
+ }
+ ushort_label: DW_TAG_base_type {
+ {DW_AT_byte_size 2 DW_FORM_udata}
+ {DW_AT_encoding @DW_ATE_unsigned}
+ {DW_AT_name "myushort"}
+ }
+
+ struct_label: DW_TAG_structure_type {
+ {DW_AT_name "S"}
+ {DW_AT_byte_size 8 DW_FORM_udata}
+ } {
+ DW_TAG_member {
+ {DW_AT_name "a"}
+ {DW_AT_type :${int_label}}
+ {DW_AT_data_member_location 0 DW_FORM_udata}
+ }
+
+ DW_TAG_member {
+ {DW_AT_name "b"}
+ {DW_AT_type :${ushort_label}}
+ {DW_AT_data_member_location 4 DW_FORM_udata}
+ }
+ }
+
+ DW_TAG_variable {
+ {DW_AT_name "s1"}
+ {DW_AT_type :${struct_label}}
+ {DW_AT_external 1 DW_FORM_flag}
+ {DW_AT_location {
+ DW_OP_constu 1
+ DW_OP_stack_value
+ DW_OP_piece 4
+ DW_OP_constu 0
+ DW_OP_stack_value
+ DW_OP_piece 2
+ } SPECIAL_expr}
+ }
+ }
+ }
+}
+
+if { [prepare_for_testing "failed to prepare" ${testfile} \
+ [list $srcfile $asm_file] {nodebug}] } {
+ return -1
+}
+
+gdb_test "p s1" " = {a = 1, b = 0}"
--
2.9.3
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [RFA] Fix size check in dwarf2_evaluate_loc_desc_full
2017-05-29 16:25 [RFA] Fix size check in dwarf2_evaluate_loc_desc_full Tom Tromey
@ 2017-05-29 20:55 ` Simon Marchi
2017-05-29 23:19 ` Tom Tromey
0 siblings, 1 reply; 6+ messages in thread
From: Simon Marchi @ 2017-05-29 20:55 UTC (permalink / raw)
To: Tom Tromey; +Cc: gdb-patches
On 2017-05-29 18:25, Tom Tromey wrote:
> This Rust bug report:
>
> https://github.com/rust-lang/rust/issues/41970
>
> noted an error from gdb. What is happening here (for me, the original
> report had a different error) is that a pieced DWARF expression is not
> writing to every byte in the resulting value. GDB errors in this
> case. However, it seems to me that it is always valid to write fewer
> bytes; the issue comes from writing too many -- that is, the test is
> reversed. The test was also checking the sub-object, but this also
> seems incorrect, as it's expected for the expression to write the
> entirety of the enclosing object. So, this patch reverses the test
> and applies it to the outer type, not the subobject type.
Your explanation sounds sensible to me (and the tests suggests it's
good). Andreas, since you played with DWARF pieces quite a bit, do you
have an opinion on this?
Would it be possible to test the error case as well by feeding bad DWARF
info in the test case?
Thanks!
Simon
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [RFA] Fix size check in dwarf2_evaluate_loc_desc_full
2017-05-29 20:55 ` Simon Marchi
@ 2017-05-29 23:19 ` Tom Tromey
2017-05-30 5:51 ` Simon Marchi
0 siblings, 1 reply; 6+ messages in thread
From: Tom Tromey @ 2017-05-29 23:19 UTC (permalink / raw)
To: Simon Marchi; +Cc: Tom Tromey, gdb-patches
Simon> Would it be possible to test the error case as well by feeding bad
Simon> DWARF info in the test case?
Sure, here it is.
Tom
commit 51762c8cfa3a0b7203032db42b97ad51c188602b
Author: Tom Tromey <tom@tromey.com>
Date: Sun May 28 08:06:54 2017 -0600
Fix size check in dwarf2_evaluate_loc_desc_full
This Rust bug report:
https://github.com/rust-lang/rust/issues/41970
noted an error from gdb. What is happening here (for me, the original
report had a different error) is that a pieced DWARF expression is not
writing to every byte in the resulting value. GDB errors in this
case. However, it seems to me that it is always valid to write fewer
bytes; the issue comes from writing too many -- that is, the test is
reversed. The test was also checking the sub-object, but this also
seems incorrect, as it's expected for the expression to write the
entirety of the enclosing object. So, this patch reverses the test
and applies it to the outer type, not the subobject type.
Regtested on the buildbot.
ChangeLog
2017-05-29 Tom Tromey <tom@tromey.com>
* dwarf2loc.c (dwarf2_evaluate_loc_desc_full): Reverse size
check and apply to outer type.
testsuite/ChangeLog
2017-05-29 Tom Tromey <tom@tromey.com>
* gdb.dwarf2/shortpiece.exp: New file.
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index fd52229..e331f4a 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,8 @@
+2017-05-29 Tom Tromey <tom@tromey.com>
+
+ * dwarf2loc.c (dwarf2_evaluate_loc_desc_full): Reverse size
+ check and apply to outer type.
+
2017-05-26 Alan Hayward <alan.hayward@arm.com>
* defs.h (copy_integer_to_size): New declaration.
diff --git a/gdb/dwarf2loc.c b/gdb/dwarf2loc.c
index 127167d..9ffe197 100644
--- a/gdb/dwarf2loc.c
+++ b/gdb/dwarf2loc.c
@@ -2407,7 +2407,9 @@ dwarf2_evaluate_loc_desc_full (struct type *type, struct frame_info *frame,
for (i = 0; i < ctx.num_pieces; ++i)
bit_size += ctx.pieces[i].size;
- if (8 * (subobj_byte_offset + TYPE_LENGTH (subobj_type)) > bit_size)
+ /* Complain if the expression is larger than the size of the
+ outer type. */
+ if (bit_size > 8 * TYPE_LENGTH (type))
invalid_synthetic_pointer ();
c = allocate_piece_closure (per_cu, ctx.num_pieces, ctx.pieces,
diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog
index c16f201..d31679a 100644
--- a/gdb/testsuite/ChangeLog
+++ b/gdb/testsuite/ChangeLog
@@ -1,3 +1,7 @@
+2017-05-29 Tom Tromey <tom@tromey.com>
+
+ * gdb.dwarf2/shortpiece.exp: New file.
+
2017-05-21 Tom Tromey <tom@tromey.com>
PR rust/21466:
diff --git a/gdb/testsuite/gdb.dwarf2/shortpiece.exp b/gdb/testsuite/gdb.dwarf2/shortpiece.exp
new file mode 100644
index 0000000..8526a70
--- /dev/null
+++ b/gdb/testsuite/gdb.dwarf2/shortpiece.exp
@@ -0,0 +1,100 @@
+# Copyright 2017 Free Software Foundation, Inc.
+
+# This program 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.
+#
+# This program 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/>.
+
+load_lib dwarf.exp
+
+# This test can only be run on targets which support DWARF-2 and use gas.
+if {![dwarf2_support]} {
+ return 0
+}
+
+standard_testfile main.c shortpiece-dw.S
+
+# Make some DWARF for the test.
+set asm_file [standard_output_file $srcfile2]
+Dwarf::assemble $asm_file {
+ global pair
+
+ cu { addr_size 4 } {
+ compile_unit {} {
+ declare_labels int_label ushort_label struct_label
+
+ int_label: DW_TAG_base_type {
+ {DW_AT_byte_size 4 DW_FORM_udata}
+ {DW_AT_encoding @DW_ATE_unsigned}
+ {DW_AT_name "myint"}
+ }
+ ushort_label: DW_TAG_base_type {
+ {DW_AT_byte_size 2 DW_FORM_udata}
+ {DW_AT_encoding @DW_ATE_unsigned}
+ {DW_AT_name "myushort"}
+ }
+
+ struct_label: DW_TAG_structure_type {
+ {DW_AT_name "S"}
+ {DW_AT_byte_size 8 DW_FORM_udata}
+ } {
+ DW_TAG_member {
+ {DW_AT_name "a"}
+ {DW_AT_type :${int_label}}
+ {DW_AT_data_member_location 0 DW_FORM_udata}
+ }
+
+ DW_TAG_member {
+ {DW_AT_name "b"}
+ {DW_AT_type :${ushort_label}}
+ {DW_AT_data_member_location 4 DW_FORM_udata}
+ }
+ }
+
+ DW_TAG_variable {
+ {DW_AT_name "s1"}
+ {DW_AT_type :${struct_label}}
+ {DW_AT_external 1 DW_FORM_flag}
+ {DW_AT_location {
+ DW_OP_constu 1
+ DW_OP_stack_value
+ DW_OP_piece 4
+ DW_OP_constu 0
+ DW_OP_stack_value
+ DW_OP_piece 2
+ } SPECIAL_expr}
+ }
+
+ DW_TAG_variable {
+ {DW_AT_name "s2"}
+ {DW_AT_type :${struct_label}}
+ {DW_AT_external 1 DW_FORM_flag}
+ {DW_AT_location {
+ DW_OP_constu 1
+ DW_OP_stack_value
+ DW_OP_piece 4
+ DW_OP_constu 0
+ DW_OP_stack_value
+ DW_OP_piece 8
+ } SPECIAL_expr}
+ }
+ }
+ }
+}
+
+if { [prepare_for_testing "failed to prepare" ${testfile} \
+ [list $srcfile $asm_file] {nodebug}] } {
+ return -1
+}
+
+gdb_test "p s1" " = {a = 1, b = 0}"
+gdb_test "p s2" \
+ "access outside bounds of object referenced via synthetic pointer"
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [RFA] Fix size check in dwarf2_evaluate_loc_desc_full
2017-05-29 23:19 ` Tom Tromey
@ 2017-05-30 5:51 ` Simon Marchi
2017-06-27 18:23 ` Pedro Alves
0 siblings, 1 reply; 6+ messages in thread
From: Simon Marchi @ 2017-05-30 5:51 UTC (permalink / raw)
To: Tom Tromey; +Cc: gdb-patches
On 2017-05-30 01:19, Tom Tromey wrote:
> Simon> Would it be possible to test the error case as well by feeding
> bad
> Simon> DWARF info in the test case?
>
> Sure, here it is.
>
> Tom
Awesome!
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [RFA] Fix size check in dwarf2_evaluate_loc_desc_full
2017-05-30 5:51 ` Simon Marchi
@ 2017-06-27 18:23 ` Pedro Alves
2017-07-09 17:22 ` Tom Tromey
0 siblings, 1 reply; 6+ messages in thread
From: Pedro Alves @ 2017-06-27 18:23 UTC (permalink / raw)
To: Simon Marchi, Tom Tromey; +Cc: gdb-patches
On 05/30/2017 06:49 AM, Simon Marchi wrote:
> On 2017-05-30 01:19, Tom Tromey wrote:
>> Simon> Would it be possible to test the error case as well by feeding bad
>> Simon> DWARF info in the test case?
>>
>> Sure, here it is.
>>
>> Tom
>
> Awesome!
Agreed. I think we should put this in now.
Thanks,
Pedro Alves
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [RFA] Fix size check in dwarf2_evaluate_loc_desc_full
2017-06-27 18:23 ` Pedro Alves
@ 2017-07-09 17:22 ` Tom Tromey
0 siblings, 0 replies; 6+ messages in thread
From: Tom Tromey @ 2017-07-09 17:22 UTC (permalink / raw)
To: Pedro Alves; +Cc: Simon Marchi, Tom Tromey, gdb-patches
[...]
Pedro> Agreed. I think we should put this in now.
Thanks. I've rebased this and pushed it.
Tom
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2017-07-09 17:22 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-05-29 16:25 [RFA] Fix size check in dwarf2_evaluate_loc_desc_full Tom Tromey
2017-05-29 20:55 ` Simon Marchi
2017-05-29 23:19 ` Tom Tromey
2017-05-30 5:51 ` Simon Marchi
2017-06-27 18:23 ` Pedro Alves
2017-07-09 17:22 ` Tom Tromey
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).