22#include "gdbsupport/preprocessor.h"
26#include "gdbsupport/gdb_assert.h"
54 bool strip_artificial);
58gdb::unique_xmalloc_ptr<char>
61 if (natural ==
nullptr)
68 return make_unique_xstrdup (natural);
73static enum gcc_cp_symbol_kind
77 return GCC_CP_ACCESS_PROTECTED;
79 return GCC_CP_ACCESS_PRIVATE;
82 return GCC_CP_ACCESS_PUBLIC;
88enum gcc_cp_symbol_kind
91 gdb_assert (
type->
code () == TYPE_CODE_STRUCT);
95 return GCC_CP_ACCESS_PUBLIC;
100 return GCC_CP_ACCESS_PROTECTED;
102 return GCC_CP_ACCESS_PRIVATE;
104 return GCC_CP_ACCESS_PUBLIC;
112 for (
const auto &comp: scope)
114 const char *
symbol = (comp.bsymbol.symbol !=
nullptr
115 ? comp.bsymbol.symbol->natural_name ()
130 if (type_name ==
nullptr)
137 const char *p = type_name;
138 std::string lookup_name;
144 std::string s (p, len);
150 if (!lookup_name.empty ())
158 if (bsymbol.
symbol !=
nullptr)
162 scope.push_back (comp);
181 internal_error (_(
"malformed TYPE_NAME during parsing"));
213 if (lhs.size () != rhs.size ())
216 for (
int i = 0; i < lhs.size (); ++i)
218 if (lhs[i] != rhs[i])
232 if (lhs.size () != rhs.size ())
235 for (
int i = 0; i < lhs.size (); ++i)
237 if (lhs[i] != rhs[i])
261 host_address_to_string (&
m_scopes.back ()));
265 plugin ().push_namespace (
"");
273 gdb_assert (comp.bsymbol.symbol->type ()->code ()
274 == TYPE_CODE_NAMESPACE);
276 const char *ns = (comp.name == CP_ANONYMOUS_NAMESPACE_STR ? nullptr
277 : comp.name.c_str ());
279 this->plugin ().push_namespace (ns);
287 "scopes are identical\n");
308 host_address_to_string (¤t));
313 (current.begin (),current.end () - 1,
315 gdb_assert (comp.bsymbol.symbol->type ()->code ()
316 == TYPE_CODE_NAMESPACE);
317 this->plugin ().pop_binding_level (comp.name.c_str ());
327 "identical scopes -- not leaving scope\n");
349 || (
m_scopes.back ().back ().bsymbol.symbol
376 scope.m_pushed =
false;
388 scope.push_back (comp);
393 gdb_assert (
scope.size () > 0);
401 (gcc_type base,
enum gcc_cp_ref_qualifiers rquals)
403 return this->
plugin ().build_reference_type (base, rquals);
414 enum gcc_cp_ref_qualifiers quals = GCC_CP_REF_QUAL_NONE;
418 quals = GCC_CP_REF_QUAL_LVALUE;
420 case TYPE_CODE_RVALUE_REF:
421 quals = GCC_CP_REF_QUAL_RVALUE;
424 gdb_assert_not_reached (
"unexpected type code for reference type");
435 return plugin ().build_pointer_type (target);
458 if (!
range->bounds ()->low.is_constant ())
460 const char *s = _(
"array type with non-constant"
461 " lower bound is not supported");
463 return instance->
plugin ().error (s);
466 if (
range->bounds ()->low.const_val () != 0)
468 const char *s = _(
"cannot convert array type with "
469 "non-zero lower bound to C");
471 return instance->
plugin ().error (s);
479 const char *s = _(
"variably-sized vector type is not supported");
481 return instance->
plugin ().error (s);
484 std::string upper_bound
486 return instance->
plugin ().build_vla_array_type (element_type,
487 upper_bound.c_str ());
491 LONGEST low_bound, high_bound, count;
497 gdb_assert (low_bound == 0);
498 count = high_bound + 1;
502 return instance->
plugin ().build_vector_type (element_type, count);
504 return instance->
plugin ().build_array_type (element_type, count);
515 enum gcc_cp_symbol_kind nested_access)
522 gdb::unique_xmalloc_ptr<char>
name
532 GCC_CP_SYMBOL_TYPEDEF | nested_access,
533 typedef_type, 0, 0,
nullptr, 0);
610 field_type,
nullptr, physaddr,
nullptr, 0);
621 if (sym.
symbol ==
nullptr)
634 field_type,
nullptr, physaddr, filename, line);
639 gdb_assert_not_reached
640 (
"unexpected static field location kind");
646 enum gcc_cp_symbol_kind field_flags = GCC_CP_SYMBOL_FIELD
652 instance->
plugin ().build_field
653 (
field_name, field_type, field_flags, bitsize,
663 struct type *parent_type,
664 struct type *method_type)
669 gcc_type class_type = instance->
convert_type (parent_type);
670 gcc_cp_qualifiers_flags quals = 0;
673 quals |= GCC_CP_QUALIFIER_CONST;
675 quals |= GCC_CP_QUALIFIER_VOLATILE;
677 quals |= GCC_CP_QUALIFIER_RESTRICT;
680 gcc_cp_ref_qualifiers_flags rquals = GCC_CP_REF_QUAL_NONE;
682 return instance->
plugin ().build_method_type
683 (class_type,
func_type, quals.raw (), rquals.raw ());
694 if (containing_class ==
nullptr)
697 gcc_type class_type = instance->
convert_type (containing_class);
701 return instance->
plugin ().build_pointer_to_member_type
702 (class_type, member_type);
716 gdb::unique_xmalloc_ptr<char> overloaded_name
727 gcc_cp_symbol_kind_flags sym_kind = GCC_CP_SYMBOL_FUNCTION;
728 gcc_type method_type;
733 if (sym.
symbol ==
nullptr)
743 (
"pure virtual method", overloaded_name.get (),
746 | GCC_CP_FLAG_VIRTUAL_FUNCTION
747 | GCC_CP_FLAG_PURE_VIRTUAL_FUNCTION).raw (),
748 method_type,
nullptr, 0,
nullptr, 0);
760 warning (_(
"Method %s appears to be optimized out.\n"
761 "All references to this method will be undefined."),
773 kind =
"static method";
785 sym_kind |= GCC_CP_FLAG_VIRTUAL_FUNCTION;
788 (kind, overloaded_name.get (),
790 method_type,
nullptr, address, filename, line);
802 enum gcc_cp_symbol_kind nested_access)
804 const char *filename =
nullptr;
805 unsigned int line = 0;
808 gdb::unique_xmalloc_ptr<char>
name
828 if (
type->
code () == TYPE_CODE_STRUCT)
833 (what,
name.get (), (GCC_CP_SYMBOL_CLASS | nested_access
835 ? GCC_CP_FLAG_CLASS_NOFLAG
836 : GCC_CP_FLAG_CLASS_IS_STRUCT)),
837 0,
nullptr, 0, filename, line);
841 gdb_assert (
type->
code () == TYPE_CODE_UNION);
843 (
"union",
name.get (), GCC_CP_SYMBOL_UNION | nested_access,
844 0,
nullptr, 0, filename, line);
848 if (
type->
code () == TYPE_CODE_STRUCT)
851 std::vector<gcc_type> elements (num_baseclasses);
852 std::vector<enum gcc_cp_symbol_kind>
flags (num_baseclasses);
854 struct gcc_vbase_array bases {};
855 bases.elements = elements.data ();
856 bases.flags =
flags.data ();
857 bases.n_elements = num_baseclasses;
859 for (
int i = 0; i < num_baseclasses; ++i)
863 bases.flags[i] = (GCC_CP_SYMBOL_BASECLASS
866 ? GCC_CP_FLAG_BASECLASS_VIRTUAL
867 : GCC_CP_FLAG_BASECLASS_NOFLAG));
872 (
name.get (), resuld, &bases, filename, line);
876 gdb_assert (
type->
code () == TYPE_CODE_UNION);
878 (
name.get (), resuld,
nullptr, filename, line);
906 enum gcc_cp_symbol_kind nested_access)
908 bool scoped_enum_p =
false;
920 gdb::unique_xmalloc_ptr<char>
name
930 = instance->
plugin ().start_enum_type (
name.get (), int_type,
931 GCC_CP_SYMBOL_ENUM | nested_access
933 ? GCC_CP_FLAG_ENUM_SCOPED
934 : GCC_CP_FLAG_ENUM_NOFLAG),
938 gdb::unique_xmalloc_ptr<char> fname
945 instance->
plugin ().build_enum_constant (result, fname.get (),
950 instance->
plugin ().finish_enum_type (result);
960 struct type *
type,
bool strip_artificial)
973 warning (_(
"function has unknown return type; assuming int"));
981 struct gcc_type_array array = { (int)
type->
num_fields (), elements.data () };
992 array.elements[i - artificials]
999 gcc_type result = instance->
plugin ().build_function_type
1000 (return_type, &array, is_varargs);
1012 return instance->
plugin ().get_char_type ();
1015 return instance->
plugin ().get_int_type
1025 return instance->
plugin ().get_float_type
1034 return instance->
plugin ().get_void_type ();
1042 return instance->
plugin ().get_bool_type ();
1049 gcc_cp_qualifiers_flags quals)
1051 gcc_type result = base;
1054 result =
plugin ().build_qualified_type (base, quals.raw ());
1066 gcc_cp_qualifiers_flags quals = (
enum gcc_cp_qualifiers) 0;
1067 gcc_type unqual_converted = instance->
convert_type (unqual);
1070 quals |= GCC_CP_QUALIFIER_CONST;
1072 quals |= GCC_CP_QUALIFIER_VOLATILE;
1074 quals |= GCC_CP_QUALIFIER_RESTRICT;
1087 return instance->
plugin ().build_complex_type (base);
1097 gdb::unique_xmalloc_ptr<char>
name
1104 instance->
plugin ().push_namespace (
name.get ());
1125 enum gcc_cp_symbol_kind nested_access)
1137 case TYPE_CODE_RVALUE_REF:
1143 case TYPE_CODE_ARRAY:
1146 case TYPE_CODE_STRUCT:
1147 case TYPE_CODE_UNION:
1151 case TYPE_CODE_ENUM:
1154 case TYPE_CODE_FUNC:
1157 case TYPE_CODE_METHOD:
1161 case TYPE_CODE_MEMBERPTR:
1162 case TYPE_CODE_METHODPTR:
1172 case TYPE_CODE_VOID:
1175 case TYPE_CODE_BOOL:
1178 case TYPE_CODE_COMPLEX:
1181 case TYPE_CODE_NAMESPACE:
1184 case TYPE_CODE_TYPEDEF:
1191 std::string s = string_printf (_(
"unhandled TYPE_CODE %d"),
1194 return instance->
plugin ().error (s.c_str ());
1199 enum gcc_cp_symbol_kind nested_access)
1216 (
void *datum,
struct gcc_cp_context *gcc_context)
1222 (
void *datum,
struct gcc_cp_context *gcc_context)
1255template <
typename T>
1261template <
typename T,
typename... Targs>
1270#define FORWARD(OP,...) m_context->cp_ops->OP(m_context, ##__VA_ARGS__)
1271#define OUTPUT_DEBUG_RESULT(R) \
1272 if (debug_compile_cplus_types) \
1274 gdb_puts (": ", gdb_stdlog); \
1275 compile_cplus_debug_output (R); \
1276 gdb_putc ('\n', gdb_stdlog); \
1279#define GCC_METHOD0(R, N) \
1280 R gcc_cp_plugin::N () const \
1282 if (debug_compile_cplus_types) \
1283 compile_cplus_debug_output (STRINGIFY (N)); \
1284 auto result = FORWARD (N); \
1285 OUTPUT_DEBUG_RESULT (result); \
1288#define GCC_METHOD1(R, N, A) \
1289 R gcc_cp_plugin::N (A a) const \
1291 if (debug_compile_cplus_types) \
1292 compile_cplus_debug_output (STRINGIFY (N), a); \
1293 auto result = FORWARD (N, a); \
1294 OUTPUT_DEBUG_RESULT (result); \
1297#define GCC_METHOD2(R, N, A, B) \
1298 R gcc_cp_plugin::N (A a, B b) const \
1300 if (debug_compile_cplus_types) \
1301 compile_cplus_debug_output (STRINGIFY (N), a, b); \
1302 auto result = FORWARD (N, a, b); \
1303 OUTPUT_DEBUG_RESULT (result); \
1306#define GCC_METHOD3(R, N, A, B, C) \
1307 R gcc_cp_plugin::N (A a, B b, C c) const \
1309 if (debug_compile_cplus_types) \
1310 compile_cplus_debug_output (STRINGIFY (N), a, b, c); \
1311 auto result = FORWARD (N, a, b, c); \
1312 OUTPUT_DEBUG_RESULT (result); \
1315#define GCC_METHOD4(R, N, A, B, C, D) \
1316 R gcc_cp_plugin::N (A a, B b, C c, D d) const \
1318 if (debug_compile_cplus_types) \
1319 compile_cplus_debug_output (STRINGIFY (N), a, b, c, d); \
1320 auto result = FORWARD (N, a, b, c, d); \
1321 OUTPUT_DEBUG_RESULT (result); \
1324#define GCC_METHOD5(R, N, A, B, C, D, E) \
1325 R gcc_cp_plugin::N (A a, B b, C c, D d, E e) const \
1327 if (debug_compile_cplus_types) \
1328 compile_cplus_debug_output (STRINGIFY (N), a, b, c, d, e); \
1329 auto result = FORWARD (N, a, b, c, d, e); \
1330 OUTPUT_DEBUG_RESULT (result); \
1333#define GCC_METHOD7(R, N, A, B, C, D, E, F, G) \
1334 R gcc_cp_plugin::N (A a, B b, C c, D d, E e, F f, G g) const \
1336 if (debug_compile_cplus_types) \
1337 compile_cplus_debug_output (STRINGIFY (N), a, b, c, d, e, f, g); \
1338 auto result = FORWARD (N, a, b, c, d, e, f, g); \
1339 OUTPUT_DEBUG_RESULT (result); \
1343#include "gcc-cp-fe.def"
1353#undef OUTPUT_DEBUG_RESULT
1357 enum gcc_cp_symbol_kind sym_kind, gcc_type sym_type,
1358 const char *substitution_name, gcc_address address,
1359 const char *filename,
unsigned int line_number)
1365 address, filename, line_number);
1370 const struct gcc_vbase_array *base_classes,
1371 const char *filename,
unsigned int line_number)
1381 unsigned long size_in_bytes)
1404Set debugging of C++ compile type conversion."), _(
"\
1405Show debugging of C++ compile type conversion."), _(
"\
1406When enabled debugging messages are printed during C++ type conversion for\n\
1407the compile commands."),
1415Set debugging of C++ compile scopes."), _(
"\
1416Show debugging of C++ compile scopes."), _(
"\
1417When enabled debugging messages are printed about definition scopes during\n\
1418C++ type conversion for the compile commands."),
long __attribute__((__aligned__(4)))
compile_scope new_scope(const char *type_name, struct type *type)
gcc_type convert_type(struct type *type, enum gcc_cp_symbol_kind nested_access=GCC_CP_ACCESS_NONE)
static gcc_cp_enter_leave_user_expr_scope_function gcc_cplus_enter_scope
static gcc_cp_enter_leave_user_expr_scope_function gcc_cplus_leave_scope
gcc_type convert_qualified_base(gcc_type base, gcc_cp_qualifiers_flags quals)
static gdb::unique_xmalloc_ptr< char > decl_name(const char *natural)
void enter_scope(compile_scope &&scope)
std::vector< compile_scope > m_scopes
static const char * m_default_cflags
gcc_type convert_pointer_base(gcc_type target)
gcc_type convert_reference_base(gcc_type base, enum gcc_cp_ref_qualifiers rquals)
bool get_cached_type(struct type *type, gcc_type *ret) const
void insert_type(struct type *type, gcc_type gcc_type)
enum compile_i_scope_types scope() const
const struct block * block() const
int finish_class_type(const char *debug_name, unsigned long size_in_bytes)
gcc_type start_class_type(const char *debug_name, gcc_decl typedecl, const struct gcc_vbase_array *base_classes, const char *filename, unsigned int line_number)
int pop_binding_level(const char *debug_name)
gcc_expr build_decl(const char *debug_decltype, const char *name, enum gcc_cp_symbol_kind sym_kind, gcc_type sym_type, const char *substitution_name, gcc_address address, const char *filename, unsigned int line_number)
struct cmd_list_element * showdebuglist
struct cmd_list_element * setdebuglist
set_show_commands add_setshow_boolean_cmd(const char *name, enum command_class theclass, bool *var, const char *set_doc, const char *show_doc, const char *help_doc, cmd_func_ftype *set_func, show_value_ftype *show_func, struct cmd_list_element **set_list, struct cmd_list_element **show_list)
std::string c_get_range_decl_name(const struct dynamic_prop *prop)
static gcc_type compile_cplus_convert_array(compile_cplus_instance *instance, struct type *type)
static enum gcc_cp_symbol_kind get_field_access_flag(const struct type *type, int num)
static gcc_type compile_cplus_convert_qualified(compile_cplus_instance *instance, struct type *type)
static void compile_cplus_debug_output_1(ULONGEST arg)
void _initialize_compile_cplus_types()
static gcc_type compile_cplus_convert_complex(compile_cplus_instance *instance, struct type *type)
static gcc_type compile_cplus_convert_method(compile_cplus_instance *instance, struct type *parent_type, struct type *method_type)
static gcc_type compile_cplus_convert_typedef(compile_cplus_instance *instance, struct type *type, enum gcc_cp_symbol_kind nested_access)
enum gcc_cp_symbol_kind get_method_access_flag(const struct type *type, int fni, int num)
static gcc_type compile_cplus_convert_reference(compile_cplus_instance *instance, struct type *type)
bool operator==(const scope_component &lhs, const scope_component &rhs)
static gcc_type compile_cplus_convert_enum(compile_cplus_instance *instance, struct type *type, enum gcc_cp_symbol_kind nested_access)
static gcc_type compile_cplus_convert_struct_or_union(compile_cplus_instance *instance, struct type *type, enum gcc_cp_symbol_kind nested_access)
static gcc_type compile_cplus_convert_void(compile_cplus_instance *instance, struct type *type)
static bool debug_compile_cplus_types
static gcc_type compile_cplus_convert_memberptr(compile_cplus_instance *instance, struct type *type)
bool operator!=(const scope_component &lhs, const scope_component &rhs)
static bool debug_compile_cplus_scopes
static gcc_type compile_cplus_convert_bool(compile_cplus_instance *instance, struct type *type)
static void compile_cplus_convert_type_defns(compile_cplus_instance *instance, struct type *type)
static gcc_type compile_cplus_convert_func(compile_cplus_instance *instance, struct type *type, bool strip_artificial)
static gcc_type compile_cplus_convert_namespace(compile_cplus_instance *instance, struct type *type)
static gcc_type compile_cplus_convert_int(compile_cplus_instance *instance, struct type *type)
compile_scope type_name_to_scope(const char *type_name, const struct block *block)
static gcc_type compile_cplus_convert_float(compile_cplus_instance *instance, struct type *type)
static gcc_type convert_type_cplus_basic(compile_cplus_instance *instance, struct type *type, enum gcc_cp_symbol_kind nested_access)
static void compile_cplus_convert_struct_or_union_members(compile_cplus_instance *instance, struct type *type, gcc_type comp_type)
static gcc_type compile_cplus_convert_pointer(compile_cplus_instance *instance, struct type *type)
static void compile_cplus_convert_struct_or_union_methods(compile_cplus_instance *instance, struct type *type, gcc_type class_type)
static void compile_cplus_debug_output()
compile_scope type_name_to_scope(const char *type_name, const struct block *block)
const gcc_type GCC_TYPE_NONE
gdb::unique_xmalloc_ptr< char > cp_func_name(const char *full_name)
unsigned int cp_find_first_component(const char *name)
struct type * make_unqualified_type(struct type *type)
bool get_array_bounds(struct type *type, LONGEST *low_bound, LONGEST *high_bound)
const struct builtin_type * builtin_type(struct gdbarch *gdbarch)
bool types_equal(struct type *a, struct type *b)
struct type * check_typedef(struct type *type)
#define TYPE_FN_FIELD_PHYSNAME(thisfn, n)
#define TYPE_NESTED_TYPES_FIELD_PROTECTED(thistype, n)
#define TYPE_NFN_FIELDS(thistype)
#define TYPE_TYPEDEF_FIELD_PROTECTED(thistype, n)
#define TYPE_NESTED_TYPES_FIELD_TYPE(thistype, n)
#define TYPE_NESTED_TYPES_COUNT(thistype)
@ FIELD_LOC_KIND_PHYSNAME
@ FIELD_LOC_KIND_PHYSADDR
#define TYPE_FN_FIELDLIST1(thistype, n)
#define TYPE_TYPEDEF_FIELD_TYPE(thistype, n)
@ TYPE_INSTANCE_FLAG_CONST
@ TYPE_INSTANCE_FLAG_VOLATILE
@ TYPE_INSTANCE_FLAG_RESTRICT
#define TYPE_TYPEDEF_FIELD_PRIVATE(thistype, n)
#define TYPE_SELF_TYPE(thistype)
#define TYPE_FN_FIELD_TYPE(thisfn, n)
#define TYPE_BASECLASS(thistype, index)
#define TYPE_FN_FIELD_VIRTUAL_P(thisfn, n)
#define TYPE_FIELD_IGNORE(thistype, n)
#define TYPE_NESTED_TYPES_FIELD_PRIVATE(thistype, n)
#define TYPE_FN_FIELDLIST_LENGTH(thistype, n)
#define TYPE_FN_FIELD_PROTECTED(thisfn, n)
#define TYPE_FN_FIELD_PRIVATE(thisfn, n)
#define TYPE_FIELD_PROTECTED(thistype, n)
#define TYPE_FN_FIELD_STATIC_P(thisfn, n)
#define TYPE_TYPEDEF_FIELD_COUNT(thistype)
#define BASETYPE_VIA_VIRTUAL(thistype, index)
#define TYPE_FN_FIELDLIST_NAME(thistype, n)
#define TYPE_FN_FIELD_ARTIFICIAL(thisfn, n)
#define TYPE_FIELD_PRIVATE(thistype, n)
#define TYPE_N_BASECLASSES(thistype)
mach_port_t kern_return_t mach_port_t mach_msg_type_name_t msgportsPoly mach_port_t kern_return_t pid_t pid mach_port_t kern_return_t mach_port_t task mach_port_t kern_return_t int flags
static gdbpy_ref field_name(struct type *type, int field)
struct type * builtin_int
CORE_ADDR loc_physaddr() const
LONGEST loc_bitpos() const
const char * loc_physname() const
bool is_artificial() const
field_loc_kind loc_kind() const
LONGEST loc_enumval() const
const char * name() const
unsigned int bitsize() const
struct type * type() const
struct block_symbol bsymbol
const block * value_block() const
struct type * type() const
unsigned int line() const
CORE_ADDR value_address() const
struct type * target_type() const
struct field & field(int idx) const
bool is_declared_class() const
bool has_no_signedness() const
unsigned int num_fields() const
const char * name() const
type * index_type() const
const type_instance_flags instance_flags() const
struct block_symbol lookup_symbol(const char *name, const struct block *block, domain_enum domain, struct field_of_this_result *is_a_field_of_this)
void gdb_printf(struct ui_file *stream, const char *format,...)
void printf_unfiltered(const char *format,...)
void gdb_puts(const char *linebuffer, struct ui_file *stream)