本版版主招募中

 
标题: [疑问] 请教大侠:Segmentation fault 的可能原因
spring627
LU新生
Rank: 1



UID 90672
精华 0
积分 1
帖子 1
活跃指数 1
LU金币 2 个
LU金条 0 个
阅读权限 10
注册 2007-6-1
 
发表于 2007-6-1 16:22  资料  个人空间  短消息  加为好友 
请教大侠:Segmentation fault 的可能原因

各位大侠,我是刚接触 linux 的,不得不在这个系统下调试 fortran 程序。由于时间很紧,强度很大,所以在网上搜了很多天也没有很大进展,现不得不求助各位大侠,告诉我下一步要怎么做,或者看些哪方面的书才能继续下去。
是这样的,老师给了我一个fortran源程序,之前在 UNIX 下编译并成功运行过,现在我用的是 linux ,已经编译成功,但是运行就出错,先给出我的编译文件:

代码:
[hujinhe@console ~]$ cat com
mpif77 -g mdrdipord.f -c
mpif77 -g libmd.f -c
mpif77 -g dceign.f -c
mpif77 -g mdrdipord.o libmd.o dceign.o -o mdord.exe
[hujinhe@console ~]$

运行结果如下:

代码:
[hujinhe@console ~]$ ./mdord.exe <in.dip> out.out
forrtl: severe (174): SIGSEGV, segmentation fault occurred
Image              PC                Routine            Line        Source            
mdord.exe          000000000041E998  Unknown               Unknown  Unknown
mdord.exe          0000000000405C6A  Unknown               Unknown  Unknown
mdord.exe          0000000000403074  Unknown               Unknown  Unknown
mdord.exe          000000000040302A  Unknown               Unknown  Unknown
libc.so.6          000000378851C4BB  Unknown               Unknown  Unknown
mdord.exe          0000000000402F6A  Unknown               Unknown  Unknown
[hujinhe@console ~]$

所以我就学习用gdb调试,出现下面的情况:

代码:
[hujinhe@console ~]$ gdb ./mdord.exe
GNU gdb Red Hat Linux (6.3.0.0-1.96rh)
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 "x86_64-redhat-linux-gnu"...Using host libthread_db library "/lib64/tls/libthread_db.so.1".

(gdb) run <in.dip> out.out
Starting program: /export/home/hujinhe/mdord.exe <in.dip> out.out
[Thread debugging using libthread_db enabled]
[New Thread 182894224864 (LWP 13692)]

Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 182894224864 (LWP 13692)]
0x000000000041e998 in rand_ ()
(gdb) backtrace
#0  0x000000000041e998 in rand_ ()
#1  0x0000000000405c6a in start () at mdrdipord.f:559
#2  0x0000000000403074 in main$mdrdipord_$BLK () at mdrdipord.f:36
#3  0x000000000040302a in main ()
(gdb)

为了学会调试程序,我把论坛上介绍的有关帖子都看了,发现文章很好,就是例子很少,我大概的命令都知道,就是不会实际应用,所以遇到上面的问题我就不知道怎么办了,大概知道是段错误,但怎么看具体错误出在哪?接下来我要怎么做?

顶部
大漠孤星
管理员
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20


LU爱心使者  
UID 257
精华 24
积分 3097
帖子 4279
活跃指数 570
LU金币 2934 个
LU金条 422 个
阅读权限 255
注册 2003-9-30

用支付宝求购
 
发表于 2007-6-5 18:28  资料  个人空间  短消息  加为好友  添加 大漠孤星 为MSN好友 通过MSN和 大漠孤星 交谈 QQ
coredump大多数情况下都是数据越界引起的段错误,俗称溢出。

gdb纵然是比较好的调试办法,但在UNIX上显然不是很直观,不像在OS 400那么直观。

如果你是初学者,建议你采取日志调试法。





顶部
 



当前时区 GMT+8, 现在时间是 2008-10-13 09:36
乐悠LoveUnix论坛-京ICP备05005823号

Thanks to Discuz!  © 2001-2007    Power by LoveUnix.net
Processed in 0.058883 second(s), 6 queries , Gzip enabled

清除 Cookies - 联系我们 - 乐悠LoveUnix - Archiver