在 gdb 中显示段地址

Show segment addresses in gdb

这个youtube video展示了一个程序的虚拟内存布局,包括以下从内存高地址到内存低地址的段。

这些片段的排列总是这样吗?它们与计算机使用的计算机体系结构无关吗?

要检查 gdb 中每个段的地址,谁能告诉我怎么做?
以下面的C程序为例:

#include <stdio.h>

int main() {
    printf("Hello World!\n");
}

Is the arrangement of these segments always so?

没有。一方面,现代程序使用多线程,这意味着有多个堆栈。另一方面,现代 malloc 实现使用 mmap,因此“堆”不是单个连续的 space,而是不相交的竞技场的集合。共享库的.text.data也是随机分布的,可能在heap arenas之间。

Are they independent of what computer architecture a computer uses?

没有。某些架构使用向上(向更高地址)增长的堆栈,尽管这些架构目前很少见。

To inspect the address of each segment in gdb, could anybody show me how to do it?

GDB 对检查段没有任何特殊支持。在 Linux 上,/proc/$pid/maps 将显示当前映射。一旦知道任何给定段的基地址,就可以使用“普通”GDB x 命令检查该地址处的内存。