From patchwork Sat Feb 4 16:23:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ed Catmur X-Patchwork-Id: 64296 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 24EA1385842A for ; Sat, 4 Feb 2023 16:23:47 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from out5-smtp.messagingengine.com (out5-smtp.messagingengine.com [66.111.4.29]) by sourceware.org (Postfix) with ESMTPS id A5E6A3858004 for ; Sat, 4 Feb 2023 16:23:32 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A5E6A3858004 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=catmur.uk Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=catmur.uk Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailout.nyi.internal (Postfix) with ESMTP id B7D475C00F2; Sat, 4 Feb 2023 11:23:30 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute5.internal (MEProxy); Sat, 04 Feb 2023 11:23:30 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=catmur.uk; h=cc :cc:content-transfer-encoding:date:date:from:from:in-reply-to :message-id:mime-version:reply-to:sender:subject:subject:to:to; s=fm3; t=1675527810; x=1675614210; bh=/3tJ1nSjHLwpzf2kTy6kTirKA r0ZJ8V1XV3iCP8pZvo=; b=tGLdZmUpycA2DWirEZfKLMzNk6/2QzAR3Xyjt/J8o KJ/e0Fl4W2RvLj3PNU/zWKKHpa0KRncPuoCv8zPolqffnCDkEgGCe4Nt3jWgQCxT Lg0CA5/hHC3BKUQNjEsYOyfMKyldKy8GN1tbvKx8sgudckVrxJv2xAOIT9sLtFlL gngrK4aIvt1Dz8roSSaBdbTSz/RJvL7Wl+ZfRV0Yz8/Qa9aWHepErTUmvsI/s0ag 00HrvWHnK4ttYfsa8oP3QFkir/0MzqZnTwW5+z4tTNHuJsRuFREG63aj59/3J7kN x5nko2aVT8jIpm2G25FEuRrKxMEZsDce3VEp2PWIwdH6Q== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding:date:date :feedback-id:feedback-id:from:from:in-reply-to:message-id :mime-version:reply-to:sender:subject:subject:to:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm3; t= 1675527810; x=1675614210; bh=/3tJ1nSjHLwpzf2kTy6kTirKAr0ZJ8V1XV3 iCP8pZvo=; b=NWKO005goM5hwFElk7Z81MUaZ6ohJJfEShEYN8Pt7lJa1oY4apl yi419TyR2rKRmJDHOlsdkODvisWCqI9Y/ifOCijo1T2IMneXyhNvzIQqsWZtFyPH lq8QKBwLEpn+6CMQKPlP8QIZnEiOcQjla712RPWeALxuOme2ALPsowE7LIG5ag7c tBTdhCXO9iCNR+k4IpvsNqK9nJ+AXYEeubDzmrfV0kkPy4F6n6YfOk4cLnVRIcvy ZTO2Q0mCFwODlyzRbmX5UjrqLwJD3gvNWCebNn+URAF/qY1nJv9gIaWm9HE94EJz 4thO8Qpz8xYBuO2IfE1w6V82Den0JQZZ94Q== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrudegvddgkeejucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefhvfevufffkffoggfgsedtkeertd ertddtnecuhfhrohhmpefgugcuvegrthhmuhhruceovggusegtrghtmhhurhdruhhkqeen ucggtffrrghtthgvrhhnpeeggeduudefteejheeuheeghfffleffvedtffduhfeihfeife ekvdfhleegleeufeenucffohhmrghinhepugifrghrfhhsthgurdhorhhgpdhgnhhurdho rhhgpdhgihhthhhusgdrtghomhdpshhouhhrtggvfigrrhgvrdhorhhgnecuvehluhhsth gvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepvggusegtrghtmhhurhdr uhhk X-ME-Proxy: Feedback-ID: i5729427b:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sat, 4 Feb 2023 11:23:29 -0500 (EST) From: Ed Catmur To: gdb-patches@sourceware.org Cc: Ed Catmur Subject: [PATCH] Support DWARF tags for C++11 variadic templates Date: Sat, 4 Feb 2023 17:23:21 +0100 Message-Id: <20230204162321.2640-1-ed@catmur.uk> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Spam-Status: No, score=-13.2 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_SHORT, KAM_STOCKGEN, RCVD_IN_DNSWL_LOW, SPF_HELO_PASS, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) 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: , Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" This patch adds support for DW_TAG_GNU_formal_parameter_pack and DW_TAG_GNU_template_parameter_pack, added to DWARF in March 2009 for C++11 variadic templates[1]. They are not currently emitted thanks to a typo[2] but the fix is trivial[3] and has been repeatedly submitted[4] to gcc; I'm not sure what else I can do to get it accepted; regardless, anyone building their own compiler can still make use of this. This implementation synthesizes type and parameter names as T#n, p#n e.g. Args#1, args#1. This is a pretty simple approach but it seems to work OK and is compatible with the old style type and parameter names emitted by old versions of gcc and when it's writing stabs+ format, meaning that any debugger scripts will continue to work. 1. http://wiki.dwarfstd.org/index.php?title=C%2B%2B0x:_Variadic_templates 2. https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70536 3. https://github.com/ecatmur/gcc/pull/5 4. https://gcc.gnu.org/pipermail/gcc-patches/2023-January/609659.html PR. https://sourceware.org/bugzilla/show_bug.cgi?id=17272 --- gdb/dwarf2/read.c | 71 ++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 67 insertions(+), 4 deletions(-) diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c index ee4e7c1530..7591be5764 100644 --- a/gdb/dwarf2/read.c +++ b/gdb/dwarf2/read.c @@ -12103,7 +12103,8 @@ read_func_scope (struct die_info *die, struct dwarf2_cu *cu) for (child_die = die->child; child_die; child_die = child_die->sibling) { if (child_die->tag == DW_TAG_template_type_param - || child_die->tag == DW_TAG_template_value_param) + || child_die->tag == DW_TAG_template_value_param + || child_die->tag == DW_TAG_GNU_template_parameter_pack) { templ_func = new (&objfile->objfile_obstack) template_symbol; templ_func->subclass = SYMBOL_TEMPLATE; @@ -12152,6 +12153,23 @@ read_func_scope (struct die_info *die, struct dwarf2_cu *cu) if (arg != NULL) template_args.push_back (arg); } + else if (child_die->tag == DW_TAG_GNU_template_parameter_pack) + { + struct die_info *pack_die; + for (pack_die = child_die->child; pack_die; pack_die = pack_die->sibling) + { + struct symbol *arg = new_symbol (pack_die, NULL, cu); + + if (arg != NULL) + template_args.push_back (arg); + } + } + else if (child_die->tag == DW_TAG_GNU_formal_parameter_pack) + { + struct die_info *pack_die; + for (pack_die = child_die->child; pack_die; pack_die = pack_die->sibling) + process_die (pack_die, cu); + } else process_die (child_die, cu); child_die = child_die->sibling; @@ -16639,6 +16657,11 @@ read_subroutine_type (struct die_info *die, struct dwarf2_cu *cu) { if (child_die->tag == DW_TAG_formal_parameter) nparams++; + else if (child_die->tag == DW_TAG_GNU_formal_parameter_pack) + { + child_die = child_die->child; + continue; + } else if (child_die->tag == DW_TAG_unspecified_parameters) ftype->set_has_varargs (true); @@ -16714,6 +16737,11 @@ read_subroutine_type (struct die_info *die, struct dwarf2_cu *cu) ftype->field (iparams).set_type (arg_type); iparams++; } + else if (child_die->tag == DW_TAG_GNU_formal_parameter_pack) + { + child_die = child_die->child; + continue; + } child_die = child_die->sibling; } } @@ -20847,13 +20875,16 @@ new_symbol (struct die_info *die, struct type *type, struct dwarf2_cu *cu, sym->set_type (type); else sym->set_type (die_type (die, cu)); - attr = dwarf2_attr (die, + struct die_info *line_file_die = die; + if (die->tag == DW_TAG_formal_parameter && die->parent && die->parent->tag == DW_TAG_GNU_formal_parameter_pack) + line_file_die = die->parent; + attr = dwarf2_attr (line_file_die, inlined_func ? DW_AT_call_line : DW_AT_decl_line, cu); if (attr != nullptr) sym->set_line (attr->constant_value (0)); - attr = dwarf2_attr (die, + attr = dwarf2_attr (line_file_die, inlined_func ? DW_AT_call_file : DW_AT_decl_file, cu); if (attr != nullptr && attr->is_nonnegative ()) @@ -21073,6 +21104,8 @@ new_symbol (struct die_info *die, struct type *type, struct dwarf2_cu *cu, list_to_add = cu->list_in_scope; } break; + case DW_TAG_GNU_formal_parameter_pack: + break; case DW_TAG_unspecified_parameters: /* From varargs functions; gdb doesn't seem to have any interest in this information, so just ignore it for now. @@ -22081,8 +22114,11 @@ dwarf2_name (struct die_info *die, struct dwarf2_cu *cu) if (attr_name == nullptr && die->tag != DW_TAG_namespace && die->tag != DW_TAG_class_type + && die->tag != DW_TAG_formal_parameter && die->tag != DW_TAG_interface_type && die->tag != DW_TAG_structure_type + && die->tag != DW_TAG_template_type_param + && die->tag != DW_TAG_template_value_param && die->tag != DW_TAG_namelist && die->tag != DW_TAG_union_type && die->tag != DW_TAG_template_type_param @@ -22111,9 +22147,36 @@ dwarf2_name (struct die_info *die, struct dwarf2_cu *cu) return attr_name; return CP_ANONYMOUS_NAMESPACE_STR; - /* DWARF does not actually require template tags to have a name. */ + case DW_TAG_formal_parameter: case DW_TAG_template_type_param: case DW_TAG_template_value_param: + if (!attr + && die->parent + && (die->parent->tag == DW_TAG_GNU_formal_parameter_pack + || die->parent->tag == DW_TAG_GNU_template_parameter_pack)) + { + const char *parent_name; + int ordinal = 0; + struct die_info *child_die; + size_t size; + char *name; + parent_name = dwarf2_name(die->parent, cu); + if (!parent_name) + return NULL; + for (child_die = die->parent->child; child_die != die; child_die = child_die->sibling) + ++ordinal; + size = snprintf(NULL, 0, "%s#%d", parent_name, ordinal) + 1; + name = ((char *) obstack_alloc (&cu->per_objfile->per_bfd->obstack, size)); + snprintf(name, size, "%s#%d", parent_name, ordinal); + return name; + } + if (die->tag == DW_TAG_formal_parameter) + { + if (!attr || attr_name == NULL) + return NULL; + break; + } + /* DWARF does not actually require template tags to have a name. */ if (attr_name == nullptr) return unnamed_template_tag_name (die, cu); /* FALLTHROUGH. */