我在x86 Linux机器上有一个死堆进程的全堆核心转储(内核2.6.35-22,如果重要的话),我试图在GDB中调试.
是否有我可以使用的GDB命令,这意味着"向我显示此进程分配的所有内存地址区域的列表?" 换句话说,我可以弄清楚我可以在这个转储中检查的所有可能的有效内存地址是什么吗?
我问的原因是我需要在整个进程堆中搜索某个二进制字符串,并且为了使用该find命令,我需要有一个起始和结束地址.简单地从0x00搜索到0xff ..不起作用,因为find一旦遇到它无法访问的地址就会停止:
(gdb)find/w 0x10000000,0xff000000,0x12345678
警告:无法访问0x105ef883处的目标内存,暂停搜索.
因此,我需要获取内存中所有可读地址区域的列表,以便我可以一次搜索一个.
(我之所以要做这是我需要找到所有内存点结构在某个地址.)
没有show mem,show proc,info mem,info proc似乎做什么,我需要.
Emp*_*ian 79
在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.
Run Code Online (Sandbox Code Playgroud)
你想要的info proc mappings,除非它没有工作/proc(例如在正面调试期间).
试试吧maintenance info sections.
小智 17
如果您有程序和核心文件,则可以执行以下步骤.
1)在程序上运行gdb和核心文件
$gdb ./test core
Run Code Online (Sandbox Code Playgroud)
2)键入信息文件,看看核心文件中有哪些不同的段.
(gdb)info files
Run Code Online (Sandbox Code Playgroud)
示例输出:
(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
Run Code Online (Sandbox Code Playgroud)
在我的情况下,我有15个细分.每个段都有地址的开头和地址的结尾.选择要搜索数据的任何细分.例如,让我们选择load11并搜索模式.Load11的起始地址为0x08049000,结束于0x804a000.
3)在段中搜索模式.
(gdb) find /w 0x08049000 0x0804a000 0x8048034
0x804903c
0x8049040
2 patterns found
Run Code Online (Sandbox Code Playgroud)
如果您没有可执行文件,则需要使用程序打印核心文件的所有段的数据.然后,您可以在地址中搜索特定数据.我没有找到任何程序,您可以使用以下链接中的程序打印核心或可执行文件的所有段的数据.
http://emntech.com/programs/printseg.c
Run Code Online (Sandbox Code Playgroud)
(gdb) maintenance info sections
Exec file:
`/path/to/app.out', file type elf32-littlearm.
0x0000->0x0360 at 0x00008000: .intvecs ALLOC LOAD READONLY DATA HAS_CONTENTS
Run Code Online (Sandbox Code Playgroud)
这是来自 phihag 上面的评论,值得单独回答。这有效,但info proc不适用于来自 gcc-arm-none-eabi Ubuntu 软件包的 arm-none-eabi-gdb v7.4.1.20130913-cvs。
我刚刚看到以下内容:
set mem inaccessible-by-default [on|off]
Run Code Online (Sandbox Code Playgroud)
它可能允许您在不考虑内存是否可访问的情况下进行搜索.