我的环境是solaris8+gcc2.95.2+gdb6.3
写了下面这个小程序
> cat t.cpp
#include
template
void f(T t){
printf("v=%d\n",t);
}
int main(void){
f(2);//显式指定模版实参
f(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(2);
(gdb) n
v=2
8 f(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(2);
(gdb) n
void f (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(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指点迷津,十分感谢了!
顶一下吧!
(gdb) n
main () at t.cpp:8
8 f(3);
(gdb) n
v=3
Segmentation fault (core dumped)
core分明是第二次gdb的这里产生的,你一定要说是第一次产生的。
我再用gdb去调试这个core文件:
> gdb core
GNU gdb 6.3
......(略去那些no warranty的文字)
(gdb) where
No stack.
你为什么要省略这里的文字。。
gdb貌似不是这么用的
最后
gcc直接编译cpp,你的gcc是不是特别配置过?
第二次gdb的时候core了,你看能否重现?
QUOTE:原帖由 r2r4 于 2009-2-19 21:17 发表
(gdb) n
main () at t.cpp:8
8 f(3);
(gdb) n
v=3
Segmentation fault (core dumped)
core分明是第二次gdb的这里产生的,你一定要说是第一次产生的。
我再用gdb去调试这个core文件:
> gdb ...
第二次gdb产生core,是每次都能重现的。
谢谢!
阅读(2430) | 评论(0) | 转发(0) |