I am new to linux. I want to know the starting address and its size of different segments (like stack, heap, data etc.) and its current usage.
I like to know how to find both in running process and in core dump.
Thanks in advance.
I am new to linux. I want to know the starting address and its size of different segments (like stack, heap, data etc.) and its current usage.
I like to know how to find both in running process and in core dump.
Thanks in advance.
start by looking into the proc(5)
filesystem. man
is your friend.
/proc/[number]/maps
A file containing the currently mapped memory regions and their access permissions
in gdb, you can use
$ gdb -q
(gdb) help info proc
Show /proc process information about any running process.
Specify any process id, or use the program being debugged by default.
Specify any of the following keywords for detailed info:
mappings -- list of mapped memory regions.
stat -- list a bunch of random process info.
status -- list a different bunch of random process info.
all -- list all available /proc info.
have a look at info proc mappings
, except it doesn't work when there is no /proc (such as during pos-mortem debugging).
There is the pmap command. It displays the information available in /proc/PID/maps
in different ways. Plus, it adds header and summary lines. This may be more readable to you than the /proc/PID/maps
pseudo file.
Sadly, it does not have the ability to analyze core dumps.
objdump on Linux gives information about a binary. Check man objdump. It gives - sections, disassembly, debugging symbols.
objdump -h <binary>
objdump --section=name
Better way, if possible(if you can build the executable yourself from source) generate a map file while compiling and linking the source code, by giving appropriate compiler/linker option. The map file will sure have all the information about sizes, starting addresses of different sections.
Use `maintenance info sections' within gdb to print all the segments that are mapped into the process address space.