Not supported on windows
Supported on linux
Not supported on embedded
Not supported on android

set disable-randomization command

Specifies whether GDB should disable the address space randomization provided by Linux kernel before starting the debugged program.

Syntax

set disable-randomization on
set disable-randomization off
show disable-randomization

Modes

on
In this mode GDB will disable the address space randomization for the debugged process. The addresses of stack variables will not change across different debugging sessions. This is the default mode.
off
In this mode GDB will not try to disable the address space randomization. If the randomization is enabled by the current Linux kernel, the stack pointers for the variables will have different values in different debugging sessions.

Default mode

The default value for the disable-randomization setting is 'on'.

Remarks

The set disable-randomization command is only supported on Linux.

Examples

The following C++ program prints the address of a stack variable:

#include <stdio.h>

int main()
{
    int localVar;
    printf("Address of a stack variable: %08X\n", &localVar);
    return 0;
}

If we run it under GDB with default settings the address will be the same each time:

(gdb) run
Starting program: /home/testuser/randtest
Address of a stack variable: BFFFF6CC
[Inferior 1 (process 8368) exited normally]
(gdb) run
Starting program: /home/testuser/randtest
Address of a stack variable: BFFFF6CC
[Inferior 1 (process 8371) exited normally]
(gdb) run
Starting program: /home/testuser/randtest
Address of a stack variable: BFFFF6CC
[Inferior 1 (process 8372) exited normally]

If we set disable-randomization to off, the addresses will be different each run:

(gdb) set disable-randomization off
(gdb) run
Starting program: /home/testuser/randtest
Address of a stack variable: BF92FB3C
[Inferior 1 (process 8376) exited normally]
(gdb) run
Starting program: /home/testuser/randtest
Address of a stack variable: BFE16CFC
[Inferior 1 (process 8377) exited normally]
(gdb) run
Starting program: /home/testuser/randtest
Address of a stack variable: BF93FE5C
[Inferior 1 (process 8378) exited normally]

Compatibility with VisualGDB

You can disable the address space randomization when debugging Linux applications with VisualGDB by adding a set disable-randomization command to the startup command list in VisualGDB Project Properties.

See also