This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
[PATCH] gdb/testsuite/gdb.python: add test cases for anonymous members fix
- From: Li Yu <raise dot sail at gmail dot com>
- To: gdb-patches at sourceware dot org
- Cc: Paul Koning <paulkoning at comcast dot net>, Tom Tromey <tromey at redhat dot com>
- Date: Sat, 8 Oct 2011 13:42:03 +0800
- Subject: [PATCH] gdb/testsuite/gdb.python: add test cases for anonymous members fix
gdb.Type.fields() missed handling for anonymous members, I just sent a
patch to fix it, this patch adds some cases to test it.
See http://sourceware.org/ml/gdb-patches/2011-10/msg00218.html
Signed-off-by: Li Yu <raise.sail@gmail.com>
gdb/testsuite/gdb.python/:
2011-10-8 Li Yu <raise.sail@gmail.com>
* py-type.c/py-type.exp: Add test cases for bugfix of anonymous
members handling
py-type.c | 30 +++++++++++++++++++++++++++++-
py-type.exp | 18 ++++++++++++++++++
2 files changed, 47 insertions(+), 1 deletion(-)
diff --git a/gdb/testsuite/gdb.python/py-type.c b/gdb/testsuite/gdb.python/py-type.c
index b0dcc9d..2f24bec 100644
--- a/gdb/testsuite/gdb.python/py-type.c
+++ b/gdb/testsuite/gdb.python/py-type.c
@@ -47,6 +47,32 @@ enum E
{ v1, v2, v3
};
+struct A
+{
+ int a;
+ union {
+ int b0;
+ int b1;
+ union {
+ int bb0;
+ int bb1;
+ union {
+ int bbb0;
+ int bbb1;
+ };
+ };
+ };
+ int c;
+ union {
+ union {
+ int dd0;
+ int dd1;
+ };
+ int d2;
+ int d3;
+ };
+};
+
int
main ()
{
@@ -66,6 +92,8 @@ main ()
st.b = 5;
e = v2;
-
+
+ struct A a;
+
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 ec86586..786ef06 100644
--- a/gdb/testsuite/gdb.python/py-type.exp
+++ b/gdb/testsuite/gdb.python/py-type.exp
@@ -86,6 +86,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 fields usage for anonymous members of structs/union.
+ gdb_py_test_silent_cmd "print a" "print value" 1
+ gdb_py_test_silent_cmd "python a = gdb.history (0)" "get value from history" 1
+ gdb_py_test_silent_cmd "python fields = a.type.fields()" "get fields" 1
+ gdb_test "python print len(fields)" "12" "Check number of fields"
+ gdb_test "python print fields\[0\].name" "a" "Check structure field a name"
+ gdb_test "python print fields\[1\].name" "b0" "Check structure field b0 name"
+ gdb_test "python print fields\[2\].name" "b1" "Check structure field b1 name"
+ gdb_test "python print fields\[3\].name" "bb0" "Check structure field bb0 name"
+ gdb_test "python print fields\[4\].name" "bb1" "Check structure field bb1 name"
+ gdb_test "python print fields\[5\].name" "bbb0" "Check structure field bbb0 name"
+ gdb_test "python print fields\[6\].name" "bbb1" "Check structure field bbb1 name"
+ gdb_test "python print fields\[7\].name" "c" "Check structure field c name"
+ gdb_test "python print fields\[8\].name" "dd0" "Check structure field dd0 name"
+ gdb_test "python print fields\[9\].name" "dd1" "Check structure field dd1 name"
+ gdb_test "python print fields\[10\].name" "d2" "Check structure field d1 name"
+ gdb_test "python print fields\[11\].name" "d3" "Check structure field d2 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"