aboutsummaryrefslogtreecommitdiff
path: root/gdb/testsuite/gdb.python
diff options
context:
space:
mode:
authorSimon Marchi <simon.marchi@polymtl.ca>2021-05-04 22:19:05 -0400
committerSimon Marchi <simon.marchi@polymtl.ca>2021-05-04 22:19:05 -0400
commitfa94b3a7c817a5e6615b24eeb3ac569b70af7e81 (patch)
treea46071ff1dde3524530cc0074d5e8f9e2154c6b2 /gdb/testsuite/gdb.python
parentbf06b2a2f9fdf4b267c22328ba0dc35c07919f5c (diff)
downloadgdb-fa94b3a7c817a5e6615b24eeb3ac569b70af7e81.zip
gdb-fa94b3a7c817a5e6615b24eeb3ac569b70af7e81.tar.gz
gdb-fa94b3a7c817a5e6615b24eeb3ac569b70af7e81.tar.bz2
gdb: update Type.fields doc based on actual GDB behavior
I noticed two errors in the Type.fields documentation: 1. It is possible to call `fields` on an array type, in which case it returns one field representing the array's range. It is not mentioned. 2. When calling `fields` on a type that doesn't have fields (by nature, like an int), GDB raises a TypeError. It does not return an empty sequence, as currently documented. Fix these, and change the text into a bullet list. I find it easier to read than one big paragraph. The first issue is already tested in gdb.python/py-type.exp, but the second one doesn't seem tested. Add a test in gdb.python/py-type.exp for it. gdb/doc/ChangeLog: * python.texi (Types In Python): Re-organize Type.fields doc. Mention handling of array types. Correct doc for when calling the method on another type. gdb/testsuite/ChangeLog: * gdb.python/py-type.exp (test_fields): Test calling fields on an int type. Change-Id: I11c688177504cb070b81a4446ac91dec50b56a22
Diffstat (limited to 'gdb/testsuite/gdb.python')
-rw-r--r--gdb/testsuite/gdb.python/py-type.exp3
1 files changed, 3 insertions, 0 deletions
diff --git a/gdb/testsuite/gdb.python/py-type.exp b/gdb/testsuite/gdb.python/py-type.exp
index 5c0c4f5..733b25d 100644
--- a/gdb/testsuite/gdb.python/py-type.exp
+++ b/gdb/testsuite/gdb.python/py-type.exp
@@ -175,6 +175,9 @@ proc test_fields {lang} {
gdb_test "python print (len (gdb.parse_and_eval ('a_function').type.fields ()))" "2"
gdb_test "python print (gdb.parse_and_eval ('a_function').type.fields ()\[0\].type)" "int"
gdb_test "python print (gdb.parse_and_eval ('a_function').type.fields ()\[1\].type)" "char"
+
+ # Test calling `fields` on a non-aggregate type.
+ gdb_test "python gdb.lookup_type('int').fields()" "TypeError: Type is not a structure, union, enum, or function type.*"
}
}