2013-06-20 60 views
1

我在我的Mac上使用支持C++ 11功能的g ++ 4.8。在gdb中调试映射<int,unique_ptr <A>>

/opt/local/bin/g++-mp-4.8 

我也使用gdb 6.3.50。

GNU gdb 6.3.50-20050815 (Apple version gdb-1822) (Sun Aug 5 03:00:42 UTC 2012) 
Copyright 2004 Free Software Foundation, Inc. 
GDB is free software, covered by the GNU General Public License, and you are 
welcome to change it and/or distribute copies of it under certain conditions. 
Type "show copying" to see the conditions. 
There is absolutely no warranty for GDB. Type "show warranty" for details. 
This GDB was configured as "x86_64-apple-darwin". 

我的代码有很多地图或载体具有的unique_ptr的,它是真正的痛苦来调试他们,我看到没有关于地图或矢量元素的信息。

我试图做一个实用方法,并在gdb中调用它们,但它似乎不工作。它不会抛出错误信息,但它也没有显示任何内容。

void testPrint(map<int, unique_ptr<GroupContextSummary>> & m, int i) 
{ 
    cout << m[i].get()->to_string() << endl; 
} 

有没有什么方法可以查看地图/矢量中的元素?

enter image description here

+0

我'call'迭代器的功能和操作的迭代后的结果评估。 – manasij7479

+1

可能重复的[如何在GDB中打印C++向量的元素?](http://stackoverflow.com/questions/253099/how-do-i-print-the-elements-of-ac-vector- in-gdb) – ks1322

+0

just'unique_ptr':https://stackoverflow.com/questions/22798601/how-to-debug-c11-code-with-unique-ptr-in-ddd-or-gdb –

回答

0

这个职位有一些迹象表明GDB 7可能会解决这个问题。

Gdb on MacOSX lion

brew install https://raw.github.com/Homebrew/homebrew-dupes/master/gdb.rb 

然后我需要协同设计。

==> ./configure --prefix=/usr/local/Cellar/gdb/7.6 --with-python=/usr --with-system-readline 
==> make 
==> make install 
==> Caveats 
gdb requires special privileges to access Mach ports. 
You will need to codesign the binary. For instructions, see: 

    http://sourceware.org/gdb/wiki/BuildingOnDarwin 

或者你可以从sudo运行gdb。

Gdb 7.0可以编译并构建在我的Mac上,但它不能正确调试程序。我希望Mac上的下一版gdb能够解决这些问题。

相关问题