From b3a01ce2155d3532761f07639e00ce3d0317837d Mon Sep 17 00:00:00 2001 From: Weimin Pan Date: Mon, 18 Oct 2021 14:15:21 -0400 Subject: [PATCH] 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. --- gdb/ctfread.c | 15 +++++++++------ gdb/dwarf2/cu.c | 2 +- gdb/dwarf2/read.c | 26 +------------------------- gdb/dwarf2/read.h | 4 ---- gdb/objfiles.c | 26 ++++++++++++++++++++++++++ gdb/objfiles.h | 5 +++++ 6 files changed, 42 insertions(+), 36 deletions(-) diff --git a/gdb/ctfread.c b/gdb/ctfread.c index 712683b98ab..06e2224c085 100644 --- a/gdb/ctfread.c +++ b/gdb/ctfread.c @@ -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); diff --git a/gdb/dwarf2/cu.c b/gdb/dwarf2/cu.c index 2a90ba8a7b5..e7aed774c25 100644 --- a/gdb/dwarf2/cu.c +++ b/gdb/dwarf2/cu.c @@ -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 diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c index cbd9a3012eb..e456c37e193 100644 --- a/gdb/dwarf2/read.c +++ b/gdb/dwarf2/read.c @@ -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. */ diff --git a/gdb/dwarf2/read.h b/gdb/dwarf2/read.h index b57e1f95c45..1638d8521c0 100644 --- a/gdb/dwarf2/read.h +++ b/gdb/dwarf2/read.h @@ -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); diff --git a/gdb/objfiles.c b/gdb/objfiles.c index b65fa8820ca..3da6f5211aa 100644 --- a/gdb/objfiles.c +++ b/gdb/objfiles.c @@ -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"); +} diff --git a/gdb/objfiles.h b/gdb/objfiles.h index 97abc9c17ef..6062a3f61cd 100644 --- a/gdb/objfiles.h +++ b/gdb/objfiles.h @@ -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, -- 2.30.2