Reputation:
I've got a
std::set<MyIntrusivePtr<T> >
When I print out this container from within gdb I get
(gdb) p m_sSymbol->m_sVariables
$10 = std::set with 1 element = {[0] = {m_p = 0x781a0630}}
(gdb)
m_p is the plain pointer
T* m_p;
contained in
MyIntrusivePtr<T>
How can one dereference this pointer?
Example session:
[user@ hostname /directory]% cat tmp.cpp
#include <set>
struct A
{ int *m_p;
bool operator<(const A &_r) const
{ return m_p < _r.m_p;
}
A(int *p)
:m_p(p)
{
}
};
int main()
{ int a, b, c;
std::set<A> s{A(&a), A(&b), A(&c)};
}
[user@ hostname /directory]% g++ -g tmp.cpp -std=c++17 -fno-inline
[user@ hostname /directory]% ~/bin./gdb a.out
GNU gdb (GDB) 8.0
(gdb) b main
Breakpoint 2 at 0x400a45: file tmp.cpp, line 14.
(gdb) r
Starting program: /directory/a.out
Breakpoint 2, main () at tmp.cpp:14
14 std::set<A> s{A(&a), A(&b), A(&c)};
(gdb) n
15 }
(gdb) p s
$1 = std::set with 3 elements = {[0] = {m_p = 0x7fffffffd484}, [1] = {m_p = 0x7fffffffd488}, [2] = {m_p = 0x7fffffffd48c}}
(gdb) p s[0]
No symbol "operator[]" in current context.
(gdb) p (*s.begin())
Cannot evaluate function -- may be inlined
(gdb)
Upvotes: 2
Views: 31
Reputation: 213754
How can one dereference this pointer?
Unfortunately there is no built-in way.
You could write your own pretty-printer for std::set<A>
(documentation), but often the "stupid" way does it:
(gdb) print *(A*) 0x7fffffffd484
(gdb) print *(A*) 0x7fffffffd488
etc.
Upvotes: 1