Boost-Pretty-Printer icon indicating copy to clipboard operation
Boost-Pretty-Printer copied to clipboard

Cast intrusive_ptr's pointer to its dynamic_type before dereferencing

Open pepsiman opened this issue 4 years ago • 0 comments

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
  }
}

pepsiman avatar Jun 10 '20 18:06 pepsiman