我有一个同事机器上的coredump文件。
我们都有相同的程序源和相同的第三方*.so
文件(如libmysqlclient18
和几个内部文件)。
问题是我们都独立编译软件(来自相同的来源),我想用他的核心转储文件来检查我机器上的GDB。
当我尝试加载核心文件和我的可执行文件到gdb时,我得到:
user@ubuntu:/mnt/hgfs/share/dir$ gdb prog core
GNU gdb (Ubuntu/Linaro 7.4-2012.04-0ubuntu2.1) 7.4-2012.04
Copyright (C) 2012 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "i686-linux-gnu".
For bug reporting instructions, please see:
<http://bugs.launchpad.net/gdb-linaro/>...
Reading symbols from /mnt/hgfs/share/dir/prog...done.
warning: exec file is newer than core file.
[New LWP 4465]
[New LWP 4462]
[New LWP 4464]
warning: Can't read pathname for load map: Input/output error.
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/i386-linux-gnu/libthread_db.so.1".
Core was generated by `./prog'.
Program terminated with signal 11, Segmentation fault.
#0 0x002d3706 in ?? () from /lib/i386-linux-gnu/libc.so.6
(gdb) bt full
#0 0x002d3706 in ?? () from /lib/i386-linux-gnu/libc.so.6
No symbol table info available.
#1 0x00000000 in ?? ()
No symbol table info available.
(gdb)
这个场景有可能工作吗?(当然,我在编译软件时启用了调试符号)如果没有,我遗漏了哪些技术细节?
我知道如果他或我对源代码进行修改是不可能的,因为那时可执行文件会不同,但事实并非如此,第三方*.so
文件和源代码,它们都是匹配的。
更新:作为用户mkfs在评论中建议安装libc6-dbg
后,我在gdb中得到这个:
user@ubuntu:/mnt/hgfs/share/dir$ gdb prog core
GNU gdb (Ubuntu/Linaro 7.4-2012.04-0ubuntu2.1) 7.4-2012.04
Copyright (C) 2012 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "i686-linux-gnu".
For bug reporting instructions, please see:
<http://bugs.launchpad.net/gdb-linaro/>...
Reading symbols from /mnt/hgfs/share/dir/prog...done.
warning: exec file is newer than core file.
[New LWP 4465]
[New LWP 4462]
[New LWP 4464]
warning: Can't read pathname for load map: Input/output error.
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/i386-linux-gnu/libthread_db.so.1".
Core was generated by `./prog'.
Program terminated with signal 11, Segmentation fault.
#0 0x002d3706 in _IO_helper_overflow (s=0x0, c=0) at vfprintf.c:2188
2188 vfprintf.c: No such file or directory.
(gdb) bt
#0 0x002d3706 in _IO_helper_overflow (s=0x0, c=0) at vfprintf.c:2188
#1 0x00000000 in ?? ()
(gdb) bt full
#0 0x002d3706 in _IO_helper_overflow (s=0x0, c=0) at vfprintf.c:2188
written = 47
target = <optimized out>
used = -1226838776
#1 0x00000000 in ?? ()
No symbol table info available.
(gdb)
这个场景有可能工作吗?
可以,但是你需要确保你在两台机器上构建的二进制文件的符号布局是相同的(或者至少足够接近)。这并不一定是微不足道的:像本地用户名、源代码或安装目录的路径名和主机名这样的东西有时会泄漏到构建的目标文件中,并可能导致符号不匹配。
要检查二进制文件是否接近,运行diff <(nm a.out) <(nm b.out)
——应该只有很少的差异。如果你看到很多差异,说明你的二进制文件不够接近。
这可能是您的第一个错误:如果您的同事使用我编译软件时启用了调试符号,当然
-O2
构建,而您使用-g
(并暗示使用-O0
)构建,则二进制文件保证不匹配。
你需要使用来构建你的同事使用的标志(但是你可以添加调试符号;例如,如果你的同事使用-O2
构建,你应该使用-O2 -g
(em>一起构建)。
注:注意,还需要两台机器上相同版本的系统库。