05.gdb Getting Started (top)

Source: Internet
Author: User

◊ Basic framework:

A) GDB functionality

b) Run the program

c) View the source code

d) Set breakpoints (break) and observation points (watch)

e) Single-step commissioning

f) gdb Common Command Summary

5.1 gdb function

1) Start the program:

Run (R), in addition to start the program can also take the parameters (Argv[1],argv[2] ... )

2) Set Breakpoints:

Set breakpoints: Break (b) + line number/function name

You can also use conditional expressions (if) when setting breakpoints

Delete breakpoint: Delete (d) + breakpoint number

View Breakpoint: Info Break (i B)

3) View variable information:

Print View variable values

Ptype Viewing variable types

4) Dynamically change the execution environment of the program:

Print variable =value dynamically changes the value of a program runtime variable

5.2 Run the program

1) Run Program (R)

2) Run + arg1 arg2 ... (parameter list)

5.3 View Source

1) List (l) View the last 10 lines of source code

L 2,10 View source code from line 2nd to line 10th

L, 15 View the source code up to line 15th

2) List +fun (function name) to see the fun functions source code

3) List +file:fun View the fun function source in file files

4) List +file:15 View the source code of the 15th line in file

5.4 Set Breakpoints ( Break ) and observation point (Watch)

1) Break line number

2) Break function number Name

3) Break file: line number

4) Break file: Name of function

5) Break if <condition> The program stops when the condition is established

6) Info Break (I b) View Breakpoint

7) Watch expr once the value of expr has changed, the program stops

8) Delete + Breakpoint number Remove Breakpoint

5.5 single-Step debugging

1) Continue (c) run to the next breakpoint

2) Step (s) Single step tracking, enter function, similar to the VC in the step in

3) Next (N) Single step tracking, not into function, similar to step out in VC

4) Finish runs the program until the current function returns, and outputs the return value of the function.

5) until Exit loop body (for)

5.6 GDB Summary of COMMON commands

Run (r) running the program

List (l) List source code

Break (b) Set breakpoints

Info Break (i B) View breakpoint information

Continue (c) continue to run the program until the next breakpoint

Watch sets the observer, and once the observation value changes, the program stops.

Step (s) Single step tracking, enter function, similar to step in VC

Next (n) Single-step tracking, no entry function, similar to step out in VC

Finish exits the function and outputs the return value of the function.

Until (U) exit loop body

Print (p) View variable values

5.7 Some detailed knowledge:

1. Press the ENTER key during GDB debugging to repeat the previous command;

2. Comparison of several exit commands:

Until exit loop (for)

Finish Exit Function

Q Exit GDB

05.gdb Getting Started (top)

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.