Bug 30161

Summary: GCC should generate dwarf info about template parameters
Product: gcc Reporter: Jason Merrill <jason>
Component: debugAssignee: Dodji Seketeli <dodji>
Status: RESOLVED FIXED    
Severity: enhancement CC: bkoz, dodji, drow, fang, gcc-bugs, jkratochvil, rguenth, swagiaal, tromey
Priority: P3    
Version: 4.3.0   
Target Milestone: ---   
Host: Target:
Build: Known to work:
Known to fail: Last reconfirmed: 2008-12-02 09:01:51
Bug Depends on:    
Bug Blocks: 7932, 29433    

Description Jason Merrill 2006-12-12 03:43:43 UTC
GCC doesn't currently generate DW_TAG_template_*_param, and it should to improve C++ debuggability (and allow us to shorten the DW_AT_names of template instantiations).
Comment 1 Andrew Pinski 2006-12-12 06:33:36 UTC
This seems related to PR 7932.
Comment 2 Tom Tromey 2008-11-08 00:57:04 UTC
*** Bug 38058 has been marked as a duplicate of this bug. ***
Comment 3 Dodji Seketeli 2008-12-15 10:01:54 UTC
Started looking at this. Got a work in progress patch at http://www.seketeli.org/dodji/patches/gcc/PR30161-patch.txt. It's not ready for review yet, I am just backuping it online.
Comment 4 Dodji Seketeli 2008-12-26 18:32:36 UTC
More work-in-progress patches for this PR can be checked out at http://www.seketeli.org/dodji/patches/gcc/PR30161 .
Please note that each patch there is self contained and passes regtests on x86_64. The tests accompanying the patches also passes.
Comment 5 Dodji Seketeli 2009-03-11 17:16:51 UTC
Work in progress patches are now at http://people.redhat.com/~dseketel/gcc/PR30161
Comment 6 Dodji Seketeli 2009-03-11 17:54:57 UTC
Quick Status of http://people.redhat.com/~dseketel/gcc/PR30161/PR30161-patch-v4.txt:

The patch generates DW_TAG_template_type_param and DW_TAG_template_value_param for template type parameters as well as non-type parameters. Debug info for template parameter packs (parameters of variadic templates) are also generated.

Template template parameters are not supported as it seems the DWARF3 spec doesn't support those. Please look at the examples at the end of the patch to see the type of template parameters for which debug info is generated by the patch today.
Comment 7 Dodji Seketeli 2009-08-13 19:24:34 UTC
A candidate patch was sent to http://gcc.gnu.org/ml/gcc-patches/2009-08/msg00703.html .
Comment 8 Dodji Seketeli 2009-08-31 21:48:21 UTC
Subject: Bug 30161

Author: dodji
Date: Mon Aug 31 21:48:04 2009
New Revision: 151249

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=151249
Log:
Emit DWARF for template parameters (PR debug/30161)

ChangeLog:
	PR debug/30161
	* include/dwarf2.h (enum dwarf_tag): Added
	DW_TAG_GNU_template_template_param
	(enum dwarf_attribute): Added DW_AT_GNU_template_name.

gcc/ChangeLog:
	PR debug/30161
	* cgraph.h (cgraph_get_node): Declare ...
	* cgraph.c (cgraph_get_node): ... new function.
	* dwarf2out.c (gen_generic_params_dies,
	generic_parameter_die, tree_add_const_value_attribute_for_decl,
	make_ith_pack_parameter_name,
	append_entry_to_tmpl_value_parm_die_table,
	gen_remaining_tmpl_value_param_die_attribute): New functions.
	(gen_subprogram_die): Generate debug info for template parameters
	if debug info level is higher than DINFO_LEVEL_TERSE.
	Use tree_add_const_value_attribute_for_decl instead of
	tree_add_const_value_attribute.
	(gen_const_die): Use tree_add_const_value_attribute_for_decl
	instead of tree_add_const_value_attribute.
	(gen_struct_or_union_type_die): Generate debug
	info for template parameters if debug info level is higher than
	DINFO_LEVEL_TERSE.
	(tree_add_const_value_attribute): Handle integral and pointer
	constants. Update comment.
	(dwarf_tag_name): Support DW_TAG_GNU_template_template_param.
	(dwarf_attr_name): Support DW_AT_GNU_template_name.
	(reference_to_unused): Fix thinko. Remove redundant predicates from
	tests.
	(tree_add_const_value_attribute): Make this work for constant
	expressions only.
	tree_add_const_value_attribute_for_decl is to be used for variable
	DECLs now.
	(add_location_or_const_value_attribute): Use
	tree_add_const_value_attribute_for_decl now.
	(dwarf2out_finish): Emit the DW_AT_const_value attribute of
	DW_TAG_template_value_param DIEs after function DIEs have been
	emitted.
	* langhooks.h (lang_hooks_for_types): Add
	get_argument_pack_elems.
	(lang_hooks_for_decls): Add generic_generic_parameter_decl_p.
	(lang_hooks): Added get_innermost_generic_parms,
	get_innermost_generic_args.
	* langhooks-def.h (LANG_HOOKS_GET_INNERMOST_GENERIC_PARMS,
	LANG_HOOKS_GET_INNERMOST_GENERIC_ARGS,
	LANG_HOOKS_GET_ARGUMENT_PACK_ELEMS,
	LANG_HOOKS_GENERIC_GENERIC_PARAMETER_DECL_P): New language hooks.

gcc/cp/ChangeLog:
	PR debug/30161
	* cp-tree.h (get_template_info): Parameter should be const.
	(CLASSTYPE_SPECIALIZATION_OF_PRIMARY_TEMPLATE_P): Fix typo.
	(get_template_argument_pack_elems,
	get_primary_template_innermost_parameters,
	get_template_innermost_arguments, template_template_parameter_p):
	Declare ...
	* pt.c (get_template_argument_pack_elems,
	get_template_innermost_parameters, get_template_innermost_arguments,
	template_template_parameter_p):
	... New C++ front end implementation of new language hooks.
	(primary_template_instantiation_p): New private helper.
	(make_ith_pack_parameter_name): Use snprintf and strnlen instead of
	printf and strlen.
	(get_template_info): Const-ify parameter.
	* cp-lang.c (LANG_HOOKS_GET_INNERMOST_GENERIC_PARMS,
	LANG_HOOKS_GET_INNERMOST_GENERIC_ARGS,
	LANG_HOOKS_GET_ARGUMENT_PACK_ELEMS,
	LANG_HOOKS_GENERIC_TYPE_PARAMETER_DECL_P): Initialize these
	interfaces for the C++ front-end.

gcc/testsuite/ChangeLog:
	PR debug/30161
	* g++.dg/debug/dwarf2/template-params-1.C: New test.
	* g++.dg/debug/dwarf2/template-params-2.C: Likewise.
	* g++.dg/debug/dwarf2/template-params-3.C: Likewise.
	* g++.dg/debug/dwarf2/template-params-4.C: Likewise.
	* g++.dg/debug/dwarf2/template-params-5.C: Likewise.
	* g++.dg/debug/dwarf2/template-params-6.C: Likewise.
	* g++.dg/debug/dwarf2/template-func-params-1.C: Likewise.
	* g++.dg/debug/dwarf2/template-func-params-2.C: Likewise.
	* g++.dg/debug/dwarf2/template-func-params-3.C: Likewise.
	* g++.dg/debug/dwarf2/template-func-params-4.C: Likewise.
	* g++.dg/debug/dwarf2/template-func-params-5.C: Likewise.
	* g++.dg/debug/dwarf2/template-func-params-6.C: Likewise.
	* g++.dg/debug/dwarf2/template-func-params-7.C: Likewise.

Added:
    trunk/gcc/testsuite/g++.dg/debug/dwarf2/template-func-params-1.C
    trunk/gcc/testsuite/g++.dg/debug/dwarf2/template-func-params-2.C
    trunk/gcc/testsuite/g++.dg/debug/dwarf2/template-func-params-3.C
    trunk/gcc/testsuite/g++.dg/debug/dwarf2/template-func-params-4.C
    trunk/gcc/testsuite/g++.dg/debug/dwarf2/template-func-params-5.C
    trunk/gcc/testsuite/g++.dg/debug/dwarf2/template-func-params-6.C
    trunk/gcc/testsuite/g++.dg/debug/dwarf2/template-func-params-7.C
    trunk/gcc/testsuite/g++.dg/debug/dwarf2/template-params-1.C
    trunk/gcc/testsuite/g++.dg/debug/dwarf2/template-params-2.C
    trunk/gcc/testsuite/g++.dg/debug/dwarf2/template-params-3.C
    trunk/gcc/testsuite/g++.dg/debug/dwarf2/template-params-4.C
    trunk/gcc/testsuite/g++.dg/debug/dwarf2/template-params-5.C
    trunk/gcc/testsuite/g++.dg/debug/dwarf2/template-params-6.C
Modified:
    trunk/ChangeLog
    trunk/gcc/ChangeLog
    trunk/gcc/cgraph.c
    trunk/gcc/cgraph.h
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/cp-lang.c
    trunk/gcc/cp/cp-tree.h
    trunk/gcc/cp/pt.c
    trunk/gcc/dwarf2out.c
    trunk/gcc/langhooks-def.h
    trunk/gcc/langhooks.h
    trunk/gcc/testsuite/ChangeLog
    trunk/include/dwarf2.h

Comment 9 Dodji Seketeli 2009-08-31 21:55:14 UTC
Fixed in trunk.

This patch implements some GNU extensions to represent template parameter packs and template template parameters. The extension is documented at http://gcc.gnu.org/wiki/TemplateParmsDwarf .

Now I guess some discussions should happen at the DWARF level to know see how the GNU extension can evolve and turn into a proper DWARF proposal. So this patch might see some modifications in a near future.

I will open other bugs for that in due time.
Comment 10 Dodji Seketeli 2009-09-01 08:46:05 UTC
Subject: Bug 30161

Author: dodji
Date: Tue Sep  1 08:45:38 2009
New Revision: 151262

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=151262
Log:
Fix bootstrap after patch PR debug/30161

gcc/ChangeLog:
	PR bootstrap/41205
	Fix AIX bootstrap after PR debug/30161
	* dwarf2out.c (make_ith_pack_parameter_name): Don't used strnlen
	that is a GNU extension.
	(tmpl_value_parm_die_table): Move the definition of this global
	outside #ifdef DWARF2_DEBUGGING_INFO region.

gcc/cp/ChangeLog:
	PR bootstrap/41205
	* pt.c (make_ith_pack_parameter_name): Don't use strnlen that is a
	GNU extension.

Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/pt.c
    trunk/gcc/dwarf2out.c

Comment 11 Tom Tromey 2011-05-23 16:34:27 UTC
See PR 33861 for another example of where an extension
would seem to be necessary.