Bug 28946 - Missing template paramater pack support
Summary: Missing template paramater pack support
Status: RESOLVED DUPLICATE of bug 17272
Alias: None
Product: gdb
Classification: Unclassified
Component: c++ (show other bugs)
Version: 11.1
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2022-03-05 16:08 UTC by Jan Engelhardt
Modified: 2023-01-17 01:00 UTC (History)
4 users (show)

See Also:
Host:
Target:
Build:
Last reconfirmed: 2022-03-06 00:00:00
Project(s) to access:
ssh public key:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jan Engelhardt 2022-03-05 16:08:13 UTC
Input
=====
```
template<typename... T> void f(T&&...zzargs) {}
int main() { f(0); }
```

g++-11 -Wall -ggdb3 x.cpp

Observed output
===============
ยป gdb a.out
GNU gdb (GDB; openSUSE Tumbleweed) 11.1
...
(gdb) b main
(gdb) r
...
Breakpoint 1, main () at x.cpp:2
2       int main() { f(0); }
Missing separate debuginfos, use: zypper install libgcc_s1-debuginfo-11.2.1+git1173-2.3.x86_64 libstdc++6-debuginfo-11.2.1+git1173-2.3.x86_64
(gdb) s
f<int> () at x.cpp:1
1       template<typename... T> void f(T&&...zzargs) {}
(gdb) info args
No arguments.
(gdb) p zzargs
No symbol "zzargs" in current context.


Expected output
===============

(gdb) info args
zzargs = {0}
(gdb) p zzargs
$1 = {0}

or something of the sort.
Comment 1 Hannes Domani 2022-03-06 14:55:16 UTC
Note that gcc currently doesn't write the name of the parameter pack in the debug information:

 <2><95>: Abbrev Number: 5 (DW_TAG_GNU_formal_parameter_pack)
    <96>   DW_AT_decl_file   : 1
    <97>   DW_AT_decl_line   : 1
    <98>   DW_AT_decl_column : 35
 <3><99>: Abbrev Number: 6 (DW_TAG_formal_parameter)
    <9a>   DW_AT_type        : <0xaa>
    <9e>   DW_AT_location    : 2 byte block: 91 0 	(DW_OP_fbreg: 0)
 <3><a1>: Abbrev Number: 0

Apparently this has been reported already some time ago:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70536

So even if gdb would make use of DW_TAG_GNU_formal_parameter_pack, it couldn't show it as `zzargs` in the example.
Comment 2 David Blaikie 2022-10-27 21:56:51 UTC
+1 to this from a Clang developer.

Clang does name the template parameter pack.
```
0x0000039a:   DW_TAG_structure_type
                DW_AT_name      ("single_and_pack<int, int>")
                DW_AT_byte_size (1)
                DW_AT_decl_file ("/usr/local/google/home/blaikie/dev/scratch/test.cpp")
                DW_AT_decl_line (9)
                DW_AT_decl_column       (8)
                DW_AT_sibling   (0x000003b7)

0x000003a4:     DW_TAG_template_type_parameter
                  DW_AT_name    ("T1")
                  DW_AT_type    (0x00000094 "int")

0x000003ac:     DW_TAG_GNU_template_parameter_pack
                  DW_AT_name    ("Ts")

0x000003b0:       DW_TAG_template_type_parameter
                    DW_AT_type  (0x00000094 "int")

0x000003b5:       NULL

0x000003b6:     NULL
```

And there's an extra bonus reason from Clang's side:

I'm working on a mode for clang (called -gsimple-template-names) that will produce DW_AT_names for templates without template parameters in some cases (so in the above example "single_and_pack") and so working around this bug (missing structural/API access to template parameters) by using the string name won't be possible with debug info like this)

(total aside, though this is probably for a conversation on a gdb mailing list - it does look like gdb does quite a bit of work that looks /a lot/ like it's intending to support debug info like I described above... anyone happen to have context on that?)
Comment 3 Hannes Domani 2023-01-14 12:58:09 UTC
Is related to (or a duplicate of) PR17272.
Comment 4 David Blaikie 2023-01-14 19:13:14 UTC
(In reply to Hannes Domani from comment #3)
> Is related to (or a duplicate of) PR17272.

Yeah, dup seems fine
Comment 5 Tom Tromey 2023-01-16 23:37:45 UTC
Dup.

*** This bug has been marked as a duplicate of bug 17272 ***
Comment 6 Ed Catmur 2023-01-17 01:00:05 UTC
Hi David, can you let me know whether clang would be able to make use of the fix in #17272 (see attached patch, linked PR, linked ML post, whatever works for you)? It would be useful to know whether someone would be able to make use of it, even if gcc aren't interested in supporting DW_TAG_GNU_template_parameter_pack.