How to use GDB to debug? A simple menu.

1. Tools->options->Linker裡設定generate debugging information.

2. compile後執行Debug(F8)

3. run

run

r

4. 設定中斷點(breakpoints)

break linenum

 

Set a breakpoint at line linenum in the current source file.  That file is the last file whose source text was printed.  This breakpoint stops your program just before it executes any of the code on that line.

 

5.  繼續執行(Continuing)及單步執行(Step)

continue

c

Resume program execution, at the address where your program last stopped; any breakpoints set at that address are bypassed.

 

step

Continue running your program until control reaches a different source line, then stop it and return control to GDB.  This command is abbreviated s.

 

Next

Continue to the next source line in the current (innermost) stack frame.

 

6. debug中看特定參數var的值

p var