Boost-Pretty-Printer
Boost-Pretty-Printer copied to clipboard
Cast intrusive_ptr's pointer to its dynamic_type before dereferencing
I use boost::intrusive_ptr with the root of a class hierarchy. It would be useful to see the members of derived types in gdb.
Before:
(gdb) p intrusive_derived
$1 = 0x555555ae2990 = {
value = {
<boost::sp_adl_block::intrusive_ref_counter<test_intrusive_ptr()::S, boost::sp_adl_block::thread_safe_counter>> = {
m_ref_counter = {
value_ = {
<std::__atomic_base<int>> = {
_M_i = 1
}, <No data fields>}
}
},
members of S:
_vptr.S = 0x5555557c12f0 <vtable for test_intrusive_ptr()::T+16>,
i = 6
}
}
After:
(gdb) p intrusive_derived
$1 = 0x555555ae2990 = {
value = {
<S> = {
<boost::sp_adl_block::intrusive_ref_counter<test_intrusive_ptr()::S, boost::sp_adl_block::thread_safe_counter>> = {
m_ref_counter = {
value_ = {
<std::__atomic_base<int>> = {
_M_i = 1
}, <No data fields>}
}
},
members of S:
_vptr.S = 0x5555557c12f0 <vtable for test_intrusive_ptr()::T+16>,
i = 6
},
members of T:
j = 9
}
}