Compilation flags in gcc to debug static variables in gdb (in AIX OS)
<p>I need in a debug session, see and manipulate some global variables of a C program. I already tried some options of gcc, but no success until now to see (print) at least my global variables.</p>

<p>GDB always say: No symbol "???" in current context.</p>

<p>What flags shall I use in compilation with gcc to do that ?</p>

<p><strong>MY SAMPLE:</strong></p>

<pre><code>#include &lt;stdio.h&gt;

/* Some vars to see in debug */
static long gvar = 0L;
int othervar=3;
char* onepointer=NULL;

int main() {
    long lvar=gvar;

    gvar = 1L;
    lvar = gvar;
    printf("gvar = %ld\n", gvar);

    gvar = 5L;
    lvar = gvar;
    printf("gvar = %ld\n", gvar);
}
</code></pre>

<p><strong>GDB TUI SESSION:</strong></p>

<p><a href="https://i.stack.imgur.com/GP2k1.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/GP2k1.png" alt="enter image description here"></a></p>

<p><strong>THE ENVIRONMENT:</strong></p>

<ul>
<li>OS: AIX 7 </li>
<li>GCC: 4.8.3 </li>
<li>GDB: 7.8.1</li>
</ul>

<p><strong>TRIED GCC FLAGS (in some combinations):</strong></p>

<p>-g, -g3, -ggdb, -ggdb3 -O0, and others </p>