title: Why GDB jumps unpredictably between lines and prints variables as "<value optimized out>"?
body: <p>Can anyone explain this behavior of gdb?</p>
  
  <pre><code>900         memset(&amp;new_ckpt_info,'\0',sizeof(CKPT_INFO));
  (gdb)
  **903         prev_offset   = cp_node-&gt;offset;**
  (gdb)
  **905         m_CPND_CKPTINFO_READ(ckpt_info,(char *)cb-&gt;shm_addr.ckpt_addr+sizeof(CKPT_** HDR),i_offset);
  (gdb)
  **903         prev_offset   = cp_node-&gt;offset;**
  (gdb)
  **905         m_CPND_CKPTINFO_READ(ckpt_info,(char *)cb-&gt;shm_addr.ckpt_addr+sizeof(CKPT_ HDR),i_offset);**
  (gdb)
  **908         bitmap_offset  = client_hdl/32;**
  (gdb)
  **910         bitmap_value = cpnd_client_bitmap_set(client_hdl%32);**
  (gdb)
  **908         bitmap_offset  = client_hdl/32;**
  (gdb)
  **910         bitmap_value = cpnd_client_bitmap_set(client_hdl%32);**
  (gdb)
  **908         bitmap_offset  = client_hdl/32;**
  (gdb)
  **910         bitmap_value = cpnd_client_bitmap_set(client_hdl%32);**
  (gdb)
  913         found = cpnd_find_exact_ckptinfo(cb , &amp;ckpt_info , bitmap_offset , &amp;offset , &amp;prev_offset);
  (gdb)
  916         if(!found)
  (gdb) p found
  $1 = &lt;value optimized out&gt;
  (gdb) set found=0
  Left operand of assignment is not an lvalue.
  </code></pre>
  
  <p>Why after executing line 903 it again executes the same for 905 908 910?</p>
  
  <p>Another things is <code>found</code> is a <code>bool</code>-type variable, so why it is showing <code>value optimized out</code>?
  I am not able to set the value of <code>found</code> as well.</p>
  
  <p>This seems to be a compiler optimization (in this case its <code>-O2</code>); how can I still set the value of <code>found</code>?</p>