The Linux GDB uses

Source: Internet
Author: User

GDB is used under Linux to debug a software, here, I only record the usual often used knowledge points, what to use, to record what, in the debugging environment to familiarize with debugging methods and debugging tools, this will deepen understanding.

What can gdb do? It can be in accordance with your definition, arbitrary control of your program, so that the program at the breakpoint you specify to stop, when stopped, you can check what happened in your program, you can also dynamically change the execution environment of the program. In the early stages you need to do the preparation, just need to add the-G option at compile time.

B Function name/number of rows

B filename:linenum 

B info  //View breakpoint information

Delete Breakpin ts //Delete breakpoint

When the break command has no arguments, it stops at the next instruction.

B If i = 3   when I is 3 o'clock, set to a breakpoint, stop the program.

Info b to view breakpoints

R run, know to encounter a breakpoint or exit

S run step-by-step, the function is entered into   s <count>: Step into the following count bar, then stop

The

N encounters a function and executes directly without entering.

C continues executing the program until the next breakpoint is encountered or the program exits

Finish to run the program until the current function finishes returning, and the return stack address, return value, and parameter information for the function are printed.

U run the program until you exit the loop body

bt    view the function stack

P i    Print the value of the variable i

View count The value of a group or a contiguous amount of memory space, you can use GDB's @ operator, the "@" to the left is the address value of the first memory, and the right is the length of memory you want to see.

For example:

int *array  = (int *) malloc (len * sizeof (int));

During debugging, you can use P *[email protected] To see the relevant content, if it is a static array, then the P array is the contents of the array,

Watch i   ; Set the watch variable, and stop running once the variable changes.

3. During debugging, you can execute a shell command or execute the make command, which calls the current directory's makefile to compile a new program, so you can dynamically modify the code, compile and debug it, while debugging, without exiting GDB's debug command interface.

.

4. Set the operating parameters

Set args 10 20 30 40 50 Setting Run Parameters//ARGC = 6 argv[0]= program name argv[1]=10 argv[5]=50

Show args

Info Program//Viewer run status

Other advanced features, until later use, then go deep experience learning.

The Linux GDB uses

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.