Linux GDB Basic Concepts

Source: Internet
Author: User

GDB is a powerful debugger, which is a free software that can be used on many UNIX platforms. It is also the default debugger in Linux systems. GDB has been ported to many other computer platforms and can be used to debug embedded real-time systems. In general, GDB can mainly help us to complete the following four aspects of the function: 1, start your program, you can follow your custom requirements to run the program at will.  2, you can have the program being debugged stop at the breakpoint you specified. 3, when the program is stopped, you can check what happens in your program at this time.  4, dynamically change the execution environment of your program. GDB has the following advantages over graphical debugging tools: GDB starts much faster than a GUI, which is an important advantage when you need to quickly check something in your code. This difference in startup time is significant when compared to eclipse.

The following is an experiment of the code I copied on my own virtual machine.

GCC main.c-g-o app

GDB app

Then we can use GDB to debug.

Run is executed at full speed, start execution, and these two commands are best added (recommended) if they have command line arguments.

Start interface

Start executes directly to line 67.

List: You can view the code

List+num can indicate which line of code to view

Listen to break can interrupt point, info breakpoints can see which breakpoints we used, delete breakpoints can cancel breakpoint, here we need to notice a problem is, in virtual Studio breakpoint, If it turns off the next open still exists, but if it's closed here next time it won't exist.

In response, VS has a custodial function, that is, monitor variables, display has this function, info display can see which variables we monitor, and then each time we next and step, we will show the last few lines of the monitored variables, delete is deleted

Step is the statement mode, next is to follow the process mode

Set var variable name = value can change the value of a variable halfway,

printf can output variable values in the middle

BackTrace (BT) shows the level of the program is closed, with the function call stack frame, the following 75 lines to 26 lines jump to another function, so that you can use BackTrace to see the hierarchical relationship, two functions using different stacks, so we use print argc when not working, We can jump to main in the frame temporarily,

In a box of functions we use finish to challenge the start of the call

X (X/20WX) can be viewed in memory, 20 to see 20 bytes, w means word,x for hexadecimal

Continue if a breakpoint is used, we can use the continue to power down

Set Follow-fork-mode (child or parent) calls the parent process sub-process

Core enable core file to help debug

When compiling and running the app, if there is a problem, it is very convenient to generate a core file that will directly find the error through GDB core, but the core file is particularly large

Quit debugging

Linux GDB Basic Concepts

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.