ASLR doesn’t work?


I have following code:

#include <stdio.h> #include <stdlib.h>  int main() {         int *ptr1 = malloc(16);         int val1 = 0x12345678;         printf("stack: %p\nheap: %p\n", &val1, ptr1);         return 0; } 

Compilation: gcc -fpie -pie main.c

I wanted to test how aslr behaves under debugger, so i started gdb session, broke at main and ran the program. At main I show memory layout using ‘info proc mappings’: enter image description here

And those values should be randomized as far as i know due to aslr. But every time I re-run the program those values remains the same. I’m using Centos 8, x86_64. I also disabled built-in kernel ASLR by ‘echo 0 > /proc/sys/kernel/randomize_va_space’, but I don’t think it matters.

I also checked if ALSR is enabled using checksec: enter image description here

Is it normal behavior or am I missing something?

EDIT: I saw that when I run binary without gdb everything works totally fine. What can I do to make it work under debugger?