Home > Mobile >  How does GDB know optimized out local variable values?
How does GDB know optimized out local variable values?

Time:07-03

When I compile the following code with gcc -g -O1 t.c

int main()
{
    int a = 1;
    int b = 2;
    int c = 3;
    int d = 4;

    return 0;
}

GCC optimize out all unused local variables. This can be seen by GDB disassemble command, only instructions for return 0 were left:

(gdb) disassemble main 
Dump of assembler code for function main:
   0x0000000000401106 < 0>: mov    $0x0,           
  • Related