gdb/doc/
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.python / py-type.exp
index f7437d845997c91e6e568676c732aff50f540e7f..b5e6ff9df8a65cf828fb4ec1190111bf41422ffc 100644 (file)
@@ -64,6 +64,10 @@ proc runto_bp {bp} {
 proc test_fields {lang} {
   global gdb_prompt
 
+  # .fields() of a typedef should still return the underlying field list
+  gdb_test "python print len(gdb.parse_and_eval('ts').type.fields())" "2" \
+      "$lang typedef field list"
+
   if {$lang == "c++"} {
       # Test usage with a class
       gdb_py_test_silent_cmd "print c" "print value" 1
@@ -86,6 +90,24 @@ 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"
+  gdb_test "python print not not st.type" "True" "Check conversion to bool"
+
+  # Test rejection of mapping operations on scalar types
+  gdb_test "python print len (st.type\['a'\].type)" "TypeError: Type is not a structure, union, or enum type.*"
+  gdb_test "python print st.type\['a'\].type.has_key ('x')" "TypeError: Type is not a structure, union, or enum type.*"
+  gdb_test "python print st.type\['a'\].type.keys ()" "TypeError: Type is not a structure, union, or enum type.*"
+  gdb_test "python print st.type\['a'\].type\['x'\]" "TypeError: Type is not a structure, union, or enum type.*"
+
+  # Test conversion to bool on scalar types
+  gdb_test "python print not not st.type\['a'\].type" "True"
+  
   # 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 +123,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
@@ -156,7 +193,7 @@ proc test_template {} {
     gdb_test "python print isinstance(ttype.template_argument(1), gdb.Value)" \
        "True"
 
-    setup_kfail "gcc/41736" *-*-*
+    setup_xfail "gcc/41736" *-*-*
     gdb_test "python print ttype.template_argument(2)" "&C::c"
 }
 
@@ -169,6 +206,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 +216,4 @@ test_fields "c++"
 test_base_class
 test_range
 test_template
+test_enums
This page took 0.024386 seconds and 4 git commands to generate.