From patchwork Fri Nov 17 19:25:47 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 24331 Received: (qmail 48159 invoked by alias); 17 Nov 2017 19:26:04 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 48086 invoked by uid 89); 17 Nov 2017 19:26:04 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-24.0 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_STOCKGEN, KB_WAM_FROM_NAME_SINGLEWORD, RCVD_IN_DNSWL_NONE, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy= X-HELO: gateway20.websitewelcome.com Received: from gateway20.websitewelcome.com (HELO gateway20.websitewelcome.com) (192.185.64.36) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 17 Nov 2017 19:26:00 +0000 Received: from cm13.websitewelcome.com (cm13.websitewelcome.com [100.42.49.6]) by gateway20.websitewelcome.com (Postfix) with ESMTP id E3BC7400D85C7 for ; Fri, 17 Nov 2017 13:25:49 -0600 (CST) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id FmGreaGQurWstFmGreH15X; Fri, 17 Nov 2017 13:25:49 -0600 Received: from 71-218-90-63.hlrn.qwest.net ([71.218.90.63]:56172 helo=pokyo.Home) by box5379.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.89) (envelope-from ) id 1eFmGr-001NLF-J4; Fri, 17 Nov 2017 13:25:49 -0600 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [RFA v2 3/3] Use an enum to represent subclasses of symbol Date: Fri, 17 Nov 2017 12:25:47 -0700 Message-Id: <20171117192547.3515-4-tom@tromey.com> In-Reply-To: <20171117192547.3515-1-tom@tromey.com> References: <20171117192547.3515-1-tom@tromey.com> X-BWhitelist: no X-Source-L: No X-Exim-ID: 1eFmGr-001NLF-J4 X-Source-Sender: 71-218-90-63.hlrn.qwest.net (pokyo.Home) [71.218.90.63]:56172 X-Source-Auth: tom+tromey.com X-Email-Count: 4 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes This changes struct symbol to use an enum to encode the concrete subclass of a particular symbol. Note that "enum class" doesn't work properly with bitfields, so a plain enum is used. 2017-11-17 Tom Tromey * symtab.h (enum symbol_subclass_kind): New. (struct symbol) : Remove. : New member. (SYMBOL_IS_CPLUS_TEMPLATE_FUNCTION): Update. * rust-lang.c (rust_get_trait_object_pointer): Update. * dwarf2read.c (read_func_scope): Update. (read_variable): Update. --- gdb/ChangeLog | 11 +++++++++++ gdb/dwarf2read.c | 4 ++-- gdb/rust-lang.c | 2 +- gdb/symtab.h | 26 ++++++++++++++++++-------- 4 files changed, 32 insertions(+), 11 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 1551654..1502f06 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,5 +1,16 @@ 2017-11-17 Tom Tromey + * symtab.h (enum symbol_subclass_kind): New. + (struct symbol) : + Remove. + : New member. + (SYMBOL_IS_CPLUS_TEMPLATE_FUNCTION): Update. + * rust-lang.c (rust_get_trait_object_pointer): Update. + * dwarf2read.c (read_func_scope): Update. + (read_variable): Update. + +2017-11-17 Tom Tromey + * dwarf2read.c (read_func_scope): Update. * symtab.h (struct template_symbol): Derive from symbol. : Remove. diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c index 86b6996..5437d21 100644 --- a/gdb/dwarf2read.c +++ b/gdb/dwarf2read.c @@ -12263,7 +12263,7 @@ read_func_scope (struct die_info *die, struct dwarf2_cu *cu) || child_die->tag == DW_TAG_template_value_param) { templ_func = allocate_template_symbol (objfile); - templ_func->is_cplus_template_function = 1; + templ_func->subclass = SYMBOL_TEMPLATE; break; } } @@ -12821,7 +12821,7 @@ read_variable (struct die_info *die, struct dwarf2_cu *cu) struct rust_vtable_symbol); initialize_objfile_symbol (storage); storage->concrete_type = containing_type; - storage->is_rust_vtable = 1; + storage->subclass = SYMBOL_RUST_VTABLE; } } diff --git a/gdb/rust-lang.c b/gdb/rust-lang.c index 832f77f..f3562e0 100644 --- a/gdb/rust-lang.c +++ b/gdb/rust-lang.c @@ -421,7 +421,7 @@ rust_get_trait_object_pointer (struct value *value) CORE_ADDR vtable = value_as_address (value_field (value, vtable_field)); struct symbol *symbol = find_symbol_at_address (vtable); - if (symbol == NULL || !symbol->is_rust_vtable) + if (symbol == NULL || symbol->subclass != SYMBOL_RUST_VTABLE) return NULL; struct rust_vtable_symbol *vtable_sym diff --git a/gdb/symtab.h b/gdb/symtab.h index 6ecce81..ad8d602 100644 --- a/gdb/symtab.h +++ b/gdb/symtab.h @@ -1008,6 +1008,21 @@ struct symbol_impl const struct symbol_register_ops *ops_register; }; +/* struct symbol has some subclasses. This enum is used to + differentiate between them. */ + +enum symbol_subclass_kind +{ + /* Plain struct symbol. */ + SYMBOL_NONE, + + /* struct template_symbol. */ + SYMBOL_TEMPLATE, + + /* struct rust_vtable_symbol. */ + SYMBOL_RUST_VTABLE +}; + /* This structure is space critical. See space comments at the top. */ struct symbol @@ -1057,14 +1072,9 @@ struct symbol /* Whether this is an inlined function (class LOC_BLOCK only). */ unsigned is_inlined : 1; - /* True if this is a C++ function symbol with template arguments. - In this case the symbol is really a "struct template_symbol". */ - unsigned is_cplus_template_function : 1; - - /* True if this is a Rust virtual table. In this case, the symbol - can be downcast to "struct rust_vtable_symbol". */ + /* The concrete type of this symbol. */ - unsigned is_rust_vtable : 1; + ENUM_BITFIELD (symbol_subclass_kind) subclass : 2; /* Line number of this symbol's definition, except for inlined functions. For an inlined function (class LOC_BLOCK and @@ -1126,7 +1136,7 @@ extern const struct block_symbol null_block_symbol; #define SYMBOL_IS_ARGUMENT(symbol) (symbol)->is_argument #define SYMBOL_INLINED(symbol) (symbol)->is_inlined #define SYMBOL_IS_CPLUS_TEMPLATE_FUNCTION(symbol) \ - (symbol)->is_cplus_template_function + (((symbol)->subclass) == SYMBOL_TEMPLATE) #define SYMBOL_TYPE(symbol) (symbol)->type #define SYMBOL_LINE(symbol) (symbol)->line #define SYMBOL_COMPUTED_OPS(symbol) (SYMBOL_IMPL (symbol).ops_computed)