When running GDB under Linux, I often want to see why a system call failed, but when I try to print errno, I get “Cannot access memory at address 0×8″. This is because errno is a macro for:
# define errno (*__errno_location ())
The solution to the problem is to print what the macro expands to:
(gdb) p errno
Cannot access memory at address 0×8
(gdb) p (*__errno_location ())
$4 = 1