CTF: incorrect underlying type setting for enumeration types

A bug was filed against the incorrect underlying type setting for
an enumeration type, which was caused by a copy and paste error.
This patch fixes the problem by setting it by calling objfile_int_type,
which was originally dwarf2_per_objfile::int_type, with ctf_type_size bits.
Also add error checking on ctf_func_type_info call.
This commit is contained in:
Weimin Pan
2021-10-18 14:15:21 -04:00
parent 19b9612448
commit b3a01ce215
6 changed files with 42 additions and 36 deletions

View File

@ -691,7 +691,12 @@ read_func_kind_type (struct ctf_context *ccp, ctf_id_t tid)
type = alloc_type (of);
type->set_code (TYPE_CODE_FUNC);
ctf_func_type_info (fp, tid, &cfi);
if (ctf_func_type_info (fp, tid, &cfi) < 0)
{
const char *fname = ctf_type_name_raw (fp, tid);
error (_("Error getting function type info: %s"),
fname == nullptr ? "noname" : fname);
}
rettype = fetch_tid_type (ccp, cfi.ctc_return);
TYPE_TARGET_TYPE (type) = rettype;
set_type_align (type, ctf_type_align (fp, tid));
@ -733,8 +738,7 @@ read_enum_type (struct ctf_context *ccp, ctf_id_t tid)
{
struct objfile *of = ccp->of;
ctf_dict_t *fp = ccp->fp;
struct type *type, *target_type;
ctf_funcinfo_t fi;
struct type *type;
type = alloc_type (of);
@ -744,9 +748,8 @@ read_enum_type (struct ctf_context *ccp, ctf_id_t tid)
type->set_code (TYPE_CODE_ENUM);
TYPE_LENGTH (type) = ctf_type_size (fp, tid);
ctf_func_type_info (fp, tid, &fi);
target_type = get_tid_type (of, fi.ctc_return);
TYPE_TARGET_TYPE (type) = target_type;
/* Set the underlying type based on its ctf_type_size bits. */
TYPE_TARGET_TYPE (type) = objfile_int_type (of, TYPE_LENGTH (type), false);
set_type_align (type, ctf_type_align (fp, tid));
return set_tid_type (of, tid, type);

View File

@ -46,7 +46,7 @@ struct type *
dwarf2_cu::addr_sized_int_type (bool unsigned_p) const
{
int addr_size = this->per_cu->addr_size ();
return this->per_objfile->int_type (addr_size, unsigned_p);
return objfile_int_type (this->per_objfile->objfile, addr_size, unsigned_p);
}
/* Start a symtab for DWARF. NAME, COMP_DIR, LOW_PC are passed to the

View File

@ -17429,7 +17429,7 @@ read_tag_string_type (struct die_info *die, struct dwarf2_cu *cu)
/* Pass 0 as the default as we know this attribute is constant
and the default value will not be returned. */
LONGEST sz = len->constant_value (0);
prop_type = cu->per_objfile->int_type (sz, true);
prop_type = objfile_int_type (objfile, sz, true);
}
else
{
@ -18480,30 +18480,6 @@ attr_to_dynamic_prop (const struct attribute *attr, struct die_info *die,
/* See read.h. */
struct type *
dwarf2_per_objfile::int_type (int size_in_bytes, bool unsigned_p) const
{
struct type *int_type;
/* Helper macro to examine the various builtin types. */
#define TRY_TYPE(F) \
int_type = (unsigned_p \
? objfile_type (objfile)->builtin_unsigned_ ## F \
: objfile_type (objfile)->builtin_ ## F); \
if (int_type != NULL && TYPE_LENGTH (int_type) == size_in_bytes) \
return int_type
TRY_TYPE (char);
TRY_TYPE (short);
TRY_TYPE (int);
TRY_TYPE (long);
TRY_TYPE (long_long);
#undef TRY_TYPE
gdb_assert_not_reached ("unable to find suitable integer type");
}
/* Read the DW_AT_type attribute for a sub-range. If this attribute is not
present (which is valid) then compute the default type based on the
compilation units address size. */

View File

@ -537,10 +537,6 @@ struct dwarf2_per_objfile
void set_type_for_signatured_type (signatured_type *sig_type,
struct type *type);
/* Find an integer type SIZE_IN_BYTES bytes in size and return it.
UNSIGNED_P controls if the integer is unsigned or not. */
struct type *int_type (int size_in_bytes, bool unsigned_p) const;
/* Get the dwarf2_cu matching PER_CU for this objfile. */
dwarf2_cu *get_cu (dwarf2_per_cu_data *per_cu);

View File

@ -1374,3 +1374,29 @@ objfile_flavour_name (struct objfile *objfile)
return bfd_flavour_name (bfd_get_flavour (objfile->obfd));
return NULL;
}
/* See objfiles.h. */
struct type *
objfile_int_type (struct objfile *of, int size_in_bytes, bool unsigned_p)
{
struct type *int_type;
/* Helper macro to examine the various builtin types. */
#define TRY_TYPE(F) \
int_type = (unsigned_p \
? objfile_type (of)->builtin_unsigned_ ## F \
: objfile_type (of)->builtin_ ## F); \
if (int_type != NULL && TYPE_LENGTH (int_type) == size_in_bytes) \
return int_type
TRY_TYPE (char);
TRY_TYPE (short);
TRY_TYPE (int);
TRY_TYPE (long);
TRY_TYPE (long_long);
#undef TRY_TYPE
gdb_assert_not_reached ("unable to find suitable integer type");
}

View File

@ -936,6 +936,11 @@ const char *objfile_flavour_name (struct objfile *objfile);
extern void set_objfile_main_name (struct objfile *objfile,
const char *name, enum language lang);
/* Find an integer type SIZE_IN_BYTES bytes in size from OF and return it.
UNSIGNED_P controls if the integer is unsigned or not. */
extern struct type *objfile_int_type (struct objfile *of, int size_in_bytes,
bool unsigned_p);
extern void objfile_register_static_link
(struct objfile *objfile,
const struct block *block,