Linux basics (4) Gdb debugging program

Source: Internet
Author: User
Gdb debugging note: Must I add the Gcc compilation option? G. exit GDB: quit or Ctrl & amp; 43; D. the debugging process is as follows: 1.

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

 

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.