2013-07-04 3 views
1

gdb에 익숙하지 않아 gdb 매뉴얼에서이 시나리오를 찾는 방법을 알 수 없습니다.gdb에`std :: array` 내용을 출력하는 법?

std::array의 내용을 gdb에 인쇄하려고합니다. 아래 gdb에서 디버깅하려고하는 usecase입니다.

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의 내용을 인쇄하려면 어떻게해야합니까?

+0

gdb 버전이란 무엇입니까? –

+0

GNU gdb (GDB) 7.5.91.20130417-cvs-ubuntu – mutelogan

+2

gdb의이 특정 버전의 버그이거나 바이너리가 동일한 함수를 병합하는 링커 일 수 있습니다. 일반적으로 그것은 단지 당신에게 인간이 읽을 수있는 가치를 인쇄해야합니다. 'mosp :: Point'는 당신의 소스에서 볼 수 없다. 아마도 gdb가 혼란 스럽다는 것을 의미 할 것이다. 'p * ((std :: vector *) (v1))'시도해보십시오. 도움이 될 것이라고 약속 할 수는 없습니다. –

답변

0

gdb 7.6 아니오.

[[email protected] ~]# 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) 
+0

업데이트 해 주셔서 감사합니다. – mutelogan

1

gdb에서 내가 사용해온 속임수는 내 자신의 인쇄 기능을 정의하는 것입니다. 그리고 GDB에서

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

가 실행할 수있는 프롬프트 : 예를 들어

p print_int_array(&array_variable_name) 

문제는이 여러 기능을 정의 할 필요하다는 것이다 (참고 : GDB가 더 나은 템플릿 지원이있을 수 있습니다 및 당신은 템플릿을 명시 적 인스턴스화와 함께 사용할 수 있지만 보수적입니다.)

+0

업데이트 해 주셔서 감사합니다. 그것은 작동합니다. 하지만 내 코드에이 함수를 한 번 이상 호출하지 않으면이 메서드가 작동하지 않는 것처럼 보입니다. 결코이 문제는

set print object off
에 의해 해결됩니다. – mutelogan

관련 문제