Re: [情報] gdb/ddd quick reference

看板EE_DSnP作者 (Ric)時間11年前 (2012/11/21 21:42), 編輯推噓3(302)
留言5則, 4人參與, 最新討論串4/4 (看更多)
每年都要 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. -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 59.121.132.127

05/22 08:51,
感謝老師
05/22 08:51
-- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 111.248.111.157

11/21 21:44, , 1F
想開始使用: gdb memTest 就可以啦!!
11/21 21:44, 1F

11/21 21:55, , 2F
推!感謝老師~
11/21 21:55, 2F

11/21 22:27, , 4F
比較親民的版本ㄏㄏ
11/21 22:27, 4F

11/22 00:03, , 5F
推 實用又簡明的教學文
11/22 00:03, 5F
文章代碼(AID): #1GhDe_7q (EE_DSnP)
文章代碼(AID): #1GhDe_7q (EE_DSnP)