title: gcc/g++ not producing debug symbols for variables
body: <p>I have tried both gcc and g++, for each of them using <code>-g</code>, <code>-O0</code>, <code>-Og</code>, and various combinations thereof, even <code>gcc -g -Og -c main.c -O0 -g -g -g -g</code>. I do not get symbols for my variables.</p>
  
  <p>I have made a reduced test program with the following code:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  
  void aFunction() { printf("?\n"); }
  
  int main(int argc, char** argv)
  {
      int intVariable = 0;
      printf("argc = %d, intVariable = %d\n", argc, intVariable);
      return 0;
  }
  </code></pre>
  
  <p>Even with that code, compiled with either gcc or g++, using all manner of -g/-O0/-Og, also trying -c to make sure the linking phase wasn't stripping it out, still, in either the .o or the .out file I can see the functions but not the variables.</p>
  
  <p>I am checking with <code>nm main.o</code> (or <code>nm a.out</code> when omitting the -c). The output includes <code>aFunction</code> and <code>main</code>, but it does not include <code>argc</code> and not <code>intVariable</code>.</p>
  
  <p>I have read over so many questions/answers/posts/articles/etc. trying to figure out why gcc/g++ are not producing debug symbols for my variables, but I cannot fix this. Most sources just mention <code>-g</code>, <code>-O0</code>, <code>-Og</code>, and avoiding <code>-s</code> and compile-optimization.</p>
  
  <p>I need the symbols for debugging in gdb. If I do <code>gdb a.out</code> then <code>break main</code>, let it run and break, then <code>bt</code> to confirm I'm in <code>main</code> and <code>print argc</code> or <code>print intVariable</code> I get the "No symbol "argc" in current context." since the symbols for them aren't present.</p>
  
  <p>When running in gdb, I also get the message "Missing separate debuginfos, use: debuginfo-install glibc-..." I mention it here for completeness, but I don't think that is related since, if I understand correctly, that would only be necessary if I want to debug into lower level glibc-specific code. Correct me if I'm wrong.</p>
  
  <p>This is not the first time I've tried to fix this, and this attempt just wasted a bunch of time again. It would be great if I could use gdb properly.</p>
  
  <p>How do you troubleshoot missing symbols from compiled code?</p>
  
  <p>I'm using gcc 4.9.2. I've tested on a couple of versions of Red Hat on a few different computers. I do not have the ability to change the versions of anything or to install anything here at work, but I can probably try different versions of gcc or operating systems while I'm at home.</p>
  
  <p>Chris Dodds points out that perhaps it is my version of GDB rather than my version or usage or GCC. Doing <code>gdb --version</code> produces output beginning with: <code>GNU gdb (GDB) Red Hat Enterprise Linux (7.2-83.el6)</code>.</p>