How to debug C++11 code with unique_ptr in DDD (or gdb)?
This problem is actually not related to C++11, unique_ptr or pretty printing. The problem is that gcc does not emit code for std::unique_ptr::operator* that could be called by gdb to dereference the unique_ptr. If you for instance add *pTest;
to your code then gdb does perform the dereferencing.
A similar problem is described in the SO post How to `print`/evaluate c++ template functions in gdb. Almost the same problem is described for an auto_ptr at https://sourceware.org/ml/archer/2012-q1/msg00003.html. If I understand the thread correctly one workaround would be to patch the pretty printer and also print out the dereferenced pointer when printing the unique_ptr. A gdb bug report can be found at http://sourceware.org/bugzilla/show_bug.cgi?id=12937.
The gdb wiki at https://sourceware.org/gdb/wiki/STLSupport describes more pretty printing solutions, which could have other workarounds.
Edit: A more elegant solution forcing the compiler to emit code for all member templates including operator* is to explicitly instantiate the class:
template class std::unique_ptr<MyType>;
Debugging mapint, unique_ptrA in gdb
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.
- Copy the .gdbinit in ~/
- Restart the gdb
- 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
How to print out the content in vectorunique_ptr with gdb on Mac OS X
I could use Xcode; lldb works fine on Xcode.
How to view the internal data of a smart pointer inside gdb?
Try the following:
p *si._M_ptr
Now, this assumes that you're using libstdc++.so
, given the output for p si
.
Alternatively, you could use the value 0x614c20
directly (from your output):
p {int}0x614c20
Both should display the value 5
.
How to access target of std::tr1::shared_ptr in GDB
Try with
(gdb) p (*sharedPtr.get())
that function returns the a pointer to the object owned by the smart pointer.
Related Topics
How to Embed Node.Js Interpreter into C/C++
Observer Design Pattern in C++
How to Perform Rgb->Yuv Conversion in C/C++
Array[Byte] to Hbitmap or Cbitmap
How to Set the Background Image in Qt Stylesheet
How to Create a N Way Cartesian Product of Type Lists in C++
Math Interface VS Cmath in C++
Convert from Utf-8 to Unicode C++
What Happens When Calling the Destructor of a Thread Object That Has a Condition Variable Waiting
Some Issues About Cygwin[Linux in Windows] (Socket,Thread,Other Programming and Shell Issues)
Std::Istream_Iterator<> with Copy_N() and Friends
Does Class/Function Order Matter in C++
C++ Error on Ms Visual Studio: "Windows Has Triggered a Breakpoint in Javaw.Exe"
How to Find the Minimum Value in a Map
Multithreading on Dual Core MAChine
Trouble with Template Parameters Used in MACros