检查gdb中的模板参数包 [英] Inspect template parameter pack in gdb

查看:277
本文介绍了检查gdb中的模板参数包的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图调试以下简单程序:

I'm trying to debug the following simple program:

#include <iostream>

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

int main() {
    printAll(1, "23", 4); 
}

使用gcc 4.9.2编译:

Compiled with gcc 4.9.2 using:

g++ -std=c++11 -g -O0 foo.cxx

然后使用gdb 7.9调试:

And then debugging with gdb 7.9 using:

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

我在正确的函数,但我没有办法检查参数包:

I'm in the right function, but I have no way to inspect the parameter pack:

(gdb) info args
No arguments.
(gdb) print args
No symbol "args" in current context.
(gdb) inspect args
No symbol "args" in current context.

如何实际检查参数?

推荐答案

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

这里有两个问题:首先是g ++使用标签以DWARF格式发出参数包调试信息 DW_TAG_GNU_template_parameter_pack DW_TAG_GNU_formal_parameter_pack ,其中gdb 尚未支持(修补附件)

There are two problems here; the first is that g++ emits parameter pack debugging information in the DWARF format using the tags DW_TAG_GNU_template_parameter_pack and DW_TAG_GNU_formal_parameter_pack, which gdb does not yet support (patch attached).

即使这是固定的,我们遇到另一个问题,这是调试信息g ++发射是破碎的;它缺少参数名称( DW_AT_name )(补丁附件)

Even when this is fixed, we run into another problem, which is that the debugging information g++ emits is broken; it's missing the parameter name (DW_AT_name) (patch attached).

TBH gdb对C ++ 11的支持是非常糟糕的(不足为奇, C ++ 11的另一个靠近showstopper的bug是它不支持右值引用( DW_TAG_rvalue_reference_type )(修补程序附加),打印错误消息如<未知类型在/tmp/a.out,CU 0x0,DIE 0x7f> ;

TBH gdb support for C++11 is pretty abysmal (unsurprising as it was effectively abandoned for so long); another near-showstopper bug for C++11 is that it doesn't support rvalue references (DW_TAG_rvalue_reference_type) (patch attached), printing error messages like <unknown type in /tmp/a.out, CU 0x0, DIE 0x7f>.

解决方法(除了使用clang或g ++的古代版本,不使用 DW_TAG_GNU_template_parameter_pack 标签,例如4.4.7)是要使用 stabs调试格式与gcc扩展

The workaround (other than using clang, or an ancient version of g++ that doesn't use the DW_TAG_GNU_template_parameter_pack tags, e.g. 4.4.7) is to use the stabs debugging format with GCC extensions:

g++ -std=c++11 -gstabs+ -O0 foo.cxx

(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

这篇关于检查gdb中的模板参数包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆