1

I use g++ 4.8 that supports c++ 11 feature on my mac.

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

I also use 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.

I tried to make a utility method and call them in gdb, but it doesn't seem to work. 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?

enter image description here

prosseek
  • 182,215
  • 215
  • 566
  • 871

2 Answers2

0

This post has some hints that gdb 7 may solve this issue.

Gdb on MacOSX lion

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.

Gdb 7.0 could be compiled and built on my Mac, but it doesn't correctly debug the program. I hope next version of gdb on Mac will solve the issues.

Community
  • 1
  • 1
prosseek
  • 182,215
  • 215
  • 566
  • 871
0

I could debug map and vector without using gdb 7, but with pretty printer setup.

This site(http://www.yolinux.com/TUTORIALS/GDB-Commands.html#STLDEREF) has the procedure. In short.

  1. Copy the .gdbinit in ~/
  2. Restart the gdb
  3. Use pvector for printing vectors.

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

Community
  • 1
  • 1
prosseek
  • 182,215
  • 215
  • 566
  • 871