作者gwliao (gwliao)
看板NTUGIEE_EDA
标题Re: Debug
时间Mon Nov 7 02:02:56 2005
※ 引述《tellux (寒川凝步)》之铭言:
: 我现在弄的程式
: 跑一跑会出现问题
: 用gdb查
: 结果是
: Program received signal SIGSEGV, Segmentation fault.
: CPaqpRegion::partition (this=0x8534390, isH=false, reg1=@0x8554fb8, reg2=@0x85
: 55004)
: at stl_vector.h:462
: 462 stl_vector.h: No such file or directory.
: in stl_vector.h
: 在eda4 (gcc3.4.1)上make,在eda6上面run...
: 有没有人知道这是怎麽回事呢
本来想回.......那就debug吧 :D
但是看样子你应该不大会用gdb!
我用gdb的几大步骤
(1) load coredump file
(2) "bt"
(3) "f OOXX", OOXX是由bt看到的数字
(4) "l"
(5) "p A.B A->B....."
bt--backtrack,看看calling stack的样子, main() call func1(), 再func1又call func2()....
那bt会看到 [0]main, [1]func1, [2]func2......
以你的例子来说, 最後一个应该会在stl当中.
f --frame,切换gdb所"看"到的环境, 切到calling的那一瞬间的环境,
这样可以在整个calling stack当中钻来钻去 XD
l --list, 当然後列出source code, 是出事的那行的前後几行.
当然可以指定某档的某行(EX:列出main.c的23行,main.c:23)
不知道出事的行号? bt一下就又看到了.
p--print, 印出这个frame环境可以看到的变数的值!
其他指令的话,可以喊救命......"help"
但是help只会列出大概的类型, 如下
(gdb) help
List of classes of commands:
aliases -- Aliases of other commands
breakpoints -- Making program stop at certain points
data -- Examining data
files -- Specifying and examining files
[...砍砍砍砍砍砍砍砍砍砍砍砍砍砍砍砍砍砍砍砍砍砍砍砍砍砍...]
Type "help" followed by a class name for a list of commands in that class.
Type "help" followed by command name for full documentation.
Command name abbreviations are allowed if unambiguous.
你想知道breakpoints的东西时, 就喊help breakpoints!
(gdb) help breakpoints
Making program stop at certain points.
List of commands:
awatch -- Set a watchpoint for an expression
break -- Set breakpoint at specified line or function
catch -- Set catchpoints to catch events
clear -- Clear breakpoint at specified line or function
commands -- Set commands to be executed when a breakpoint is hit
[...砍砍砍砍砍砍砍砍砍砍砍砍砍砍砍砍砍砍砍砍砍砍砍砍砍砍...]
Type "help" followed by command name for full documentation.
Command name abbreviations are allowed if unambiguous.
对breakpoints中的clear有疑问, 就喊clear
(gdb) help clear
Clear breakpoint at specified line or function.
Argument may be line number, function name, or "*" and an address.
If line number is specified, all breakpoints in that line are cleared.
If function is specified, breakpoints at beginning of function are cleared.
If an address is specified, breakpoints at that address are cleared.
With no argument, clears all breakpoints in the line that the selected frame
is executing in.
See also the "delete" command which clears breakpo
觉得我的"快快乐乐学不会gdb"无聊的话, 想离开就按q........
(gdb) q
--
gdb的使用方法,
1) 东东有买一本gdb的书给Lab.
2) 我的桌上(书架)有一本很多年前的中文书, 当中一个chapter是gdb.
要借书,没问题. 只要让我知道书流落何方.
因为这本书也是我某不知名的学长的"赠"书.....Orz
3) 网路上的电子书:
http://www.gnu.org/software/gdb/documentation/
4) 不错的资料
http://www.study-area.org/cyril/opentools/opentools/book1.html
这份讲了一些UNIX上programming常用的工具的基本用法
5) ......给各位补充吧 XD
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 140.112.230.125
忘了补充, 有一种情况是我用gdb也查不来(应该是我功力太差 Orz )
就是stack overflow!
calling stack太小, 在程式的执行过程中, 被灌爆了 XD
gdb会看到啥风景? 我忘了 Orz 只记得一切正常的样子,没问题的样子,
但那程式又coredump :O 当时"彰化"都念的几百遍 :P 还是找不到,
我是在running time, 下breakpoint, 看很久......zzzZZZZzzzz........
到"bt"可以看到1XXX个frames时, 才猜出这是stack overflow的问题!
1F:推 bhlin:不晓得有没有装ddd? 不熟gdb的可以用ddd比较方便 11/07 19:51
3F:推 gwliao:我不会用DDD, 所以只能讲gdb的东西! 11/07 22:43
4F:推 gwliao:用gdb去debug几次, 就会发现....gdb简单的很! XD 11/07 22:46
※ 编辑: gwliao 来自: 140.112.230.125 (11/07 23:32)