Use bitpos and type to lookup a gdb.Field object when its name is 'None'.

PR python/15464
	PR python/16113
	* valops.c (value_struct_elt_bitpos): New function
	* py-type.c (convert_field): Set 'name' attribute of a gdb.Field
	object to 'None' if the field name is an empty string ("").
	* python/py-value.c (valpy_getitem): Use 'bitpos' and 'type'
	attribute to look for a field when 'name' is 'None'.
	(get_field_type): New function

	testsuite/
	* gdb.python/py-type.c: Enhance test case.
	* gdb.python/py-value-cc.cc: Likewise
	* gdb.python/py-type.exp: Add new tests.
	* gdb.python/py-value-cc.exp: Likewise
This commit is contained in:
Siva Chandra
2013-12-27 12:20:59 -08:00
parent 13aaf45454
commit b5b08fb4ff
10 changed files with 208 additions and 18 deletions

View File

@ -21,6 +21,12 @@ struct s
int b;
};
struct SS
{
union { int x; char y; };
union { int a; char b; };
};
typedef struct s TS;
TS ts;
@ -58,6 +64,7 @@ main ()
{
int ar[2] = {1,2};
struct s st;
struct SS ss;
#ifdef __cplusplus
C c;
c.c = 1;
@ -72,6 +79,8 @@ main ()
st.b = 5;
e = v2;
ss.x = 100;
return 0; /* break to inspect struct and array. */
}

View File

@ -85,6 +85,15 @@ 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 that unamed fields have 'None' for name.
gdb_py_test_silent_cmd "python ss = gdb.parse_and_eval('ss')" "init ss" 1
gdb_py_test_silent_cmd "python ss_fields = ss.type.fields()" \
"get fields from ss.type" 1
gdb_test "python print len(ss_fields)" "2" "Check length of ss_fields"
gdb_test "python print ss_fields\[0\].name is None" "True" \
"Check ss_fields\[0\].name"
gdb_test "python print ss_fields\[1\].name is None" "True" \
"Check ss_fields\[1\].name"
# Regression test for
# http://sourceware.org/bugzilla/show_bug.cgi?id=12070.
gdb_test "python print ('type' in dir(fields\[0\]))" "True" \

View File

@ -30,8 +30,21 @@ class B : public A {
char a;
};
struct X
{
union { int x; char y; };
union { int a; char b; };
};
union UU
{
union { int x; char y; };
union { int a; char b; };
};
typedef B Btd;
typedef int *int_ptr;
typedef X Xtd;
int
func (const A &a)
@ -57,6 +70,16 @@ func (const A &a)
U u;
u.a = 99;
X x;
x.x = 101;
x.a = 102;
UU uu;
uu.x = 1000;
X *x_ptr = &x;
Xtd *xtd = &x;
return 0; /* Break here. */
}

View File

@ -53,6 +53,14 @@ 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_no_output "python x = gdb.parse_and_eval('x')" "init x"
gdb_test_no_output "python x_fields = x.type.fields()" "init x_fields"
gdb_test_no_output "python uu = gdb.parse_and_eval('uu')" "init uu"
gdb_test_no_output "python uu_fields = uu.type.fields()" "init uu_fields"
gdb_test_no_output "python x_ptr = gdb.parse_and_eval('x_ptr')" "init x_ptr"
gdb_test_no_output "python xtd = gdb.parse_and_eval('xtd')" "init xtd"
gdb_test "python print(b\[b_fields\[1\]\])" "97 'a'" "b.a via field"
gdb_test "python print(b\[b_fields\[1\]\])" "97 'a'" "b.a via field"
gdb_test "python print(b\[b_fields\[0\]\].type)" "A" \
@ -79,3 +87,15 @@ gdb_test "python print(b_td\[b_fields\[0\]\]\['a'\])" "100" \
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"
gdb_test "python print len(x_fields)" "2" "number for fields in u"
gdb_test "python print x\[x_fields\[0\]\]\['x'\]" "101" "x.x via field"
gdb_test "python print x\[x_fields\[1\]\]\['a'\]" "102" "x.a via field"
gdb_test "python print x_ptr\[x_fields\[0\]\]\['x'\]" "101" "x_ptr->x via field"
gdb_test "python print x_ptr\[x_fields\[1\]\]\['a'\]" "102" "x_ptr->a via field"
gdb_test "python print xtd\[x_fields\[0\]\]\['x'\]" "101" "xtd->x via field"
gdb_test "python print xtd\[x_fields\[1\]\]\['a'\]" "102" "xtd->a via field"
gdb_test "python print len(uu_fields)" "2" "number of fields in uu"
gdb_test "python print uu\[uu_fields\[0\]\]\['x'\]" "1000" "uu.x via field"
gdb_test "python print uu\[uu_fields\[1\]\]\['a'\]" "1000" "uu.a via field"