title: How to print a c++ object members using GDB from an address if the object's class type is like A::B
body: <p>From this link
  <a href="https://stackoverflow.com/questions/5381836/gdb-interpret-memory-address-as-an-object">gdb interpret memory address as an object</a>
  we know that, if an object of class type  A is at a specific address such as 0x6cf010, then we can use:</p>
  
  <pre><code>(gdb) p *(A *) 0x6cf010 
  </code></pre>
  
  <p>to print the member elements of this object. </p>
  
  <p>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:</p>
  
  <pre><code>(gdb) p *(A::B *) 0x6cf010
  (gdb) p *((A::B *) 0x6cf010)
  </code></pre>
  
  <p>So, who knows how to print the object elements under this conditions?</p>
  
  <hr>
  
  <p>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).</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  
  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-&gt;print();
  
      int *q = 0;
  
      // Generating a core here
      *q = 0;
      return 0;
  </code></pre>
  
  <p>}</p>