The C language-gdb debugging tool detailed

Source: Internet
Author: User

Enter repeat Last command

To produce a debugger executable file:
Gcc-g Main.c-o Main, you must add the-G line to indicate that the source file information is added to the executable file, but not to embed the source file in the executable, so you must ensure that GDB can find the source file when debugging

Go to debug:
GDB fname, entering the debug environment of the fname executable file

To view the source file code:
L/list N/func/fname:n/fname:func

To view more information:
I/info View a Breakpoint | Details about a variable, etc.

Debugging steps:
Start using, start running the program, stop in front of the first line of the main function of the statement waiting for the command
R/run starts with, runs the program from the beginning, executes the program continuously until a breakpoint is encountered
N/next the next line, but does not enter a function call
S/step the next line and enters the function call, that is, if there is a function call into the function
C/continue continue executing the program until the next breakpoint
Fini/finish continue to current stack frame/function completion
Bt/backtrace print run-time stacks

Variable Information management:
P/print variable name, print the value of the variable
Display variable name, which causes the value of the variable to be displayed each time the program stops
X/NBX variable name, viewing n bytes starting from the variable name, X/7BX input for viewing the contents of 7 memory units starting from the variable input
Set var variable name = variable value, such as set $p = * ($ESP)

To view the function stack:
Bt/backtrace viewing information for function calls
F/frame N, n is the stack level, then you can use other commands (info) To view variable information at this level, you can use BT to list the function call information in the stack, and then use F N to switch between stack functions

Breakpoint Management:
B/break N/func/fname:n/fname:func If condition, set breakpoint-can be used/without the IF condition
I/info breakpoints, view the breakpoint information for the setting
Delete Breakpoints N/func ..., remove breakpoint
Enable breakpoints N/func ... to make breakpoints effective
Disable Breakpoints N/func ... to invalidate a breakpoint

Exit GDB:
Q/quit

Reference:

http://blog.csdn.net/nixiangxiren/article/details/6935052

Http://www.cnblogs.com/kzloser/archive/2012/09/21/2697185.html

The C language-gdb debugging tool detailed

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.