不显示删除回复显示所有回复显示星级回复显示得分回复 gdb调试无法定位段错误 求救

翔云123456 2012-08-14 09:58:21



写了一段程序,总是出现段错误,于是gdb调试,结果无法找到段错误的位置。

gdb调试结果如下

[root@localhost udp_server4.9.3]# gcc -g -rdynamic -o server udp_server4.9.3.c
[root@localhost udp_server4.9.3]# gdb ./server
GNU gdb Red Hat Linux (6.5-15.fc6rh)
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 "i386-redhat-linux-gnu"...Using host libthread_db library "/lib/libthread_db.so.1".

(gdb) r
Starting program: /home/zyy/udp_socket/udp_server4.9.3/server


Program received signal SIGSEGV, Segmentation fault.
0x39313030 in ?? ()
(gdb) bt
#0 0x39313030 in ?? ()
#1 0x3839392e in ?? ()
#2 0x302c562c in ?? ()
#3 0x2e303030 in ?? ()
#4 0x30303030 in ?? ()
#5 0x302c4e2c in ?? ()
#6 0x30303030 in ?? ()
#7 0x3030302e in ?? ()
#8 0x2c452c30 in ?? ()
#9 0x30332c2c in ?? ()
#10 0x32323130 in ?? ()
#11 0x312a2c2c in ?? ()
#12 0x240a0d36 in ?? ()
#13 0x54565047 in ?? ()
#14 0x542c2c47 in ?? ()
#15 0x2c4d2c2c in ?? ()
#16 0x2c2c4e2c in ?? ()
#17 0x45342a4b in ?? ()
#18 0x47240a0d in ?? ()
#19 0x41474750 in ?? ()
#20 0x3030302c in ?? ()
#21 0x2e303230 in ?? ()
#22 0x2c383939 in ?? ()
---Type <return> to continue, or q <return> to quit---

关键位置全是问号,情何以堪?这可怎么看啊



代码有点长,先不帖了。

各位大侠指点
...全文
116 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
翔云123456 2012-08-20
  • 打赏
  • 举报
回复
段错误定位到了,下一步就分析错误是如何造成的

结贴
翔云123456 2012-08-16
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 的回复:]
貌似现场已经被破坏了,要么单步,要么查下内存操作的代码。
[/Quote]


我现在的调试定位到了错误错误,但是出现错误的地方是简单的语句,不涉及内存操作,我怀疑是其他地方的内存操作问题

这样的话,如何调试呢
louyong0571 2012-08-16
  • 打赏
  • 举报
回复
貌似现场已经被破坏了,要么单步,要么查下内存操作的代码。
翔云123456 2012-08-16
  • 打赏
  • 举报
回复
通过设置断点,进行调试
最后确定段错误出现在data_deal()

调试过程和结果如下

(gdb)
data_deal (serfd=7, msg=0xbfd494a0 "") at udp_server4.9.3.c:251 正常

(gdb)
263 bzero(buf,sizeof(buf));
(gdb)
265 if (!read_datas(serfd,buf))
(gdb)
read_datas (fd=7, rcv_buf=0xbfd48c08 "") at udp_server4.9.3.c:191

(gdb) c
Continuing.


Program received signal SIGSEGV, Segmentation fault.
0x08049479 in data_deal (serfd=743320624,
msg=0x30303030 <Address 0x30303030 out of bounds>) at udp_server4.9.3.c:273
273 nread=strlen(buf);
(gdb)

从read_datas()返回data_deal()后,data_deal()参数就出问题了

这是什么问题,堆栈溢出?
帅得不敢出门 2012-08-15
  • 打赏
  • 举报
回复
先b到某一处,再next试试。

23,120

社区成员

发帖
与我相关
我的任务
社区描述
Linux/Unix社区 应用程序开发区
社区管理员
  • 应用程序开发区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧