title: gdb print static variable from function
body: <p>We have a C++ program such as:</p>
  <pre><code>int&amp;
  Instance()
  {
      static int test;
      return test;
  }
  
  int
  main( int argc, char ** argv )
  {
      int&amp; test = Instance();
      printf(&quot;%d\n&quot;,test);
      
      return 0;
  }
  </code></pre>
  <p>Now I'm trying to print <code>Instance::test</code>, as suggested by some gdb documentation: <a href="https://ftp.gnu.org/old-gnu/Manuals/gdb/html_node/gdb_52.html" rel="nofollow noreferrer">https://ftp.gnu.org/old-gnu/Manuals/gdb/html_node/gdb_52.html</a></p>
  <p>However, this yields:</p>
  <pre><code>(gdb) p Instance::test
  
  No symbol &quot;test&quot; in specified context.
  </code></pre>
  <p>I'm compiling with <code>-O0 -g</code>.</p>