Gdb debugging
Note:-g must be added to the Gcc compilation options.
Exit GDB: quit or Ctrl + d
Debugging process:
1. view files
Command:(Gdb) l
2. Set breakpoints
Command:(Gdb) B row number
Note: up to 17th rows are stopped, and 17 rows are not executed.
3. view the breakpoint info B
4. Run code r
Command:(Gdb) r
(You can also specify the row to start running, and add the row number after r)
5. View variable value p
Command:(Gdb) p variable name
6. Set monitoring point: watch z (variable name)
It can also be a complex expression.
7. One-step operation
Command:(Gdb) n(Process by process)
8. Step by step, it will enter the Function
Command:(Gdb) s
9. Conditional breakpoint
Change normal breakpoint to conditional breakpoint: condition
For example:Condition 1 I = 10
The checkpoint 1 is paused only when the condition I = 1 is met.
10. Resume program running c
Command:(Gdb) c
(The program will run. If there is no breakpoint, the remaining part will be run. If there is a breakpoint, it will run to the next breakpoint)
11. remove breakpoints
Clear line_number
Clear filename: line_number
12. help
12.1 help find the category
12.2help from the list