[5/5] Add new test internalvar.exp

Message ID 1437072684-26565-5-git-send-email-simon.marchi@ericsson.com
State New, archived
Headers

Commit Message

Simon Marchi July 16, 2015, 6:51 p.m. UTC
  I wrote this test While doing the work that lead to the previous patch,
so I thought I would contribute it upstream.  From what I can see, there
is no test currently to verify operations on internal variables (please
point me to it if I'm wrong).

gdb/testsuite/ChangeLog:

	* gdb.base/internalvar.exp: New file.
	* gdb.base/internalvar.c: New file.
---
 gdb/testsuite/gdb.base/internalvar.c   | 45 ++++++++++++++++++++++++++++++++++
 gdb/testsuite/gdb.base/internalvar.exp | 42 +++++++++++++++++++++++++++++++
 2 files changed, 87 insertions(+)
 create mode 100644 gdb/testsuite/gdb.base/internalvar.c
 create mode 100644 gdb/testsuite/gdb.base/internalvar.exp
  

Comments

Pedro Alves July 24, 2015, 11:41 a.m. UTC | #1
On 07/16/2015 07:51 PM, Simon Marchi wrote:
> I wrote this test While doing the work that lead to the previous patch,
> so I thought I would contribute it upstream.  From what I can see, there
> is no test currently to verify operations on internal variables (please
> point me to it if I'm wrong).

Pedantically, it'd be better to call these convenience vars.

Convenience var specifics are tested in gdbvars.exp.  Likely we have this
more covered on the C++ tests.  Something like what you're testing, but
for bitfields, is done in bitfields.exp.  structs.exp is for infcalls, which IIRC
your target doesn't do.  I guess one could hack a bug in the value field access
code somewhere in value.c/valops.c/valprint.c, and the find the test that
has more failures.  :-)

In any case, more tests can't hurt.  :-)

AFAICS, this is really more about getting value field offsets and contents
right than convenience vars per se, which end up just exercising the
routine value paths.

You could put these in gdb.base/struct3.c|.exp, which if you look
at struct3.c, it's structure is similar, with an inner and outer struct too.
Otherwise, I'd suggest renaming the test in the value
direction -- value-fields.exp, value-units.exp, value-offsets.exp or
some such.

I'd also suggest making the describing comment be something like:

# Test accessing different fields of structures, inner structures,
# arrays, etc., and make sure GDB prints the right contents.  Handy to
# exercise the value machinery code that handles host vs target bytes/memory
# units.

Anyway, the test code itself looks good to me, with:

> ---
>  gdb/testsuite/gdb.base/internalvar.c   | 45 ++++++++++++++++++++++++++++++++++
>  gdb/testsuite/gdb.base/internalvar.exp | 42 +++++++++++++++++++++++++++++++
>  2 files changed, 87 insertions(+)
>  create mode 100644 gdb/testsuite/gdb.base/internalvar.c
>  create mode 100644 gdb/testsuite/gdb.base/internalvar.exp
> 
> diff --git a/gdb/testsuite/gdb.base/internalvar.c b/gdb/testsuite/gdb.base/internalvar.c
> new file mode 100644
> index 0000000..2aadc11
> --- /dev/null
> +++ b/gdb/testsuite/gdb.base/internalvar.c
> @@ -0,0 +1,45 @@

Copyright header missing.

Thanks,
Pedro Alves
  

Patch

diff --git a/gdb/testsuite/gdb.base/internalvar.c b/gdb/testsuite/gdb.base/internalvar.c
new file mode 100644
index 0000000..2aadc11
--- /dev/null
+++ b/gdb/testsuite/gdb.base/internalvar.c
@@ -0,0 +1,45 @@ 
+struct inner
+{
+  int a;
+  int b[2];
+};
+
+struct outer
+{
+  int x;
+  int y;
+
+  struct inner inner;
+
+  int z[2];
+};
+
+struct outer o;
+struct inner i;
+
+void
+break_here (void)
+{
+}
+
+int
+main (void)
+{
+  o.x = 0x1111;
+  o.y = 0x2222;
+
+  o.inner.a = 0x3333;
+  o.inner.b[0] = 0x4444;
+  o.inner.b[1] = 0x5555;
+
+  o.z[0] = 0x6666;
+  o.z[1] = 0x7777;
+
+  i.a = 0x8888;
+  i.b[0] = 0x9999;
+  i.b[1] = 0xaaaa;
+
+  break_here ();
+
+  return 0;
+}
diff --git a/gdb/testsuite/gdb.base/internalvar.exp b/gdb/testsuite/gdb.base/internalvar.exp
new file mode 100644
index 0000000..701cc16
--- /dev/null
+++ b/gdb/testsuite/gdb.base/internalvar.exp
@@ -0,0 +1,42 @@ 
+# Copyright 2015 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/>.
+
+#
+# Test operations on internal variables.
+#
+
+standard_testfile
+
+if {[prepare_for_testing ${testfile}.exp ${testfile}]} {
+    return -1
+}
+
+runto break_here
+
+gdb_test_no_output "set \$a = 0x1234"
+gdb_test "p/x \$a" " = 0x1234"
+
+gdb_test_no_output "set \$s = o"
+gdb_test "p/x \$s" " = {x = 0x1111, y = 0x2222, inner = {a = 0x3333, b = \\{0x4444, 0x5555}}, z = \\{0x6666, 0x7777}}"
+gdb_test "p/x \$s.inner" " = {a = 0x3333, b = \\{0x4444, 0x5555}}"
+gdb_test "p/x \$s.inner.b\[1\]" " = 0x5555"
+
+gdb_test_no_output "set \$s.inner = i"
+gdb_test "p/x \$s" " = {x = 0x1111, y = 0x2222, inner = {a = 0x8888, b = \\{0x9999, 0xaaaa}}, z = \\{0x6666, 0x7777}}"
+
+gdb_test_no_output "set \$s.x = 0xffff"
+gdb_test_no_output "set \$s.inner.b\[1\] = 0xeeee"
+gdb_test_no_output "set \$s.z\[1\] = 0xdddd"
+gdb_test "p/x \$s" " = {x = 0xffff, y = 0x2222, inner = {a = 0x8888, b = \\{0x9999, 0xeeee}}, z = \\{0x6666, 0xdddd}}"