7 How do I see the flags?

The C, Z, S and O flags are all stored in the status register eflags (enhanced flags) of the i386 architecture. However, it is not always convenient to extract the corresponding bits from 32-bit register. As s result, it is handy to define a gdb macro to interepret the flag bits for us.

define flags  
  printf "%c%c%c%c%c\n",\  
    ($eflags & 0x001) ? ’C’ : ’ ’,\  
    ($eflags & 0x040) ? ’Z’ : ’ ’,\  
    ($eflags & 0x080) ? ’S’ : ’ ’,\  
    ($eflags & 0x800) ? ’O’ : ’ ’,\  
    ((($eflags & 0x080) == 0x080) != (($eflags & 0x800) == 0x800)) ? ’L’ : ’ ’  
end  
  

While you can copy-and-paste this into gdb every time it is started, it is more convenient to put this definition in a file called .gdbinit in the same directory that you will start gdb. To display the flags, simply use the command flags in gdb.

Iff a flag is set, it is displayed when the command is executed.