3

I'm trying to use C++11 feature on Mac OS X. I downloaded g++ 4.8.1 with port.

This is the test code.

class A
{
    int x;
public:
    A() {}
    ~A() {}
    A(A& a) {}
    A(int x) {this->x = x;}
    int get() {return x;}
};

int main()
{
    vector<unique_ptr<A>> v;
    auto a = new A(10);
    unique_ptr<A> pa(a);
    v.push_back(move(pa)); // move(pa);
    for (auto& i: v)
    {
        cout << i->get();
    }
}

It compiles well under g++ 4.8, and I could debug it using gdb. Following this page, I could print out STL vectors using vector v command.

However, with vector with unique_ptr, I got this error message in gdb.

enter image description here

Cannot perform pointer math on incomplete type "unique_ptr<A, std::default_delet
e<A> >", try casting to a known type, or void *.

What's the problem with it? How can I make unique_ptr complete type to get the content with gdb?

ADDED

I noticed that clang++ in Xcode 4.5 supports c++11 features, so the easiest way might be to use Xcode. I have some issue with command line though (lldb on xcode vs lldb on standalone)

Community
  • 1
  • 1
prosseek
  • 182,215
  • 215
  • 566
  • 871
  • 1
    Have you tried `($8)->get()`? It seems $8 is a pointer to a unique pointer... – kennytm Jun 22 '13 at 07:18
  • @Kenny TM: Yes I have : "Attempt to extract a component of a value that is not a struct or union" is an error message. – prosseek Jun 22 '13 at 10:33
  • you may try using an Ubuntu virtual machine, I own a macbook pro but almost stopped developing for c++ in it. I put a Parallels Ubuntu instance fullscreen and forget about OS X :-). What's awesome, I got better font display from the Ubuntu VM than the native OS X (non-retina display) http://imgur.com/a/2DAvL – oblitum Jun 23 '13 at 02:15
  • @chico - I think mac has stdc++ as default: http://stackoverflow.com/questions/14972425/should-i-use-libc-or-libstdc – prosseek Jun 23 '13 at 02:17
  • non-OSX specific: https://stackoverflow.com/questions/22798601/how-to-debug-c11-code-with-unique-ptr-in-ddd-or-gdb – Ciro Santilli OurBigBook.com Sep 24 '17 at 12:01

2 Answers2

0

Use python printers for GDB, your printers seem like deprecated stuff:

enter image description here

Community
  • 1
  • 1
oblitum
  • 11,380
  • 6
  • 54
  • 120
  • It doesn't work (same print message) with my `GNU gdb (GDB) 7.5` install from port. I also tested with gdb 7.6 install from brew, but it also doesn't work. I copied the .gdbinit in the debugging directory to make sure it is read. – prosseek Jun 23 '13 at 01:44
  • @prosseek, it won't work with libc++, as your environment is OS X, I'm not sure whether you're using it. GCC python pretty printers support libstdc++. – oblitum Jun 23 '13 at 02:04
0

enter image description here

I could use Xcode; lldb works fine on Xcode.

prosseek
  • 182,215
  • 215
  • 566
  • 871