From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from barracuda.ebox.ca (barracuda.ebox.ca [96.127.255.19]) by sourceware.org (Postfix) with ESMTPS id 90C1A385E021 for ; Thu, 21 Jan 2021 03:24:12 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 90C1A385E021 X-ASG-Debug-ID: 1611199451-0c856e6cd5731cd0001-fS2M51 Received: from smtp.ebox.ca (smtp.ebox.ca [96.127.255.82]) by barracuda.ebox.ca with ESMTP id 4CSD6bXwdMQt4abF (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Wed, 20 Jan 2021 22:24:11 -0500 (EST) X-Barracuda-Envelope-From: simon.marchi@polymtl.ca X-Barracuda-RBL-Trusted-Forwarder: 96.127.255.82 Received: from simark.localdomain (192-222-157-6.qc.cable.ebox.net [192.222.157.6]) by smtp.ebox.ca (Postfix) with ESMTP id 79D73441B21; Wed, 20 Jan 2021 22:24:11 -0500 (EST) From: Simon Marchi X-Barracuda-RBL-IP: 192.222.157.6 X-Barracuda-Effective-Source-IP: 192-222-157-6.qc.cable.ebox.net[192.222.157.6] X-Barracuda-Apparent-Source-IP: 192.222.157.6 To: gdb-patches@sourceware.org Cc: Simon Marchi Subject: [PATCH 1/3] gdb: add owner-related methods to struct type Date: Wed, 20 Jan 2021 22:24:08 -0500 X-ASG-Orig-Subj: [PATCH 1/3] gdb: add owner-related methods to struct type Message-Id: <20210121032410.97525-1-simon.marchi@polymtl.ca> X-Mailer: git-send-email 2.30.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Barracuda-Connect: smtp.ebox.ca[96.127.255.82] X-Barracuda-Start-Time: 1611199451 X-Barracuda-Encrypted: DHE-RSA-AES256-SHA X-Barracuda-URL: https://96.127.255.19:443/cgi-mod/mark.cgi X-Virus-Scanned: by bsmtpd at ebox.ca X-Barracuda-Scan-Msg-Size: 11950 X-Barracuda-BRTS-Status: 1 X-Barracuda-Spam-Score: 0.50 X-Barracuda-Spam-Status: No, SCORE=0.50 using global scores of TAG_LEVEL=1000.0 QUARANTINE_LEVEL=1000.0 KILL_LEVEL=8.0 tests=BSF_RULE7568M X-Barracuda-Spam-Report: Code version 3.2, rules version 3.2.3.87396 Rule breakdown below pts rule name description ---- ---------------------- -------------------------------------------------- 0.50 BSF_RULE7568M Custom Rule 7568M X-Spam-Status: No, score=-22.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_QUARANTINE, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_SOFTFAIL, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 21 Jan 2021 03:24:14 -0000 From: Simon Marchi Add the following methods to struct type: * is_objfile_owned * set_owner (objfile and gdbarch overloads) * objfile and arch getters Rename the fields in main_type to ensure no other code accesses them directly. As usual, we can't make them actually private, but giving them the `m_` prefix will help making sure they are not accessed when not supposed to, by convention. Remove the TYPE_OWNER macro to ensure no code uses the type_owner struct directly. gdb/ChangeLog: * gdbtypes.h (TYPE_OBJFILE_OWNED): Adjust. (TYPE_OWNER): Remove. (TYPE_OBJFILE): Adjust. (struct main_type) : Rename to... : ... this. : Rename to... : ... this. (struct type) : New methods. (TYPE_ALLOC): Adjust. * gdbtypes.c (alloc_type): Adjust. (alloc_type_arch): Adjust. (alloc_type_copy): Adjust. (get_type_arch): Adjust. (smash_type): Adjust. (lookup_array_range_type): Adjust. (recursive_dump_type): Adjust. (copy_type_recursive): Adjust. * compile/compile-c-types.c (convert_func): Adjust. (convert_type_basic): Adjust. * compile/compile-cplus-types.c (compile_cplus_convert_func): Adjust. * language.c (language_arch_info::type_and_symbol::alloc_type_symbol): Adjust. Change-Id: I7f92e869d9f92e2402a3d3007dd0832e05aa6ac8 --- gdb/compile/compile-c-types.c | 8 ++--- gdb/compile/compile-cplus-types.c | 4 +-- gdb/gdbtypes.c | 38 +++++++++++---------- gdb/gdbtypes.h | 56 +++++++++++++++++++++++++++---- gdb/language.c | 2 +- 5 files changed, 76 insertions(+), 32 deletions(-) diff --git a/gdb/compile/compile-c-types.c b/gdb/compile/compile-c-types.c index eea084469a8d..90de2084c85c 100644 --- a/gdb/compile/compile-c-types.c +++ b/gdb/compile/compile-c-types.c @@ -165,9 +165,9 @@ convert_func (compile_c_instance *context, struct type *type) if (target_type == NULL) { if (TYPE_OBJFILE_OWNED (type)) - target_type = objfile_type (TYPE_OWNER (type).objfile)->builtin_int; + target_type = objfile_type (type->objfile ())->builtin_int; else - target_type = builtin_type (TYPE_OWNER (type).gdbarch)->builtin_int; + target_type = builtin_type (type->arch ())->builtin_int; warning (_("function has unknown return type; assuming int")); } @@ -324,9 +324,9 @@ convert_type_basic (compile_c_instance *context, struct type *type) built-in parser used to do, but at least warn. */ struct type *fallback; if (TYPE_OBJFILE_OWNED (type)) - fallback = objfile_type (TYPE_OWNER (type).objfile)->builtin_int; + fallback = objfile_type (type->objfile ())->builtin_int; else - fallback = builtin_type (TYPE_OWNER (type).gdbarch)->builtin_int; + fallback = builtin_type (type->arch ())->builtin_int; warning (_("variable has unknown type; assuming int")); return convert_int (context, fallback); } diff --git a/gdb/compile/compile-cplus-types.c b/gdb/compile/compile-cplus-types.c index 5289f6f45924..ddb0d8a03682 100644 --- a/gdb/compile/compile-cplus-types.c +++ b/gdb/compile/compile-cplus-types.c @@ -971,9 +971,9 @@ compile_cplus_convert_func (compile_cplus_instance *instance, if (target_type == nullptr) { if (TYPE_OBJFILE_OWNED (type)) - target_type = objfile_type (TYPE_OWNER (type).objfile)->builtin_int; + target_type = objfile_type (type->objfile ())->builtin_int; else - target_type = builtin_type (TYPE_OWNER (type).gdbarch)->builtin_int; + target_type = builtin_type (type->arch ())->builtin_int; warning (_("function has unknown return type; assuming int")); } diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c index d9842817462a..e2f8837dcb4d 100644 --- a/gdb/gdbtypes.c +++ b/gdb/gdbtypes.c @@ -183,8 +183,7 @@ alloc_type (struct objfile *objfile) struct main_type); OBJSTAT (objfile, n_types++); - TYPE_OBJFILE_OWNED (type) = 1; - TYPE_OWNER (type).objfile = objfile; + type->set_owner (objfile); /* Initialize the fields that might not be zero. */ @@ -210,8 +209,7 @@ alloc_type_arch (struct gdbarch *gdbarch) type = GDBARCH_OBSTACK_ZALLOC (gdbarch, struct type); TYPE_MAIN_TYPE (type) = GDBARCH_OBSTACK_ZALLOC (gdbarch, struct main_type); - TYPE_OBJFILE_OWNED (type) = 0; - TYPE_OWNER (type).gdbarch = gdbarch; + type->set_owner (gdbarch); /* Initialize the fields that might not be zero. */ @@ -229,9 +227,9 @@ struct type * alloc_type_copy (const struct type *type) { if (TYPE_OBJFILE_OWNED (type)) - return alloc_type (TYPE_OWNER (type).objfile); + return alloc_type (type->objfile ()); else - return alloc_type_arch (TYPE_OWNER (type).gdbarch); + return alloc_type_arch (type->arch ()); } /* If TYPE is gdbarch-associated, return that architecture. @@ -243,9 +241,9 @@ get_type_arch (const struct type *type) struct gdbarch *arch; if (TYPE_OBJFILE_OWNED (type)) - arch = TYPE_OWNER (type).objfile->arch (); + arch = type->objfile ()->arch (); else - arch = TYPE_OWNER (type).gdbarch; + arch = type->arch (); /* The ARCH can be NULL if TYPE is associated with neither an objfile nor a gdbarch, however, this is very rare, and even then, in most cases @@ -311,14 +309,17 @@ alloc_type_instance (struct type *oldtype) static void smash_type (struct type *type) { - int objfile_owned = TYPE_OBJFILE_OWNED (type); - union type_owner owner = TYPE_OWNER (type); + bool objfile_owned = type->is_objfile_owned (); + objfile *objfile = type->objfile (); + gdbarch *arch = type->arch (); memset (TYPE_MAIN_TYPE (type), 0, sizeof (struct main_type)); /* Restore owner information. */ - TYPE_OBJFILE_OWNED (type) = objfile_owned; - TYPE_OWNER (type) = owner; + if (objfile_owned) + type->set_owner (objfile); + else + type->set_owner (arch); /* For now, delete the rings. */ TYPE_CHAIN (type) = type; @@ -1429,9 +1430,10 @@ lookup_array_range_type (struct type *element_type, struct type *range_type; if (TYPE_OBJFILE_OWNED (element_type)) - index_type = objfile_type (TYPE_OWNER (element_type).objfile)->builtin_int; + index_type = objfile_type (element_type->objfile ())->builtin_int; else - index_type = builtin_type (get_type_arch (element_type))->builtin_int; + index_type = builtin_type (element_type->arch ())->builtin_int; + range_type = create_static_range_type (NULL, index_type, low_bound, high_bound); @@ -5190,12 +5192,12 @@ recursive_dump_type (struct type *type, int spaces) if (TYPE_OBJFILE_OWNED (type)) { printf_filtered ("%*sobjfile ", spaces, ""); - gdb_print_host_address (TYPE_OWNER (type).objfile, gdb_stdout); + gdb_print_host_address (type->objfile (), gdb_stdout); } else { printf_filtered ("%*sgdbarch ", spaces, ""); - gdb_print_host_address (TYPE_OWNER (type).gdbarch, gdb_stdout); + gdb_print_host_address (type->arch (), gdb_stdout); } printf_filtered ("\n"); printf_filtered ("%*starget_type ", spaces, ""); @@ -5515,8 +5517,8 @@ copy_type_recursive (struct objfile *objfile, /* Copy the common fields of types. For the main type, we simply copy the entire thing and then update specific fields as needed. */ *TYPE_MAIN_TYPE (new_type) = *TYPE_MAIN_TYPE (type); - TYPE_OBJFILE_OWNED (new_type) = 0; - TYPE_OWNER (new_type).gdbarch = get_type_arch (type); + + new_type->set_owner (type->arch ()); if (type->name ()) new_type->set_name (xstrdup (type->name ())); diff --git a/gdb/gdbtypes.h b/gdb/gdbtypes.h index c74098826b8b..51f603157ba7 100644 --- a/gdb/gdbtypes.h +++ b/gdb/gdbtypes.h @@ -224,9 +224,8 @@ DEF_ENUM_FLAGS_TYPE (enum type_instance_flag_value, type_instance_flags); the objfile retrieved as TYPE_OBJFILE. Otherwise, the type is owned by an architecture; TYPE_OBJFILE is NULL in this case. */ -#define TYPE_OBJFILE_OWNED(t) (TYPE_MAIN_TYPE (t)->flag_objfile_owned) -#define TYPE_OWNER(t) TYPE_MAIN_TYPE(t)->owner -#define TYPE_OBJFILE(t) (TYPE_OBJFILE_OWNED(t)? TYPE_OWNER(t).objfile : NULL) +#define TYPE_OBJFILE_OWNED(t) ((t)->is_objfile_owned ()) +#define TYPE_OBJFILE(t) ((t)->objfile ()) /* * True if this type was declared using the "class" keyword. This is only valid for C++ structure and enum types. If false, a structure @@ -817,7 +816,7 @@ struct main_type unsigned int m_flag_stub_supported : 1; unsigned int m_flag_gnu_ifunc : 1; unsigned int m_flag_fixed_instance : 1; - unsigned int flag_objfile_owned : 1; + unsigned int m_flag_objfile_owned : 1; unsigned int m_flag_endianity_not_default : 1; /* * True if this type was declared with "class" rather than @@ -860,7 +859,7 @@ struct main_type this is somewhat ugly, but without major overhaul of the internal type system, it can't be avoided for now. */ - union type_owner owner; + union type_owner m_owner; /* * For a pointer type, describes the type of object pointed to. - For an array type, describes the type of the elements. @@ -1243,6 +1242,49 @@ struct type /* * Remove dynamic property of kind KIND from this type, if it exists. */ void remove_dyn_prop (dynamic_prop_node_kind kind); + /* Return true if this type is owned by an objfile. Return false if it is + owned by an architecture. */ + bool is_objfile_owned () const + { + return this->main_type->m_flag_objfile_owned; + } + + /* Set the owner of the type to be OBJFILE. */ + void set_owner (objfile *objfile) + { + this->main_type->m_owner.objfile = objfile; + this->main_type->m_flag_objfile_owned = true; + } + + /* Set the owner of the type to be ARCH. */ + void set_owner (gdbarch *arch) + { + this->main_type->m_owner.gdbarch = arch; + this->main_type->m_flag_objfile_owned = false; + } + + /* Return the objfile owner of this type. + + Return nullptr if this type is not objfile-owned. */ + struct objfile *objfile () const + { + if (!this->is_objfile_owned ()) + return nullptr; + + return this->main_type->m_owner.objfile; + } + + gdbarch *arch () const + { + if (this->is_objfile_owned ()) + return nullptr; + + /* Return the gdbarch owner of this type. + + Return nullptr if this type is not gdbarch-owned. */ + return this->main_type->m_owner.gdbarch; + } + /* * Return true if this is an integer type whose logical (bit) size differs from its storage size; false otherwise. Always return false for non-integer (i.e., non-TYPE_SPECIFIC_INT) types. */ @@ -2201,8 +2243,8 @@ extern const struct floatformat *floatformats_bfloat16[BFD_ENDIAN_UNKNOWN]; #define TYPE_ALLOC(t,size) \ (obstack_alloc ((TYPE_OBJFILE_OWNED (t) \ - ? &TYPE_OBJFILE (t)->objfile_obstack \ - : gdbarch_obstack (TYPE_OWNER (t).gdbarch)), \ + ? &((t)->objfile ()->objfile_obstack) \ + : gdbarch_obstack ((t)->arch ())), \ size)) diff --git a/gdb/language.c b/gdb/language.c index 1770ba1f8e1e..d4b84911f8b5 100644 --- a/gdb/language.c +++ b/gdb/language.c @@ -1037,7 +1037,7 @@ language_arch_info::type_and_symbol::alloc_type_symbol struct symbol *symbol; struct gdbarch *gdbarch; gdb_assert (!TYPE_OBJFILE_OWNED (type)); - gdbarch = TYPE_OWNER (type).gdbarch; + gdbarch = type->arch (); symbol = new (gdbarch_obstack (gdbarch)) struct symbol (); symbol->m_name = type->name (); symbol->set_language (lang, nullptr); -- 2.30.0