Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

can I find via GDB if a variable belong to heap or stack?

Tags:

c

linux

gdb

My breakpoint points to a variable. (points somewhere. Can I figure out if somewhere belongs to the heap or the stack?)

is there any way to find where is the beginning and the end of the stack? is there any way to find where is the beginning and the end of the heap?

like image 266
cateof Avatar asked Mar 09 '11 14:03

cateof


People also ask

Are variables stored in stack or heap?

Stack and a Heap ? Stack is used for static memory allocation and Heap for dynamic memory allocation, both stored in the computer's RAM . Variables allocated on the stack are stored directly to the memory and access to this memory is very fast, and it's allocation is dealt with when the program is compiled.

Do functions go on the stack or heap?

So, all input arguments and all local variables for a function/class method are placed on the stack.

Is the heap part of the stack?

JVM has divided memory space between two parts one is Stack and another one is Heap space. Stack space is mainly used for storing order of method execution and local variables. Stack always stored blocks in LIFO order whereas heap memory used dynamic allocation for allocating and deallocating memory blocks.

Can the heap run into the stack?

If the heap grows into the stack, the operating system should always be aware of the situation and some sort of system call will fail. The implementation of malloc() almost certainly notices the failure and returns NULL .


1 Answers

Use info proc mappings for /proc info about your memory layout.

like image 69
Erik Avatar answered Sep 19 '22 17:09

Erik