Details
-
Bug
-
Resolution: Done
-
Not Evaluated
-
Qt Creator 4.11.2
-
None
-
-
252a0431d126ea85a83b67ae266f2d3387d8bd0b
Description
Specs:
GDB 8.3
CXX_FLAGS (for debug builds): -g -O0
~/.gdbinit:
set pretty print on
set print elements 0
Details:
When using the PImpl pattern with std::unique_ptr or std::shared_ptr to store the PImpl member, sometimes the values of the PImpl member cannot be expanded in the Variables window beyond the get() method of the std::ptr.
Sometimes, adding an expression for the PImpl member (e.g. *obj.m_impl.get()) allows the values of the member to be viewed. Sometimes the members still cannot be viewed.
Printing the same expression (e.g. p *obj.m_impl.get()) from the gdb terminal (within Qt Creator) always displays the members of the value.
Sample code:
PImpl.hpp:
#define PIMPL(memberName) \ struct Impl; \ struct ImplDeleter { void operator()(Impl*); }; \ std::unique_ptr<Impl, ImplDeleter memberName; #define PIMPL_DELETER(class) \ void class::ImplDeleter::operator()(class::Impl* toDelete) \ { delete toDelete; }
ClassOne.hpp:
#include "PImpl.hpp" class ClassOne { public: // Public interface private: PIMPL(m_impl); };
ClassOne.cpp:
#include "ClassOne.hpp" struct ClassOne::Impl { // Private interface std::string aMember; static int AStaticMember = 4; }; PIMPL_DELETER(ClassOne);
// Class One Public Interface Implementation}}
*ClassTwo.hpp:* #include "PImpl.hpp" class ClassTwo { public: // Public interface private: PIMPL(m_impl); };
ClassTwo.cpp:
#include "ClassTwo.hpp" #include "ClassOne.hpp" struct ClassTwo::Impl { ClassOne classOneMember; // Other members } PIMPL_DELETER(ClassTwo) // Class Two Public interface implementation.
In this example, when debugging a program which constructs and manipulates a ClassOne object directly it is possible to see the values of ClassOne::m_impl from the Variables pane. When debugging a program which constructs an manipulates a ClassTwo object, the details of *ClassTwo::m_impl->classOneMember.m_impl.get() cannot be viewed in either the Variables or the Expressions pane, but they can be viewed in the GDB terminal.
If desired, I can provide screenshots of the behavior.