星期四 十一月 09, 2006
core dump的实例分析
有个客户遇到这样一个core dump.具体的测试用例和core为:
#include <stdlib.h>
#include <stdio.h>
int main(int argc,char *argv[])
{
int i = 0;
try
{
printf("aabbccn");
throw;
}
catch(...)
{
printf("catch.....n");
}
运行结果:
aabbcc
Abort
Core dump info:
(dbx) where -h
=>[1] _libc_kill(0x0, 0x6, 0xffbff4e8, 0x7f9d5434, 0x1, 0xffbff534),
at 0x7f9204f8
[2] abort(0x7f9eaea4, 0x5, 0x2124c, 0x15360, 0x1, 0x7f9eaea4), at
0x7f8b6d10
[3] __Cimpl::default_terminate(0x7f9eaea4, 0x4, 0x10910, 0x15360,
0x5, 0x7f9d5048), at 0x7f9d504c
[4] __Cimpl::ex_terminate(0x7f9eaea8, 0x0, 0x7f940294, 0x0, 0x0,
0x1), at 0x7f9d4e64
[5] __Crun::ex_rethrow(0x7, 0x7f9eaf74, 0x15688, 0x0, 0x13984,
0x21364), at 0x7f9d5a8c
[6] main(0x1, 0xffbff704, 0xffbff70c, 0x21000, 0x0, 0x0), at 0x10ef0
这个例子中的错误是在于throw抛出的是Null,而C++标准中对于抛出一个Null异常时,从而引起新的异常rethrow,在缺省状况下,会直接调用terminate(),而terminate最终会调用abort(),使得程序得到一个Abort信号从而退出,导致最终运行失败。具体的C++标准见C++ standard 15.1章节.关于异常处理,还可以参考 http://docs.sun.com/app/docs/doc/805-4955/6j4mg8071?a=view
对于这个例子,只需要把异常处理中的throw抛出相应的处理类就可以了,可以修改为:
#include <stdlib.h>
#include <stdio.h>
int main(int argc,char *argv[])
{
int i = 0;
try
{
printf("aabbccn");
throw "aa";
}
catch(int a)
{
printf("catch.....%dn", a);
}
catch(...)
{
printf("catch.....n");
}
}
这样程序就不会core dump了。
Posted at 04:40下午 十一月 09, 2006 by Wenlong Zhang in Solaris | Comments[1]
求助!我的程序是在Solaris8上用
forte 6 update2编译连接的。
在Solaris10运行Coredump后。
用pstack分析,发现我们自己的函数名都显示为问号????,但调用者ACE和被调用者ASN相关的函数名(使用的公共开源的动态或静态库)都是正常的。不知道为什么,请指教。
# pstack core.2580 | more
core 'core.2580' of 2580: java_vm
----------------- lwp# 1 / thread# 1 --------------------
fef40a27 read (b, 804280c, 1)
feb11ba8 __1cDhpiEread6FipvI_I_ (b, 804280c, 1) + a8
feb11aef _jcRead (b, 804280c, 1) + 2f
fe77045e [b]????????[/b] (80685b8, 8042864, 22)
...
feb1d55c jni_CallStaticVoidMethod (80685b8, 8069020, 80e8355,
0) + 14c
080516c2 main (2, 8047168, 8047174) + 50c
08050daa ???????? (2, 80472cc, 80472d4, 0, 80472d5, 8047301)
----------------- lwp# 2 / thread# 2 --------------------[/i]
Posted by Jammy on 十一月 10, 2007 at 11:50 上午 GMT+08:00 #