From patchwork Fri Jul 20 13:19:42 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 28526 Received: (qmail 48378 invoked by alias); 20 Jul 2018 13:19:49 -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 48363 invoked by uid 89); 20 Jul 2018 13:19:48 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-25.6 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy= X-HELO: gateway34.websitewelcome.com Received: from gateway34.websitewelcome.com (HELO gateway34.websitewelcome.com) (192.185.148.140) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 20 Jul 2018 13:19:46 +0000 Received: from cm17.websitewelcome.com (cm17.websitewelcome.com [100.42.49.20]) by gateway34.websitewelcome.com (Postfix) with ESMTP id 5A62862BA21 for ; Fri, 20 Jul 2018 08:19:45 -0500 (CDT) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id gVJxfN72gPvAdgVJxfRrE4; Fri, 20 Jul 2018 08:19:45 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To:MIME-Version :Content-Type:Content-Transfer-Encoding:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: In-Reply-To:References:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=VXC+oBSE+M6OVi0I+Hv5BhkmCYOSvTKfWgiNartpBK0=; b=ndNRg/fwP/k8IjofVPrD07y/z/ X/skSyI/akAvo7NHP1t2TdcC8VB8FpG9atlvtdOflLd45+NorvuntvQ2hYVHAL1OEXKTen/euQPoy ELF7kXsWNdH60O1BNYPnbTQmf; Received: from 75-166-85-72.hlrn.qwest.net ([75.166.85.72]:54428 helo=pokyo.Home) by box5379.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.91) (envelope-from ) id 1fgVJx-001LWw-2C; Fri, 20 Jul 2018 08:19:45 -0500 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [RFA] Allow "info address" of a template parameter Date: Fri, 20 Jul 2018 07:19:42 -0600 Message-Id: <20180720131942.6958-1-tom@tromey.com> PR symtab/16842 shows that gdb will crash when the user tries to invoke "info address" of a template parameter. The bug here is that dwarf2read.c does not set the symtab on the template parameter symbols. This is pedantically correct, given that the template symbols do not appear in a symtab. However, gdb primarily uses the symtab backlink to find the symbol's objfile. So, this patch simply sets the symtab on these symbols. Tested by the buildbot. gdb/ChangeLog 2018-07-20 Tom Tromey PR symtab/16842. * dwarf2read.c (read_func_scope): Set symtab on template parameter symbols. (process_structure_scope): Likewise. gdb/testsuite/ChangeLog 2018-07-20 Tom Tromey PR symtab/16842. * gdb.cp/temargs.exp: Test "info address" of a template parameter. --- gdb/ChangeLog | 7 +++++++ gdb/dwarf2read.c | 24 +++++++++++++++++++++++- gdb/testsuite/ChangeLog | 6 ++++++ gdb/testsuite/gdb.cp/temargs.exp | 8 ++++++++ 4 files changed, 44 insertions(+), 1 deletion(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 302a0f493a4..c3656d2ca3c 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,10 @@ +2018-07-20 Tom Tromey + + PR symtab/16842. + * dwarf2read.c (read_func_scope): Set symtab on template parameter + symbols. + (process_structure_scope): Likewise. + 2018-07-19 Pedro Alves * guile/guile-internal.h (gdbscm_scm_to_c_string): Now returns a diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c index b7933de49cf..8f5fb597161 100644 --- a/gdb/dwarf2read.c +++ b/gdb/dwarf2read.c @@ -13714,6 +13714,13 @@ read_func_scope (struct die_info *die, struct dwarf2_cu *cu) memcpy (templ_func->template_arguments, template_args.data (), (templ_func->n_template_arguments * sizeof (struct symbol *))); + + /* Make sure that the symtab is set on the new symbols. Even + though they don't appear in this symtab directly, other parts + of gdb assume that symbols do, and this is reasonably + true. */ + for (struct symbol *sym : template_args) + symbol_set_symtab (sym, symbol_symtab (templ_func)); } /* In C++, we can have functions nested inside functions (e.g., when @@ -15832,6 +15839,7 @@ process_structure_scope (struct die_info *die, struct dwarf2_cu *cu) discriminant_info. */ bool is_variant_part = TYPE_FLAG_DISCRIMINATED_UNION (type); sect_offset discr_offset; + bool has_template_parameters = false; if (is_variant_part) { @@ -15879,6 +15887,7 @@ process_structure_scope (struct die_info *die, struct dwarf2_cu *cu) /* Attach template arguments to type. */ if (!template_args.empty ()) { + has_template_parameters = true; ALLOCATE_CPLUS_STRUCT_TYPE (type); TYPE_N_TEMPLATE_ARGUMENTS (type) = template_args.size (); TYPE_TEMPLATE_ARGUMENTS (type) @@ -16028,7 +16037,20 @@ process_structure_scope (struct die_info *die, struct dwarf2_cu *cu) attribute, and a declaration attribute. */ if (dwarf2_attr (die, DW_AT_byte_size, cu) != NULL || !die_is_declaration (die, cu)) - new_symbol (die, type, cu); + { + struct symbol *sym = new_symbol (die, type, cu); + + if (has_template_parameters) + { + /* Make sure that the symtab is set on the new symbols. + Even though they don't appear in this symtab directly, + other parts of gdb assume that symbols do, and this is + reasonably true. */ + for (int i = 0; i < TYPE_N_TEMPLATE_ARGUMENTS (type); ++i) + symbol_set_symtab (TYPE_TEMPLATE_ARGUMENT (type, i), + symbol_symtab (sym)); + } + } } /* Assuming DIE is an enumeration type, and TYPE is its associated type, diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog index 79ef76faf76..7039518ac3d 100644 --- a/gdb/testsuite/ChangeLog +++ b/gdb/testsuite/ChangeLog @@ -1,3 +1,9 @@ +2018-07-20 Tom Tromey + + PR symtab/16842. + * gdb.cp/temargs.exp: Test "info address" of a template + parameter. + 2018-07-19 Tom de Vries * gdb.mi/list-thread-groups-available.exp (cores_re): Fix quoting in diff --git a/gdb/testsuite/gdb.cp/temargs.exp b/gdb/testsuite/gdb.cp/temargs.exp index 8c87872225e..5a109102d75 100644 --- a/gdb/testsuite/gdb.cp/temargs.exp +++ b/gdb/testsuite/gdb.cp/temargs.exp @@ -133,6 +133,10 @@ gdb_test "ptype T" "unsigned char" "test type of T in func" if $have_older_template_gcc { setup_xfail "*-*-*" } gdb_test "print I" " = 91" "test value of I in func" +# PR symtab/16842 - gdb used to crash here. +if $have_older_template_gcc { setup_xfail "*-*-*" } +gdb_test "info addr I" "Symbol \"I\" is constant." "test address of I in templ_m" + if $have_older_template_gcc { setup_xfail "*-*-*" } gdb_test "print P == &a_global" " = true" "test value of P in func" @@ -151,6 +155,10 @@ gdb_test "ptype T" "double" "test type of T in templ_m" if $have_older_template_gcc { setup_xfail "*-*-*" } gdb_test "print I" " = 23" "test value of I in templ_m" +# PR symtab/16842 - gdb used to crash here. +if $have_older_template_gcc { setup_xfail "*-*-*" } +gdb_test "info addr I" "Symbol \"I\" is constant." "test address of I in templ_m" + if $have_older_template_gcc { setup_xfail "*-*-*" } gdb_test "print P == &a_global" " = true" "test value of P in templ_m"