六月 7, 2012

linux/cygwin下使用gdb三板斧

Written by

第一步,先用gdb装载exe程序的调试符

(我用的是cygwin,所以使用’/cygdrive/盘符’来跳转到I盘下的xxx/111目录下)

HYH@HYH-PC ~
$ cd /                                                                        <========到根目录

HYH@HYH-PC /
$ cd /cygdrive/i/SingleValueTrans/111                      <========到exe所在目录

HYH@HYH-PC /cygdrive/i/SingleValueTrans/111
$ gdb valuetrans.exe                                                <========用gdb装载exe程序的调试符
GNU gdb (GDB) 7.3.50.20111026-cvs (cygwin-special)
Copyright (C) 2011 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type “show copying”
and “show warranty” for details.
This GDB was configured as “i686-cygwin”.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>…
Reading symbols from /cygdrive/i/SingleValueTrans/111/valuetrans.exe…done.
(gdb)

 

第二步,用gdb运行程序
(gdb)
(gdb) r                          <========用gdb装载exe程序
Starting program: /cygdrive/i/SingleValueTrans/111/valuetrans.exe
[New Thread 22604.0x5de0]
[New Thread 22604.0x5e8c]
2012-06-07 18:17:04 Single value translation service is starting …

……

……

 

第三步,gdb已经自动在出问题的代码出停止并推出exe程序

2012-06-07 18:17:46 socket service listening at port ‘502’

Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 22604.0×6030]
0x004e703d in sockServer::tListen (param=0x20074160) at ..\sockServer.cpp:193

轻松看到看到程序在 sockServer.cpp:193行出问题了

 

 

还有些招数,比如生成core文件,利用core文件调试等,很好很强大,但是上面三板斧已经能直接定位到问题所在了,杀鸡焉用牛刀呢

 

 

Category : C/C++Linux/Unix

Tags :

发表评论

电子邮件地址不会被公开。

Proudly powered by WordPress and Sweet Tech Theme