Linux Diary-gdb Command

Source: Internet
Author: User

"program"

[Compile to unlinked target program/.O file]
[No symbol table is read.] Please use "file" command.)
First, did you correctly compile the C program? Like:
Gcc-g Your.c-o AAA
Once you finish compiling the program with the use of below command to GDB it:
GDB AAA
Or If you start GDB w/o specifying the program ' AAA ', you can input
' File AAA '
In the GDB shell.
[Execution Program]
Run: Re-execute
[view variables/require breakpoints]
print/p + variable Name
If you set the breakpoint inside the loop body and want to loop the output variable value, you will need to execute the next statement with the next command.
[Output variables by format]
P I: normal output; P/C i: Character formatting; p/t i: Binary format

[Call Function/breakpoint Required]
Break 19
Run
The formal parameter in the print func (3)//function must be replaced with an argument
[view array/breakpoint Required]
Break 12
Run
Print sz
[automatically show variables/require breakpoints]
Break 15
Run
DISPLAY/D I//formatted auto output I
DISPLAY/D result//formatted output result
Step/next//performs the next step and displays the values of the automatic output variables (i and result) in the current display
Info Display//View the number + format + variable name of the auto-display variable in the current display
[Delete auto-display variable]
Delete Display 1//Remove an auto-display variable according to the number obtained by info
Undisplay//Delete all variables in the current display
[Enable/disable auto prompt]
Disable display [1]//display the line number indicates that the current line is disabled and all rows are disabled
Enable display [1]//enabled, same as above
Disable Display 1 2//middle space to manipulate multiple auto-display variables

"Breakpoint"

Note:<1> commands after breakpoints are not automatically executed (either in main or in other functions), only manually step by step;
<2> breakpoints follow the calling function into the external function body.
[New Breakpoint]
Break 1
[Delete endpoint]
<1> (GDB) Delete Breakpoint 1//delete current position breakpoint, 1 represents the first breakpoint
<2>clear//Remove the breakpoint at the last stop of the program
<3>clear 20//Delete all breakpoints on line 20th

[Set breakpoint valid invalid]
Enable/disable Breakpoint
[view current breakpoint information]
Info break/b
[value of variable at breakpoint]
print/p + variable Name
If you set the breakpoint inside the loop body and want to loop the output variable value, you will need to execute the next statement with the next command.
[shortcut key enters next breakpoint]
Note: After <1>[breakpoint] You can continue with run, continue, next, step.
<2> If the breakpoint is paused after it has been executed, then the next program execution can use enter instead of the command you just made.
The difference between #.run continue next step
[Run]: Head = Breakpoint
Refers to the Gcc-c compiled intermediate program from the beginning to execute, retaining breakpoints/automatic display and other properties;
[Continue]: Breakpoint = + End/Loop once
If the breakpoint is not inside the loop, the result is directly executed once, and if the breakpoint is inside the loop, the execution once is equal to a loop (convenient ~);
[Step]: Breakpoint = breakpoint +1 command line (enter the function to be adjusted)
If a function call is on the source line where the command will run, the step command causes GDB to enter the inside of the called function.
[Next]: Breakpoint = breakpoint +1 command line (does not enter the called function)
Unlike step, it does not enter the function, but waits at the exit.
All four of the above can be set to automatically display the variable after the breakpoint, especially within the loop to monitor the value change.
[Conditional breakpoint]: Breakpoints appear when eligible, used in loops/judgments
<1>break 6//Assume info break is number 2nd
Condition 2 i==5//When a breakpoint is added to line 6th at the time of i=2, the other condition equals that breakpoint does not exist
<2>break 6 if i==5//meaning ditto, just together write


Linux Diary-gdb Command

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.