* [PATCH][exp] Interpret size of vla with unknown size as <optimized out>
@ 2018-07-18 13:27 Tom de Vries
2018-07-25 14:22 ` [PING][PATCH][exp] " Tom de Vries
0 siblings, 1 reply; 3+ messages in thread
From: Tom de Vries @ 2018-07-18 13:27 UTC (permalink / raw)
To: gdb-patches
Hi,
at -O3 -g -gstrict-dwarf, gcc generates for an optimized out vla 'a' a
DW_TAG_variable with type DW_TAG_array_type containing one
DW_TAG_subrange_type, but without DW_AT_upper_bound or DW_AT_count, which
makes the upper bound value 'unknown':
...
.uleb128 0x15 # (DIE (0x161) DW_TAG_variable)
.long 0xec # DW_AT_abstract_origin
.long 0x170 # DW_AT_type
...
.uleb128 0xa # (DIE (0x170) DW_TAG_array_type)
.long 0x110 # DW_AT_type
.long 0x17f # DW_AT_sibling
.uleb128 0x17 # (DIE (0x179) DW_TAG_subrange_type)
.long 0xc6 # DW_AT_type
.byte 0 # end of children of DIE 0x170
...
But gdb prints '0' for the size of 'a':
...
/gdb ./vla-1.exe -batch -ex "b f1" -ex "run" -ex "p sizeof(a)"
Breakpoint 1 at 0x4004c0: f1. (2 locations)
Breakpoint 1, f1 (i=<optimized out>) at vla-1.c:18
18 }
$1 = 0
...
while <optimized out> would be more appropriate.
This patch fixes that in evaluate_subexp_for_sizeof.
Build and reg-tested on x86_64-linux.
OK for trunk?
Thanks,
- Tom
[gdb/exp] Interpret size of vla with unknown size as <optimized out>
2018-07-06 Tom de Vries <tdevries@suse.de>
* eval.c (evaluate_subexp_for_sizeof): Interpret size of dynamic type
with undefined upper bound as <optimized out>.
* gdb.base/vla-optimized-out-o3.c: New test.
* gdb.base/vla-optimized-out-o3.exp: New file.
---
gdb/eval.c | 2 ++
gdb/testsuite/gdb.base/vla-optimized-out-o3.c | 34 +++++++++++++++++++++
gdb/testsuite/gdb.base/vla-optimized-out-o3.exp | 40 +++++++++++++++++++++++++
3 files changed, 76 insertions(+)
diff --git a/gdb/eval.c b/gdb/eval.c
index 9db6e7c69d..0495a11bfd 100644
--- a/gdb/eval.c
+++ b/gdb/eval.c
@@ -3145,6 +3145,8 @@ evaluate_subexp_for_sizeof (struct expression *exp, int *pos,
{
val = evaluate_subexp (NULL_TYPE, exp, pos, EVAL_NORMAL);
type = value_type (val);
+ if (TYPE_HIGH_BOUND_UNDEFINED (TYPE_INDEX_TYPE (type)))
+ return allocate_optimized_out_value (size_type);
}
else
(*pos) += 4;
diff --git a/gdb/testsuite/gdb.base/vla-optimized-out-o3.c b/gdb/testsuite/gdb.base/vla-optimized-out-o3.c
new file mode 100644
index 0000000000..799a1f7b10
--- /dev/null
+++ b/gdb/testsuite/gdb.base/vla-optimized-out-o3.c
@@ -0,0 +1,34 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+ Copyright 2018 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/>. */
+
+int __attribute__((noinline))
+f1 (int i)
+{
+ char a[i + 1];
+ a[0] = 5;
+ return a[0];
+}
+
+int
+main (void)
+{
+ volatile int j;
+ int i = 5;
+ asm volatile ("" : "=r" (i) : "0" (i));
+ j = f1 (i);
+ return 0;
+}
diff --git a/gdb/testsuite/gdb.base/vla-optimized-out-o3.exp b/gdb/testsuite/gdb.base/vla-optimized-out-o3.exp
new file mode 100644
index 0000000000..bc435cc4aa
--- /dev/null
+++ b/gdb/testsuite/gdb.base/vla-optimized-out-o3.exp
@@ -0,0 +1,40 @@
+# Copyright 2018 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/>.
+
+# Check whether we can determine the size of an optimized-out vla.
+
+standard_testfile
+
+if { [prepare_for_testing "failed to prepare" $testfile $srcfile \
+ {debug optimize=-O3 additional_flags=-gstrict-dwarf}] } {
+ return -1
+}
+
+proc vla_optimized_out { } {
+ if ![runto f1] {
+ fail "can't run to f1"
+ return
+ }
+
+ gdb_test "p a" \
+ { = <optimized out>} \
+ "printed optimized out vla"
+
+ gdb_test "p sizeof (a)" \
+ { = <optimized out>} \
+ "printed optimized out size of optimized out vla"
+}
+
+vla_optimized_out
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PING][PATCH][exp] Interpret size of vla with unknown size as <optimized out>
2018-07-18 13:27 [PATCH][exp] Interpret size of vla with unknown size as <optimized out> Tom de Vries
@ 2018-07-25 14:22 ` Tom de Vries
2018-07-27 15:18 ` Tom Tromey
0 siblings, 1 reply; 3+ messages in thread
From: Tom de Vries @ 2018-07-25 14:22 UTC (permalink / raw)
To: gdb-patches
Hi,
at -O3 -g -gstrict-dwarf, gcc generates for an optimized out vla 'a' a
DW_TAG_variable with type DW_TAG_array_type containing one
DW_TAG_subrange_type, but without DW_AT_upper_bound or DW_AT_count, which
makes the upper bound value 'unknown':
...
.uleb128 0x15 # (DIE (0x161) DW_TAG_variable)
.long 0xec # DW_AT_abstract_origin
.long 0x170 # DW_AT_type
...
.uleb128 0xa # (DIE (0x170) DW_TAG_array_type)
.long 0x110 # DW_AT_type
.long 0x17f # DW_AT_sibling
.uleb128 0x17 # (DIE (0x179) DW_TAG_subrange_type)
.long 0xc6 # DW_AT_type
.byte 0 # end of children of DIE 0x170
...
But gdb prints '0' for the size of 'a':
...
/gdb ./vla-1.exe -batch -ex "b f1" -ex "run" -ex "p sizeof(a)"
Breakpoint 1 at 0x4004c0: f1. (2 locations)
Breakpoint 1, f1 (i=<optimized out>) at vla-1.c:18
18 }
$1 = 0
...
while <optimized out> would be more appropriate.
This patch fixes that in evaluate_subexp_for_sizeof.
Build and reg-tested on x86_64-linux.
OK for trunk?
Thanks,
- Tom
[gdb/exp] Interpret size of vla with unknown size as <optimized out>
2018-07-06 Tom de Vries <tdevries@suse.de>
* eval.c (evaluate_subexp_for_sizeof): Interpret size of dynamic type
with undefined upper bound as <optimized out>.
* gdb.base/vla-optimized-out-o3.c: New test.
* gdb.base/vla-optimized-out-o3.exp: New file.
---
gdb/eval.c | 2 ++
gdb/testsuite/gdb.base/vla-optimized-out-o3.c | 34 +++++++++++++++++++++
gdb/testsuite/gdb.base/vla-optimized-out-o3.exp | 40
+++++++++++++++++++++++++
3 files changed, 76 insertions(+)
diff --git a/gdb/eval.c b/gdb/eval.c
index 9db6e7c69d..0495a11bfd 100644
--- a/gdb/eval.c
+++ b/gdb/eval.c
@@ -3145,6 +3145,8 @@ evaluate_subexp_for_sizeof (struct expression
*exp, int *pos,
{
val = evaluate_subexp (NULL_TYPE, exp, pos, EVAL_NORMAL);
type = value_type (val);
+ if (TYPE_HIGH_BOUND_UNDEFINED (TYPE_INDEX_TYPE (type)))
+ return allocate_optimized_out_value (size_type);
}
else
(*pos) += 4;
diff --git a/gdb/testsuite/gdb.base/vla-optimized-out-o3.c
b/gdb/testsuite/gdb.base/vla-optimized-out-o3.c
new file mode 100644
index 0000000000..799a1f7b10
--- /dev/null
+++ b/gdb/testsuite/gdb.base/vla-optimized-out-o3.c
@@ -0,0 +1,34 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+ Copyright 2018 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/>. */
+
+int __attribute__((noinline))
+f1 (int i)
+{
+ char a[i + 1];
+ a[0] = 5;
+ return a[0];
+}
+
+int
+main (void)
+{
+ volatile int j;
+ int i = 5;
+ asm volatile ("" : "=r" (i) : "0" (i));
+ j = f1 (i);
+ return 0;
+}
diff --git a/gdb/testsuite/gdb.base/vla-optimized-out-o3.exp
b/gdb/testsuite/gdb.base/vla-optimized-out-o3.exp
new file mode 100644
index 0000000000..bc435cc4aa
--- /dev/null
+++ b/gdb/testsuite/gdb.base/vla-optimized-out-o3.exp
@@ -0,0 +1,40 @@
+# Copyright 2018 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/>.
+
+# Check whether we can determine the size of an optimized-out vla.
+
+standard_testfile
+
+if { [prepare_for_testing "failed to prepare" $testfile $srcfile \
+ {debug optimize=-O3 additional_flags=-gstrict-dwarf}] } {
+ return -1
+}
+
+proc vla_optimized_out { } {
+ if ![runto f1] {
+ fail "can't run to f1"
+ return
+ }
+
+ gdb_test "p a" \
+ { = <optimized out>} \
+ "printed optimized out vla"
+
+ gdb_test "p sizeof (a)" \
+ { = <optimized out>} \
+ "printed optimized out size of optimized out vla"
+}
+
+vla_optimized_out
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PING][PATCH][exp] Interpret size of vla with unknown size as <optimized out>
2018-07-25 14:22 ` [PING][PATCH][exp] " Tom de Vries
@ 2018-07-27 15:18 ` Tom Tromey
0 siblings, 0 replies; 3+ messages in thread
From: Tom Tromey @ 2018-07-27 15:18 UTC (permalink / raw)
To: Tom de Vries; +Cc: gdb-patches
>>>>> "Tom" == Tom de Vries <tdevries@suse.de> writes:
Tom> [gdb/exp] Interpret size of vla with unknown size as <optimized out>
Tom> 2018-07-06 Tom de Vries <tdevries@suse.de>
Tom> * eval.c (evaluate_subexp_for_sizeof): Interpret size of dynamic type
Tom> with undefined upper bound as <optimized out>.
Tom> * gdb.base/vla-optimized-out-o3.c: New test.
Tom> * gdb.base/vla-optimized-out-o3.exp: New file.
Thanks. This seems like a reasonable approach to me.
Please check it in.
Tom
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2018-07-27 15:18 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-07-18 13:27 [PATCH][exp] Interpret size of vla with unknown size as <optimized out> Tom de Vries
2018-07-25 14:22 ` [PING][PATCH][exp] " Tom de Vries
2018-07-27 15:18 ` 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).