利用coredump定位出错的代码行

在Target机上操作:

1) ulimit -S -c unlimited > /dev/null 2>&1

2) 运行程序./panda_elf,发生异常生成core.13811

将core.13811拷贝到Host机上以便进行分析:
1) mipsel-linux-gdb -c core.13811 panda_elf

sep@debian:~/project$ mipsel-linux-gdb -c core.13811 panda_elf

GNU gdb 6.6.0.20070423-cvs
Copyright (C) 2006 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB. Type "show warranty" for details.
This GDB was configured as "--host=mipsel-linux --target=mipsel-linux-uclibc"...
warning: core file may not match specified executable file.
Error while mapping shared library sections:
/lib/librt.so.0: No such file or directory.
Error while mapping shared library sections:
/lib/libdl.so.0: No such file or directory.
warning: .dynamic section for "/lib/libpthread.so.0" is not at the expected addr ess (wrong library or version mismatch?)
Error while mapping shared library sections:
/lib/libm.so.0: No such file or directory.
Error while mapping shared library sections:
/lib/libc.so.0: No such file or directory.
Error while mapping shared library sections:
/lib/ld-uClibc.so.0: No such file or directory.
Reading symbols from /opt/nfs/work/phase4.0git/apply/BSEAV/bin/libb_os.so...done .
Loaded symbols for ./libb_os.so
Reading symbols from /opt/nfs/work/phase4.0git/images/qte/lib/libQtGui.so.4...do ne.
Loaded symbols for ./lib/libQtGui.so.4
Reading symbols from /opt/nfs/work/phase4.0git/images/qte/lib/libQtNetwork.so.4. ..done.
Loaded symbols for ./lib/libQtNetwork.so.4
Reading symbols from /opt/nfs/work/phase4.0git/images/qte/lib/libQtCore.so.4...d one.
Loaded symbols for ./lib/libQtCore.so.4
Symbol file not found for /lib/librt.so.0
Symbol file not found for /lib/libdl.so.0
Reading symbols from /lib/libpthread.so.0...done.
Loaded symbols for /lib/libpthread.so.0
Reading symbols from /opt/nfs/work/phase4.0git/apply/BSEAV/bin/libstdc++.so.6... done.
Loaded symbols for ./libstdc++.so.6
Symbol file not found for /lib/libm.so.0
Reading symbols from /opt/nfs/work/phase4.0git/apply/BSEAV/bin/libgcc_s.so.1...d one.
Loaded symbols for ./libgcc_s.so.1
Symbol file not found for /lib/libc.so.0
Symbol file not found for /lib/ld-uClibc.so.0
warning: Unable to find dynamic linker breakpoint function.
GDB will be unable to debug shared library initializers
and track explicitly loaded dynamic code.
Core was generated by `panda_elf

 
2) 列出问题所在(gdb) where

(gdb) where
#0 0x0048d558 in IpanelScreen::keyReleaseEvent ()
#1 0x2af3d2ec in QWidget::event () from ./lib/libQtGui.so.4
#2 0x2aef8324 in QApplicationPrivate::notify_helper ()
   from ./lib/libQtGui.so.4
#3 0x2aefb178 in QApplication::notify () from ./lib/libQtGui.so.4
#4 0x2b4f062c in QCoreApplication::notifyInternal () from ./lib/libQtCore.so.4
#5 0x2af43468 in __dso_handle () from ./lib/libQtGui.so.4
warning: GDB can
't find the start of the function at 0x2af43468.
    GDB is unable to find the start of the function at 0x2af43468
and thus can'
t determine the size of that function
's stack frame.
This means that GDB may be unable to access that stack frame, or
the frames below it.
    This problem is most likely caused by an invalid program counter or
stack pointer.
    However, if you think GDB should simply search farther back
from 0x2af43468 for code which looks like the beginning of a
function, you can increase the range of the search using the `set
heuristic-fence-post'
command.
Backtrace stopped: previous frame inner to this frame (corrupt stack?)
(gdb)

注意红色标志部分, IpanelScreen::keyReleaseEvent ()是我们实行的Qt按键处理函数,cormdump的入口就在这里。
地址0x0048d558就是产生问题的入口:
#0  0x0048d558 in IpanelScreen::keyReleaseEvent ()
 
3) mipsel-linux-objdump -d panda_elf > panda_elf.asm
将panda_elf反汇编,用UE打开panda_elf.asm,找出地址48d558(去掉前面的零)所在的行,最后定位是一个全局变量没有加互斥保护。
另外,如果编译时打开debug选项,则可以在gdb中直接查看是哪一行的源代码导致coredump,不用再反汇编那么麻烦。

你可能感兴趣的:(利用coredump定位出错的代码行)