Is the arrangement of these segments always so?
No. For one thing, modern programs use multiple threads, which means there are multiple stacks. For another, modern malloc
implementations use mmap
, so "the heap" is not a single contiguous space, but a collection of disjoint arenas. Shared libraries' .text
and .data
are also sprinkled randomly, and may be between heap arenas.
Are they independent of what computer architecture a computer uses?
No. Certain architectures use stack which grows up (towards higher addresses), though these architectures are currently rare.
To inspect the address of each segment in gdb, could anybody show me how to do it?
GDB doesn't have any special support for examining segments. On Linux, /proc/$pid/maps
will show you current mappings. Once you know the base address of any given segment, you can examine memory at that address using the "normal" GDB x
command.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…