title: How does GDB know optimized out local variable values?
body: <p>When I compile the following code with <code>gcc -g -O1 t.c</code></p>
  <pre><code>int main()
  {
      int a = 1;
      int b = 2;
      int c = 3;
      int d = 4;
  
      return 0;
  }
  </code></pre>
  <p>GCC optimize out all unused local variables. This can be seen by GDB <code>disassemble</code> command, only instructions for <code>return 0</code> were left:</p>
  <pre><code>(gdb) disassemble main 
  Dump of assembler code for function main:
     0x0000000000401106 &lt;+0&gt;: mov    $0x0,%eax
     0x000000000040110b &lt;+5&gt;: ret    
  End of assembler dump.
  </code></pre>
  <p>However, GDB somehow knows the values of variables from C code</p>
  <pre><code>(gdb) info locals 
  a = 1
  b = 2
  c = 3
  d = 4
  </code></pre>
  <p>How does GDB know about these values if they are absent in generated assembly code?</p>