- 论坛徽章:
- 0
|
10可用积分
我的环境是solaris8+gcc2.95.2+gdb6.3
写了下面这个小程序
> cat t.cpp
#include<stdio.h>
template <class T>
void f(T t){
printf("v=%d\n",t);
}
int main(void){
f<int>(2);//显式指定模版实参
f<short>(3);//显式指定模版实参
return 0;
}
编译运行都没有问题
> gcc -g t.cpp && ./a.out
v=2
v=3
但是如果用gdb来单步跟踪./a.out就会出问题,似乎是gdb自己core dump了???????????????????
==============================================
> gdb ./a.out
GNU gdb 6.3
Copyright 2004 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 "sparc-sun-solaris2.8"...
(gdb) b 7
Breakpoint 1 at 0x10618: file t.cpp, line 7.
(gdb) n
The program is not being run.
(gdb) r
Starting program: /users/denver/gonl02/tmp/a.out
Breakpoint 1, main () at t.cpp:7
7 f<int>(2);
(gdb) n
v=2
8 f<short>(3);
(gdb) n
v=3
9 return 0;
(gdb) n
10 }
(gdb) n
0x000104e4 in _start ()
(gdb) n
Single stepping until exit from function _start,
which has no line number information.
Program exited normally.
(gdb) n
The program is not being run.
(gdb) q
==============================================
然后在当前目录下面就有了一个core文件:
> ls
a.out core t.cpp
==============================================
如果我刚才b 7改成b 6,gdb的结果有点区别:
(gdb) b 6
Breakpoint 1 at 0x10614: file t.cpp, line 6.
(gdb) r
Starting program: /users/denver/gonl02/tmp/a.out
Breakpoint 1, main () at t.cpp:6
6 int main(void){
(gdb) n
7 f<int>(2);
(gdb) n
void f<int> (t=0) at t.cpp:3
3 void f(T t){
(gdb) n
4 printf("v=%d\n",t);
(gdb) n
v=2
4 printf("v=%d\n",t);
(gdb) n
main () at t.cpp:8
8 f<short>(3);
(gdb) n
v=3
Segmentation fault (core dumped)
==============================================
我再用gdb去调试这个core文件:
> gdb core
GNU gdb 6.3
......(略去那些no warranty的文字)
(gdb) where
No stack.
没有堆栈?
这是怎么回事呢? 到底是gdb core了还是我的程序core了?
还请dx指点迷津,十分感谢了! |
最佳答案
查看完整内容
会不会是因为你在main处下断点有问题,因为系统是这样调用exit(main())的,JDB断点下在这里,不就是中断了一下么,每个平台对于exit是否为可重入函数的支持不一样的,或许这就是问题的原因LZ你试试最简单的代码,main里只返回个0.。。。。以上内容纯属虚构,如有雷同,实属巧合
|