I did some tests:
64bit app: works (-O1 and -O0)
32bit app: works only with -O0
While O1 is "debugger friendly" (I might remove that), it is not "debugger perfect".
O1 runs something called the "peephole optimizer".
And that means, that a value that is already loaded into a cpu register, is not refreshed from memory, between two statements. Yet the debugger only knows the value that is in memory.
This also does not depend on what debugger is used.
The debug info written by fpc (stabs and dwarf) only specify that the value is at location X in memory.
Full asm code would look like
mov 0 => eax
move eax => mem
move mem => eax // peephole removes this line
and 8, eax
test eax for 0
....
Setup for the debugger:
http://wiki.lazarus.freepascal.org/Debugger_Setup