GDB:列出崩溃进程的所有映射内存区域

新手上路,请多包涵

我从 x86 Linux 机器上的死进程(内核 2.6.35-22,如果重要的话)得到了一个全堆核心转储,我正试图在 GDB 中调试它。

有没有我可以使用的 GDB 命令,意思是“显示此进程分配的所有内存地址区域的列表?”换句话说,我能弄清楚我可以在这个转储中检查的所有可能的有效内存地址吗?

我问的原因是我需要在 整个进程堆中 搜索某个二进制字符串,并且为了使用 find 命令,我需要有一个开始和结束地址。简单地从 0x00 搜索到 0xff.. 不起作用,因为 find 一旦遇到无法访问的地址就会停止:

(gdb) 查找 /w 0x10000000, 0xff000000, 0x12345678

警告:无法访问 0x105ef883 处的目标内存,停止搜索。

所以我需要获取内存中所有可读地址区域的列表,这样我就可以一次搜索一个。

(我需要这样做的 原因 是我需要找到内存中 指向 某个地址的所有结构。)

show mem , show proc , info mem , info proc 似乎都不需要。

原文由 Crashworks 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 1.1k
2 个回答

在 GDB 7.2 中:

 (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.

你想要 info proc mappings ,除非它在没有 /proc 时不起作用(例如在事后调试期间)。

尝试 maintenance info sections 代替。

原文由 Employed Russian 发布,翻译遵循 CC BY-SA 3.0 许可协议

如果您有程序和核心文件,您可以执行以下步骤。

1)在程序上运行gdb以及核心文件

 $gdb ./test core

2)输入信息文件并查看核心文件中有哪些不同的段。

     (gdb)info files

示例输出:

     (gdb)info files

    Symbols from "/home/emntech/debugging/test".
    Local core dump file:
`/home/emntech/debugging/core', file type elf32-i386.
  0x0055f000 - 0x0055f000 is load1
  0x0057b000 - 0x0057c000 is load2
  0x0057c000 - 0x0057d000 is load3
  0x00746000 - 0x00747000 is load4
  0x00c86000 - 0x00c86000 is load5
  0x00de0000 - 0x00de0000 is load6
  0x00de1000 - 0x00de3000 is load7
  0x00de3000 - 0x00de4000 is load8
  0x00de4000 - 0x00de7000 is load9
  0x08048000 - 0x08048000 is load10
  0x08049000 - 0x0804a000 is load11
  0x0804a000 - 0x0804b000 is load12
  0xb77b9000 - 0xb77ba000 is load13
  0xb77cc000 - 0xb77ce000 is load14
  0xbf91d000 - 0xbf93f000 is load15

就我而言,我有 15 个段。每个段都有地址的开始和地址的结束。选择要搜索数据的任何细分。例如,让我们选择 load11 并搜索模式。 Load11 的起始地址为 0x08049000,结束于 0x804a000。

  1. 在段中搜索模式。
 (gdb) find /w 0x08049000 0x0804a000 0x8048034
 0x804903c
 0x8049040
 2 patterns found

如果您没有可执行文件,则需要使用打印核心文件所有段数据的程序。然后您可以在某个地址搜索特定数据。我没有找到任何这样的程序,您可以使用以下链接中的程序打印核心或可执行文件的所有段的数据。

  http://emntech.com/programs/printseg.c

原文由 user1203496 发布,翻译遵循 CC BY-SA 3.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题