检查gdb中的模板参数包

Bar*_*rry 5 c++ gcc gdb variadic-templates

我正在尝试调试以下简单程序:

#include <iostream>

template <class... Args>
void printAll(Args&&... args) {
    using swallow = int[];
    swallow{0,
        (std::cout << args, 0)...
    };  
}

int main() {
    printAll(1, "23", 4); 
}
Run Code Online (Sandbox Code Playgroud)

用gcc 4.9.2编译使用:

g++ -std=c++11 -g -O0 foo.cxx
Run Code Online (Sandbox Code Playgroud)

然后使用gdb 7.9进行调试:

gdb a.out

(gdb) break foo.cxx:5
Breakpoint 1 at 0x400884: file foo.cxx, line 5.
(gdb) run
Starting program: /..[snip]../a.out 

Breakpoint 1, printAll<int, char const (&) [3], int>(int&&, char const (&) [3], int&&) () at foo.cxx:6
6       swallow{0,
(gdb) bt
#0  printAll<int, char const (&) [3], int>(int&&, char const (&) [3], int&&) () at foo.cxx:6
#1  0x0000000000400813 in main () at foo.cxx:12
Run Code Online (Sandbox Code Playgroud)

我的功能正常,但我无法检查参数包:

(gdb) info args
No arguments.
(gdb) print args
No symbol "args" in current context.
(gdb) inspect args
No symbol "args" in current context.
Run Code Online (Sandbox Code Playgroud)

我如何实际检查论点?

eca*_*mur 5

相关:在gdb中显示参数包的值

这里有两个问题。第一是,克++发射参数包使用标签dwarf格式的调试信息DW_TAG_GNU_template_parameter_packDW_TAG_GNU_formal_parameter_pack,该GDB 尚不支持(补丁附后)

即使这个问题解决了,我们也会遇到另一个问题,那就是g ++发出的调试信息被破坏了。它缺少参数名称(DW_AT_name)(已附加补丁)

TBH gdb对C ++ 11的支持非常糟糕(不足为奇,因为它已经被长期抛弃了);C ++ 11的另一个show-showstopper错误是它不支持rvalue引用(DW_TAG_rvalue_reference_type)(已附加补丁),并输出诸如的错误消息<unknown type in /tmp/a.out, CU 0x0, DIE 0x7f>

解决方法(不使用clang或不使用DW_TAG_GNU_template_parameter_pack标记的较旧版本的g ++ ,例如4.4.7)是使用带有GCC扩展名stabs调试格式

g++ -std=c++11 -gstabs+ -O0 foo.cxx
Run Code Online (Sandbox Code Playgroud)

(gdb) s
void printAll<int, char const (&) [3], int>(int, int&&, char const (&) [3], int&&) (i=999, args#0=@0x7fffffffe45c: 1, args#1=..., args#2=@0x7fffffffe458: 4)
    at p.cpp:7
7       swallow{0,
(gdb) p 'args#0'
$1 = (int &) @0x7fffffffe45c: 1
Run Code Online (Sandbox Code Playgroud)