1

我对 gdb 不是很熟悉,并且不知道如何在 gdb 手册中查找这种情况。

我正在尝试打印std::arraygdb 中的内容。下面是我试图在 gdb 中调试的用例。

template<unsigned int N>
double dotprod(const std::array<double, N> &v1, const std::array<double, N> &v2)
{
     ...
}

在此函数中,我尝试打印p v1. 它打印(const mosp::Point<2u> *) 0x7fffffffc150。如何打印的内容v1

4

2 回答 2

2

我一直在使用 gdb 的一个技巧是定义我自己的打印函数。

例如:

void print_int_array(array<int> *a) {
    for (auto it = a->begin(); it != a->end(); ++it)
        cout << *it << endl;
}

然后从 gdb 提示符下,您可以运行:

p print_int_array(&array_variable_name)

问题是这需要你定义几个函数(注意:gdb 可能有更好的模板支持,你可以使用具有显式实例化的模板,但我很保守)

于 2013-07-19T23:55:28.483 回答
0

gdb 7.6 没有这个问题。

[root@localhost ~]# gdb ./a.out 
GNU gdb (GDB) Fedora (7.6-30.fc19)
Copyright (C) 2013 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it. 
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "i686-redhat-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from /root/a.out...done.
(gdb) b main
Breakpoint 1 at 0x80485b9: file a.cpp, line 11. 
(gdb) r
Starting program: /root/a.out 

Breakpoint 1, main () at a.cpp:11
11              std::array<double, 5> a = {0, 1.1, 2.2, 3.3, 4.4};
Missing separate debuginfos, use: debuginfo-install glibc-2.17-4.fc19.i686 libgcc-
4.8.1-1.fc19.i686 libstdc++-4.8.1-1.fc19.i686
(gdb) n
12              std::array<double, 5> b = {5.5, 6.6, 7.7, 8.8, 9.9};
(gdb) 
13              dotprod(a, b); 
(gdb) s
dotprod<5u> (v1=..., v2=...) at a.cpp:7
7               return 0;
(gdb) p v1
$1 = (const std::array<double, 5u> &) @0xbffff640: {_M_elems = {0, 1.1000000000000001, 2.2000000000000002, 
    3.2999999999999998, 4.4000000000000004}}
(gdb)
于 2013-07-20T01:21:21.647 回答