From 7a81bdbf676fd20c7a3f6aa3d1e09bcffacbaea4 Mon Sep 17 00:00:00 2001 From: Paul Koning Date: Wed, 28 Sep 2011 20:06:01 +0000 Subject: [PATCH] * gdb.python/py-type.c (enum E): New. * gdb.python/py-type.exp (test_fields): Add tests for Python mapping access to fields. (test_enums): New test for field access on enums. --- gdb/testsuite/ChangeLog | 7 +++++++ gdb/testsuite/gdb.python/py-type.c | 9 ++++++++- gdb/testsuite/gdb.python/py-type.exp | 25 +++++++++++++++++++++++++ 3 files changed, 40 insertions(+), 1 deletion(-) diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog index c2cacb0a2a9..9eebcda8432 100644 --- a/gdb/testsuite/ChangeLog +++ b/gdb/testsuite/ChangeLog @@ -1,3 +1,10 @@ +2011-09-28 Paul Koning + + * gdb.python/py-type.c (enum E): New. + * gdb.python/py-type.exp (test_fields): Add tests for Python + mapping access to fields. + (test_enums): New test for field access on enums. + 2011-09-27 Stan Shebs * gdb.trace/collection.exp: Test collection of $_ret. diff --git a/gdb/testsuite/gdb.python/py-type.c b/gdb/testsuite/gdb.python/py-type.c index a92d5d2f930..b0dcc9dc8fd 100644 --- a/gdb/testsuite/gdb.python/py-type.c +++ b/gdb/testsuite/gdb.python/py-type.c @@ -43,6 +43,10 @@ Temargs temvar; #endif +enum E +{ v1, v2, v3 +}; + int main () { @@ -56,9 +60,12 @@ main () d.e = 3; d.f = 4; #endif - + enum E e; + st.a = 3; st.b = 5; + e = v2; + return 0; /* break to inspect struct and array. */ } diff --git a/gdb/testsuite/gdb.python/py-type.exp b/gdb/testsuite/gdb.python/py-type.exp index f7437d84599..ec86586f0af 100644 --- a/gdb/testsuite/gdb.python/py-type.exp +++ b/gdb/testsuite/gdb.python/py-type.exp @@ -86,6 +86,14 @@ proc test_fields {lang} { gdb_test "python print fields\[0\].name" "a" "Check structure field a name" gdb_test "python print fields\[1\].name" "b" "Check structure field b name" + # Test Python mapping behavior of gdb.Type for structs/classes + gdb_test "python print len(st.type)" "2" "Check number of fields" + gdb_test "python print st.type\['a'\].name" "a" "Check fields lookup by name" + gdb_test "python print \[v.bitpos for v in st.type.itervalues()\]" {\[0L, 32L\]} "Check fields iteration over values" + gdb_test "python print \[(n, v.bitpos) for (n, v) in st.type.items()\]" {\[\('a', 0L\), \('b', 32L\)\]} "Check fields items list" + gdb_test "python print 'a' in st.type" "True" "Check field name exists test" + gdb_test "python print 'nosuch' in st.type" "False" "Check field name nonexists test" + # Test regression PR python/10805 gdb_py_test_silent_cmd "print ar" "print value" 1 gdb_py_test_silent_cmd "python ar = gdb.history (0)" "get value from history" 1 @@ -101,6 +109,21 @@ proc test_fields {lang} { gdb_test "python print ar\[0\].type == ar\[0\].type" "True" } +proc test_enums {} { + gdb_py_test_silent_cmd "print e" "print value" 1 + gdb_py_test_silent_cmd "python e = gdb.history (0)" "get value from history" 1 + gdb_py_test_silent_cmd "python fields = e.type.fields()" "get value from history" 1 + gdb_test "python print len(fields)" "3" "Check the number of enum fields" + gdb_test "python print fields\[0\].name" "v1" "Check enum field name" + gdb_test "python print fields\[1\].name" "v2" "Check enum field name" + + # Ditto but by mapping operations + gdb_test "python print len(e.type)" "3" "Check the number of enum fields" + gdb_test "python print e.type\['v1'\].name" "v1" "Check enum field lookup by name" + gdb_test "python print e.type\['v3'\].name" "v3" "Check enum field lookup by name" + gdb_test "python print \[v.bitpos for v in e.type.itervalues()\]" {\[0L, 1L, 2L\]} "Check num fields iteration over values" + gdb_test "python print \[(n, v.bitpos) for (n, v) in e.type.items()\]" {\[\('v1', 0L\), \('v2', 1L\), \('v3', 2L\)\]} "Check enum fields items list" +} proc test_base_class {} { gdb_py_test_silent_cmd "print d" "print value" 1 gdb_py_test_silent_cmd "python d = gdb.history (0)" "get value from history" 1 @@ -169,6 +192,7 @@ if { [skip_python_tests] } { continue } runto_bp "break to inspect struct and array." test_fields "c" +test_enums # Perform C++ Tests. build_inferior "${binfile}-cxx" "c++" @@ -178,3 +202,4 @@ test_fields "c++" test_base_class test_range test_template +test_enums -- 2.30.2