diff options
author | Siva Chandra <sivachandra@chromium.org> | 2013-12-12 15:18:27 -0800 |
---|---|---|
committer | Siva Chandra <sivachandra@chromium.org> | 2013-12-12 15:21:53 -0800 |
commit | a16b0e220dfc49ed814e779d45faab84e31a4e42 (patch) | |
tree | 67f4c4a03309af6cd25582dd435d97781a24ca53 /gdb/testsuite | |
parent | ec0d6081a0144a61dfc79a10aaf2b96e29286180 (diff) | |
download | gdb-a16b0e220dfc49ed814e779d45faab84e31a4e42.zip gdb-a16b0e220dfc49ed814e779d45faab84e31a4e42.tar.gz gdb-a16b0e220dfc49ed814e779d45faab84e31a4e42.tar.bz2 |
2013-12-12 Siva Chandra Reddy <sivachandra@google.com>
PR python/16113
* NEWS (Python Scripting): Add entry for the new feature and the
new attribute of gdb.Field objects.
* python/py-type.c (gdbpy_is_field): New function
(convert_field): Add 'parent_type' attribute to gdb.Field
objects.
* python/py-value.c (valpy_getitem): Allow subscript value to be
a gdb.Field object.
(value_has_field): New function
(get_field_flag): New function
* python/python-internal.h (gdbpy_is_field): Add declaration.
testsuite/
* gdb.python/py-value-cc.cc: Improve test case.
* gdb.python/py-value-cc.exp: Add new tests to test usage of
gdb.Field objects as subscripts on gdb.Value objects.
doc/
* gdb.texinfo (Values From Inferior): Add a note about using
gdb.Field objects as subscripts on gdb.Value objects.
(Types In Python): Add description about the new attribute
"parent_type" of gdb.Field objects.
Diffstat (limited to 'gdb/testsuite')
-rw-r--r-- | gdb/testsuite/ChangeLog | 7 | ||||
-rw-r--r-- | gdb/testsuite/gdb.python/py-value-cc.cc | 30 | ||||
-rw-r--r-- | gdb/testsuite/gdb.python/py-value-cc.exp | 35 |
3 files changed, 72 insertions, 0 deletions
diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog index 869c8af..61f31d9 100644 --- a/gdb/testsuite/ChangeLog +++ b/gdb/testsuite/ChangeLog @@ -1,3 +1,10 @@ +2013-12-12 Siva Chandra Reddy <sivachandra@google.com> + + PR python/16113 + * gdb.python/py-value-cc.cc: Improve test case. + * gdb.python/py-value-cc.exp: Add new tests to test usage of + gdb.Field objects as subscripts on gdb.Value objects. + 2013-12-10 Doug Evans <dje@google.com> PR 16286 diff --git a/gdb/testsuite/gdb.python/py-value-cc.cc b/gdb/testsuite/gdb.python/py-value-cc.cc index c010fc9..80094ec 100644 --- a/gdb/testsuite/gdb.python/py-value-cc.cc +++ b/gdb/testsuite/gdb.python/py-value-cc.cc @@ -16,8 +16,21 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. */ class A { + public: + int a; }; +union U { + int a; + char c; +}; + +class B : public A { + public: + char a; +}; + +typedef B Btd; typedef int *int_ptr; int @@ -28,6 +41,22 @@ func (const A &a) int_ptr ptr = &val; int_ptr &int_ptr_ref = ptr; + B b; + B b1; + + b.a = 'a'; + b.A::a = 10; + + B *b_obj = &b1; + b_obj->a = 'b'; + b_obj->A::a = 100; + + B &b_ref = b1; + Btd &b_td = b1; + + U u; + u.a = 99; + return 0; /* Break here. */ } @@ -35,5 +64,6 @@ int main () { A obj; + return func (obj); } diff --git a/gdb/testsuite/gdb.python/py-value-cc.exp b/gdb/testsuite/gdb.python/py-value-cc.exp index 55c3b97..eacaf2e 100644 --- a/gdb/testsuite/gdb.python/py-value-cc.exp +++ b/gdb/testsuite/gdb.python/py-value-cc.exp @@ -44,3 +44,38 @@ gdb_test "python print (str(gdb.parse_and_eval(\"int_ptr_ref\").dereference().ty gdb_test "python print (str(gdb.parse_and_eval(\"int_ptr_ref\").referenced_value().type))" "int_ptr" gdb_test "python print (str(gdb.parse_and_eval(\"int_ptr_ref\").referenced_value().dereference()))" "10" gdb_test "python print (str(gdb.parse_and_eval(\"int_ptr_ref\").referenced_value().referenced_value()))" "10" + +# Tests for gdb.Value[gdb.Field] +gdb_test_no_output "python b = gdb.parse_and_eval('b')" "init b" +gdb_test_no_output "python b_fields = b.type.fields()" "init b_fields" +gdb_test_no_output "python b_obj = gdb.parse_and_eval('b_obj')" "init b_obj" +gdb_test_no_output "python b_ref = gdb.parse_and_eval('b_ref')" "init b_ref" +gdb_test_no_output "python b_td = gdb.parse_and_eval('b_td')" "init b_td" +gdb_test_no_output "python u = gdb.parse_and_eval('u')" "init u" +gdb_test_no_output "python u_fields = u.type.fields()" "init u_fields" + +gdb_test "python print(b\[b_fields\[1\]\])" "97 'a'" "b.a via field" +gdb_test "python print(b\[b_fields\[0\]\].type)" "A" \ + "type of b's base class via field" +gdb_test "python print(b\[b_fields\[0\]\]\['a'\])" "10" "b.A::a via field" + +gdb_test "python print(b_obj\[b_fields\[1\]\])" "98 'b'" "b_obj->a via field" +gdb_test "python print(b_obj\[b_fields\[0\]\].type.target())" "A" \ + "type of b_obj's base class via field" +gdb_test "python print(b_obj\[b_fields\[0\]\]\['a'\])" "100" \ + "b_obj->A::a via field" + +gdb_test "python print(b_ref\[b_fields\[1\]\])" "98 'b'" "b_ref.a via field" +gdb_test "python print(b_ref\[b_fields\[0\]\].type.target())" "A" \ + "type of b_ref's base class via field" +gdb_test "python print(b_ref\[b_fields\[0\]\]\['a'\])" "100" \ + "b_ref.A::a via field" + +gdb_test "python print(b_td\[b_fields\[1\]\])" "98 'b'" "b_td.a via field" +gdb_test "python print(b_td\[b_fields\[0\]\].type.target())" "A" \ + "type of b_td's base class via field" +gdb_test "python print(b_td\[b_fields\[0\]\]\['a'\])" "100" \ + "b_td.A::a via field" + +gdb_test "python print(u\[u_fields\[0\]\])" "99.*" "u's first field via field" +gdb_test "python print(u\[u_fields\[1\]\])" "99.*" "u's second field via field" |