c - Why does the address of a local variable vary when executing multiple times, but not when debugging it with GDB? -


why when running code gdb, same addresses variables declared, while executing binary don't same addresses.

#include<stdio.h> void main() {     int *x,q;     //i saw address of variable q in program through gdb during __1st__ execution.     //i re-compiled program make x point address.     x=0x7fffffffe2bc;      *x=3;     printf("%d",(*x)); } 

i ran program through gdb , never segfaulted.

$ gdb -q ./a.out   reading symbols /home/eknath/needed2/a.out...done.   (gdb) r   starting program: /home/eknath/needed2/a.out    3 program exited normally.   (gdb) q   $ 

but normal execution of program produces segfault.

$ ./a.out    segmentation fault 

i don't know if question duplicate of is address gdb debug program?

note: have not switched off aslr

the reason same address local variables while running under gdb gdb (in order simplify debugging scenarios) disables address space randomization.

you can ask gdb not set disable-address-randomization off.

for curious, disabling of address randomization current process not require privilege, , done calling personality(2). here patch added feature.


Comments

Popular posts from this blog

objective c - Change font of selected text in UITextView -

php - Accessing POST data in Facebook cavas app -

c# - Getting control value when switching a view as part of a multiview -