Re: [情报] gdb/ddd quick reference

楼主: ric2k1 (Ric)   2012-11-21 21:42:20
每年都要 repost 一下,希望同学们都能花一些时间学一下 debugger,
不要再用 cout 硬撑了啦!!
※ 引述《ric2k1 (Ric)》之铭言:
有鉴于许多同学遇到程式的 bug 但确不一定清楚如何使用 debugger,
这里写一个 quick reference 希望同学们可以多多使用 debugger.
**************************
* gdb/ddd survival guide *
**************************
[Commonly used commands]
========================
r [options]: run the program with [options]
n: execute the next line of the program
s: step into the function under current line
b [funcName | lineNo]: set break point on <funcName> or <lineNo>, break on
current line if no parameter is specified.
e.g.
b BSTree::insert
b adtTest.h:106
del <breakPointId>: delete the break point by ID
c: continue the execution to the next break or watch point
p <var>: print the content of the variable
p* <var>: print the content of the memory pointed by the varaible
display <var>: display the content of the variable
display* <var>: display the content of the memory pointed by the varaible
undisplay <displayId>: undisplay by ID
up: move up one level of source code (for viewing; won't affect the execution)
down: move down one level of source code (for viewing)
where: show the calling trace to the current line
dir <dirName>: add <dirName> for the look-up of the source code
<Ctrl-c>: force to break the execution
q: quit the debugger
[Less common commands]
======================
call <funcName>: call the function
set <varName> = <value>: force to set the variable value
watch <expression>: set the watch point (used with 'continue')
e.g. watch (idx = 10) // note: not "=="
tbreak [funcName | lineNo]: set the temporary break point. Voided after the
first encounter.
b if <expression>: conditional break point
[Note]
======
You can add a number to most of the commands to specify the "repeating times".
For example, "n 10" will execute the next 10 lines of codes. "c 100" means
you will ignore the next 99 break points and stop at the 100th one.
楼主: ric2k1 (Ric)   2011-01-21 21:44:00
想开始使用: gdb memTest 就可以啦!!
作者: boiq (olo)   2011-01-21 21:55:00
推!感谢老师~
作者: andy13579372 (痘糖)   2011-01-21 22:26:00
作者: yan12125 (姥姥)   2011-01-22 00:03:00
推 实用又简明的教学文
作者: waytin (waytin)   2012-05-22 08:51:00
感谢老师

Links booklink

Contact Us: admin [ a t ] ucptt.com