The gdb
debugger, by default, turns off address space layout randomisation. This is partially to ensure you're always debugging the same environment. From the gdb
documentation (search for disable-randomization
):
This option is useful for multiple debugging sessions to make the execution better reproducible and memory addresses reusable across debugging sessions.
It's the same reason why I use srand(42)
at the start of my code (only when debugging) rather than srand(time(NULL))
- it provides an absolutely consistent environment from run to run, to make debugging easier.
If you had a very subtle bug that was caused by where your code was located in the address space, it may come and go on different runs within the debugger, unless ASLR was disabled.
You can use:
set disable-randomization off
before starting your program from within gdb
to re-enable ASLR, as per the gdb
documentation.
I suspect you can also use gdb
to attach to an already-running process (which is under the ASLR effect) rather than having gdb
start your program from scratch though I tend to prefer the use of ~/.gdbinit
to force ASLR to be activated.