forked from Imagelibrary/binutils-gdb
Record nested types
GDB currently does not track types defined in classes. Consider:
class A
{
public:
class B
{
public:
class C { };
};
};
(gdb) ptype A
type = class A {
<no data fields>
}
This patch changes this behavior so that GDB records these nested types
and displays them to the user when he has set the (new) "print type"
option "nested-type-limit."
Example:
(gdb) set print type nested-type-limit 1
(gdb) ptype A
type = class A {
<no data fields>
class A::B {
<no data fields>
};
}
(gdb) set print type nested-type-limit 2
type = class A {
<no data fields>
class A::B {
<no data fields>
class A::B::C {
<no data fields>
};
};
}
By default, the code maintains the status quo, that is, it will not print
any nested type definitions at all.
Testing is carried out via cp_ptype_class which required quite a bit of
modification to permit recursive calling (for the nested types). This
was most easily facilitated by turning the ptype command output into a
queue. Upshot: the test suite now has stack and queue data structures that
may be used by test writers.
gdb/ChangeLog
* NEWS (New commands): Mention set/show print type nested-type-limit.
* c-typeprint.c (c_type_print_base): Print out nested types.
* dwarf2read.c (struct typedef_field_list): Rename to ...
(struct decl_field_list): ... this. Change all uses.
(struct field_info) <nested_types_list, nested_types_list_count>:
New fields.
(add_partial_symbol): Look for nested type definitions in C++, too.
(dwarf2_add_typedef): Rename to ...
(dwarf2_add_type_defn): ... this.
(type_can_define_types): New function.
Update assertion to use type_can_define_types.
Permit NULL for a field's name.
(process_structure_scope): Handle child DIEs of types that can
define types.
Copy the list of nested types into the type struct.
* gdbtypes.h (struct typedef_field): Rename to ...
(struct decl_field): ... this. Change all uses.
[is_protected, is_private]: New fields.
(struct cplus_struct_type) <nested_types, nested_types_count>: New
fields.
(TYPE_NESTED_TYPES_ARRAY, TYPE_NESTED_TYPES_FIELD)
(TYPE_NESTED_TYPES_FIELD_NAME, TYPE_NESTED_TYPES_FIELD_TYPE)
(TYPE_NESTED_TYPES_COUNT, TYPE_NESTED_TYPES_FIELD_PROTECTED)
(TYPE_NESTED_TYPES_FIELD_PRIVATE): New macros.
* typeprint.c (type_print_raw_options, default_ptype_flags): Add
default value for print_nested_type_limit.
(print_nested_type_limit): New static variable.
(set_print_type_nested_types, show_print_type_nested_types): New
functions.
(_initialize_typeprint): Register new commands for set/show
`print-nested-type-limit'.
* typeprint.h (struct type_print_options) [print_nested_type_limit]:
New field.
gdb/testsuite/ChangeLog
* gdb.cp/nested-types.cc: New file.
* gdb.cp/nested-types.exp: New file.
* lib/cp-support.exp: Load data-structures.exp library.
(debug_cp_test_ptype_class): New global.
(cp_ptype_class_verbose, next_line): New procedures.
(cp_test_ptype_class): Add and document new parameter `recursive_qid'.
Add and document new return value.
Switch the list of lines to a queue.
Add support for new `type' key for nested type definitions.
Add debugging/troubleshooting messages.
* lib/data-structures.exp: New file.
gdb/doc/ChangeLog
* gdb.texinfo (Symbols): Document "set print type nested-type-limit"
and "show print type nested-type-limit".
This commit is contained in:
@@ -863,7 +863,7 @@ struct fn_field
|
||||
|
||||
};
|
||||
|
||||
struct typedef_field
|
||||
struct decl_field
|
||||
{
|
||||
/* * Unqualified name to be prefixed by owning class qualified
|
||||
name. */
|
||||
@@ -978,10 +978,17 @@ struct cplus_struct_type
|
||||
/* * typedefs defined inside this class. typedef_field points to
|
||||
an array of typedef_field_count elements. */
|
||||
|
||||
struct typedef_field *typedef_field;
|
||||
struct decl_field *typedef_field;
|
||||
|
||||
unsigned typedef_field_count;
|
||||
|
||||
/* * The nested types defined by this type. nested_types points to
|
||||
an array of nested_types_count elements. */
|
||||
|
||||
struct decl_field *nested_types;
|
||||
|
||||
unsigned nested_types_count;
|
||||
|
||||
/* * The template arguments. This is an array with
|
||||
N_TEMPLATE_ARGUMENTS elements. This is NULL for non-template
|
||||
classes. */
|
||||
@@ -1424,6 +1431,21 @@ extern void set_type_vptr_basetype (struct type *, struct type *);
|
||||
#define TYPE_TYPEDEF_FIELD_PRIVATE(thistype, n) \
|
||||
TYPE_TYPEDEF_FIELD (thistype, n).is_private
|
||||
|
||||
#define TYPE_NESTED_TYPES_ARRAY(thistype) \
|
||||
TYPE_CPLUS_SPECIFIC (thistype)->nested_types
|
||||
#define TYPE_NESTED_TYPES_FIELD(thistype, n) \
|
||||
TYPE_CPLUS_SPECIFIC (thistype)->nested_types[n]
|
||||
#define TYPE_NESTED_TYPES_FIELD_NAME(thistype, n) \
|
||||
TYPE_NESTED_TYPES_FIELD (thistype, n).name
|
||||
#define TYPE_NESTED_TYPES_FIELD_TYPE(thistype, n) \
|
||||
TYPE_NESTED_TYPES_FIELD (thistype, n).type
|
||||
#define TYPE_NESTED_TYPES_COUNT(thistype) \
|
||||
TYPE_CPLUS_SPECIFIC (thistype)->nested_types_count
|
||||
#define TYPE_NESTED_TYPES_FIELD_PROTECTED(thistype, n) \
|
||||
TYPE_NESTED_TYPES_FIELD (thistype, n).is_protected
|
||||
#define TYPE_NESTED_TYPES_FIELD_PRIVATE(thistype, n) \
|
||||
TYPE_NESTED_TYPES_FIELD (thistype, n).is_private
|
||||
|
||||
#define TYPE_IS_OPAQUE(thistype) \
|
||||
(((TYPE_CODE (thistype) == TYPE_CODE_STRUCT) \
|
||||
|| (TYPE_CODE (thistype) == TYPE_CODE_UNION)) \
|
||||
|
||||
Reference in New Issue
Block a user