From this link gdb interpret memory address as an object we know that, if an object of class type A is at a specific address such as 0x6cf010, then we can use:
(gdb) p *(A *) 0x6cf010
to print the member elements of this object.
However, this seems doesn't work when c++ namespace is involved. That is, if the object of class type A::B, then all the following trying doesn't work:
(gdb) p *(A::B *) 0x6cf010
(gdb) p *((A::B *) 0x6cf010)
So, who knows how to print the object elements under this conditions?
We can use the following deliberate core code to try to print the members of p from the address (we can use "info locals" to show the address).
#include <stdio.h>
namespace A
{
class B
{
public:
B(int a) : m_a(a) {}
void print()
{
printf("m_a is %d\n", m_a);
}
private:
int m_a;
};
}
int main()
{
A::B *p = new A::B(100);
p->print();
int *q = 0;
// Generating a core here
*q = 0;
return 0;
}