简体   繁体   English

调试图 <int, unique_ptr<A> &gt;在gdb中

[英]Debugging map<int, unique_ptr<A>> in gdb

I use g++ 4.8 that supports c++ 11 feature on my mac. 我在Mac上使用支持c ++ 11功能的g ++ 4.8。

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

I also use gdb 6.3.50. 我也使用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".

My code has a lot of maps or vectors that has unique_ptr, and it's really pain to debug them as I see no information about the elements in the map or vector. 我的代码中有很多具有unique_ptr的地图或向量,调试它们非常痛苦,因为我看不到有关地图或向量中元素的信息。

I tried to make a utility method and call them in gdb, but it doesn't seem to work. 我试图制作一个实用程序方法,并在gdb中调用它们,但它似乎不起作用。 It doesn't throw error message, but it also shows nothing. 它不会抛出错误消息,但是也什么也没显示。

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

Are there any ways to see the elements in the map/vector? 有什么方法可以查看地图/矢量中的元素?

在此处输入图片说明

This post has some hints that gdb 7 may solve this issue. 这篇文章暗示gdb 7可以解决此问题。

Gdb on MacOSX lion MacOSX Lion上的Gdb

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

Then I needed codesign. 然后我需要代码签名。

==> ./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

Or you can just run gdb from sudo. 或者,您也可以从sudo运行gdb。

Gdb 7.0 could be compiled and built on my Mac, but it doesn't correctly debug the program. Gdb 7.0可以在Mac上进行编译和构建,但是无法正确调试该程序。 I hope next version of gdb on Mac will solve the issues. 我希望Mac上的下一版gdb能够解决问题。

I could debug map and vector without using gdb 7, but with pretty printer setup. 我可以在不使用gdb 7的情况下调试地图和矢量,但是可以使用漂亮的打印机设置。

This site( http://www.yolinux.com/TUTORIALS/GDB-Commands.html#STLDEREF ) has the procedure. 该站点( http://www.yolinux.com/TUTORIALS/GDB-Commands.html#STLDEREF )具有该过程。 In short. 简而言之。

  1. Copy the .gdbinit in ~/ 将.gdbinit复制到〜/
  2. Restart the gdb 重新启动gdb
  3. Use pvector for printing vectors. 使用pvector来打印矢量。

Please refer to this page: https://stackoverflow.com/a/17246292/260127 And this page: How to print out the content in vector<unique_ptr> with gdb on Mac OS X 请参考此页面: https : //stackoverflow.com/a/17246292/260127而此页面: 如何在Mac OS X上使用gdb打印出vector <unique_ptr>中的内容

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM