Can gdb false recreate frame's registers?

Viewed 248

I am analyzing core dump of my application and as I go to frame #1, I print value of variable that is stored in EAX. Gdb prints value, which if was true program wouldn't call panic (disassemble shows, that it compares value from register, so no other thread could've changed it). I invoked info reg and apart of instruction pointer gave me the same result for both frame #0 and #1. Is it possible, that Gdb shows value of register EAX for frame #0 when in frame #1?

EDIT: code looks like that:

switch(myVar){
    case -1:
        break;
    default:
        panic();
}

gdb shows:

(gdb) bt
#0 panic()
#1 0x0891a3e9 in myFunc() at myFunc.c:10
(gdb) up
#1 0x0891a3e9 in myFunc() at myFunc.c:10
10    panic();
(gdb) print myVar
$1 = -1
(gdb) print &myVar
Address requested for identifier "myVar" which is in register $eax
1 Answers

Is it possible, that Gdb shows value of register EAX for frame #0 when in frame #1?

Not only possible, but currently is.

GDB does not restore registers when stepping up / down in call stack, except for $EBP and $ESP and $EIP (and sometimes $EBX).

It can be argued that this is confusing (you don't get to see the actual value of non-restored registers when you navigate between frames).

GDB has behaved like that since ~forever, and people who debug at the assembly level know how to "fish" the right values from the stack.

Related