01. File -> New -> Project -> Console application -> Go -> C/C++ -> 打上 Project title 和選擇要存放的位置 -> Next -> Finish
// 不要懶的創 Project,就 File -> New -> File -> C/C++ source -> Go -> C/C++ -> ...
// 或更偷懶直接,就 File -> Empty file
// 因為這樣會不能使用 Debug 功能
02. 點左邊 Projects 下的 Workspace -> Project title -> Sources -> *.cpp,貼上下面的程式碼,來體驗一下 Code::Blocks 的 Debug 功能。
# include <iostream>
# define SIZE 10
using namespace std;
int main( ) {
int test[ SIZE ] = { 0 };
for ( int i = 0; i < SIZE; i++ ) {
test[ i ] = i;
}
system( "PAUSE" );
return 0;
}
03. Code::Blocks Debug 三部曲
a. Build target 切換到 Debug
b. Settings -> Compiler and debugger -> Produce debugging symbols [-g] 打勾
c. 新增中斷點 : 在 test[ i ] = i; 那行,行號的右邊空白按左鍵( or 右鍵 -> Add breakpoint )
04. 上面都設定好後,按下 F8 or IDE 上的圖示( Debug / Continue ) 就可以開始 Debug 了。
// Watches、Disassembly、Call Stack、Memory、CPU Registers 等,都可以在 Debug -> Debugging windows 下找到
05. 照上面設定還是不能 Debug 的話
a. Build target : Debug
b. 檢查 Settings -> Compiler and debugger -> Produce debugging symbols [-g] 是否有打勾 ( 要打勾 )
// 特徵 : ( no debugging symbols found )
d. 檢查 Settings -> Compiler and debugger -> Strip all symbols from binarry ( minimizes size ) [-s] 是否有打勾 ( 不要打勾 )
// 特徵 : ( no debugging symbols found )
c. 檢查是否有 gdb.exe
// 可以到 ( The GNU Project Debugger ) 點 GNU Source-Level Debugger 下載
// 可以到 ( The GNU Project Debugger ) 下載
Tags: Code::Blocks, Debug, GNU
