title: Print in program works but gdb says "Cannot access memory at address ..."
body: <p>I have the following code:</p>
  
  <pre><code>struct A
  {
    int fieldA;
    int fieldB;
  };
  
  A *a = (A *) ptr;
  
  cout &lt;&lt; a-&gt;fieldA; // Works fine
  cout &lt;&lt; a-&gt;fieldB; // Works fine
  </code></pre>
  
  <p><code>ptr</code> is a <code>char *</code> object that points to somewhere in memory.  The object that is stored in memory at address <code>ptr</code> is an <code>A</code> object.  The structure is written by another process in memory that is shared between the processes.  In the process where I have the above code, the shared memory is read only.</p>
  
  <p>The program being executed in on a remote target.  I run the program on the target using gdb-server, and I connect to the server from my development machine using gdb.</p>
  
  <p>The print statements correctly prints the expected value.  However, when I print the fields of the structure from gdb by doing <code>p a-&gt;fieldA</code>, I get "Cannot access memory at address ...".  This doesn't make sense because I would expect that since my program can access the contents of the structure, so should gdb.</p>
  
  <p>Why is this happening?</p>