看板Programming
標 題Re: [問題] gdb on C
發信站政大狂狷年少 (Fri Aug 25 20:03:39 2006)
轉信站ptt!ctu-reader!Spring!news.nctu!news.ntu!news.ee.ttu!netnews.csie.nctu
※ 引述《[email protected] (真人)》之銘言:
> 最近用 gdb 來 debug C 發生一些問題, 就是它會亂跑
> case 1: 用 watch 來看一個 variable, 卻發現他停在一個 if statement.
> ( if ( a ) { ... } )
> 它確實回應 old value: 0, new value: 15
> case 2: 先 break 在某處, 再用step 進入function,
> 再依次 next, 照說應該逐行執行, 例如 line 12, line 13 ...
> 結果 current line 一直亂跳, line 13, line 12, line 14
> line 13 是一個 printf(), 過了也沒print出來,
> 到了line 15時又乎然跳出printf() 的結果,
> 到底是怎樣的問題, 困擾甚久, 希望有人能給予提示,
> 多謝
不要下最佳化參數就不會這樣了,
因為 compiler 會做一些 instruction scheduling,
你用 -g -S 輸出 .s 組語檔看就會知道,
loc 假指令後面會跟著 source code 的行號,
下最佳化參數以後那個數字就有可能往回跳。
--
Name: Tseng, Ling-hua E-mail Address:
[email protected]
School: National Tsing Hua University Department: Computer Science
Interesting: C++, Compiler, PL/PD, OS, VM, Large-scale software design
Researching: Undecided
Homepage:
https://it.muds.net/~uranus
--
╔═══╗ ┼────────────────────────╮
║狂狷 ║ │
* Origin:[ 狂 狷 年 少 ] whshs.cs.nccu.edu.tw ╰─╮
║ 年少║ ┼╮
< IP:140.119.164.16 > ╰─╮
╚╦═╦╝ ╰
* From:61-230-236-188.dynamic.hinet.net
─╨─╨─ KGBBS ─ ◎ 遨翔"BBS"的狂狷不馴;屬於年少的輕狂色彩 ◎
1F:推 indept:多謝, 已解決 171.64.92.135 08/26 05:14