Debug the program "For_wind" with GDB

Source: Internet
Author: User
GDB Debugging related Learning notes ~ for_wind Debug a program with GDBHttp://wiki.ubuntu.org.cn/%E7%94%A8GDB%E8%B0%83%E8%AF%95%E7%A8%8B%E5%BA%8F

analysis of the basic working principle of GDBHttp://www.embeddedlinux.org.cn/html/xinshourumen/201304/06-2530.html
Through a system call: Ptrace. Description: Ptrace system calls provide a way for the parent process to observe and control the execution of other processes, examine and change its core image, and register. It is mainly used to implement breakpoint debugging and system call tracking. (Man Handbook)
GdB's StartupIn general, GDB is primarily debugging C + + programs. To debug a C + + program, first at compile time, we have to add debug information to the executable file. You can do this with the-g parameter of the compiler (cc/gcc/g++). such as: Gcc-g hello.c-o Hello
g++-G Hello.cpp-o Hello

Without-G, you will not see the program's function name, variable name, instead of all the run-time memory address.
gdb CommandLet's briefly describe the command words that need to be used in GDB debugging.
file [filename]
Mount the executable file you want to debug
Kill [FileName]
Terminate the program being debugged
Break [File:]function
Set a breakpoint in the (file's) function functions
Clear
Deletes a breakpoint, which needs to specify the line of code or function name as an argument
Run [arglist]
Run your program (if arglist is specified, run the program as a parameter arglist)
BT BackTrace
displaying program stack information
Print expr
Print the value of an expression
Continue
Continue running your program (after stopping, for example, after a breakpoint)
List
List part of the source code that generated the execution file
Next
Step into (after stopping); Skip function calls (the step corresponds to step, and step goes inside the function)
Nexti
Executes an assembly instruction in the source code of the next line
Set
Sets the value of a variable. For example, set nval=54 will save 54 to a Nval variable, and setting input parameters can also be done with this command (for example, when three incoming parameters are a, B, c respectively, set args a b c)
Step
Step into (after stopping); Enter function call
Stepi
Continue to execute the assembly instruction in the next line of the program's source code. If it is a function call, the command will go inside the function, stepping through the assembly code in the function
Watch
Allows you to monitor the value of a variable regardless of when it is changed
Rwatch
Specifies a variable, if the variable is read, suspends the program, displays the information in the debugger, and waits for the next debug command. Refer to Rwatch and watch commands
Awatch
Specifies a variable, if the variable is read or written, suspends the program, displays the information in the debugger, and waits for the next debug command. Refer to Rwatch and watch commands
Ctrl-c
Stops execution of executing program at current position, breakpoint on current line
Disable
Disable breakpoint feature, this command requires a forbidden breakpoint in the breakpoint list index value as parameter
Display
Displays the value of the specified expression where the breakpoint is stopped. (Show variables)
Undisplay
Deletes a variable display setting of display. This command needs to make the index in the display list an argument
Enable
Allow breakpoint function, this command needs to allow breakpoints in breakpoint list index value as parameter
Finish
Continue execution until the current function returns
Ignore
Ignores the number of times a breakpoint has been set. Example: Ignore 4 23 ignores Breakpoint 4 's 23 run and interrupts at 24th time
info [name]
View name Information
Load
Dynamically load an executable file into the debugger
Xbreak
Set a breakpoint on the point at which the current function exits
Whatis
Display the value and type of a variable
PType
Display the type of a variable
Return
Force to return from the current function
Txbreak
Set a temporary breakpoint on the exit point of the current function (only once)
Make
Allows you to recreate the executable without exiting GDB
Shell
Enables you to execute UNIX shell commands without leaving GDB
Help [Name]
Displays information about the GDB command, or shows you how to use GDB's overall information
Quit
Exit GdB.

gdb-tui Code Window related commands:

Info win Displays the size of the window

Layout next switch to the next layout mode

Layout prev Switch to previous layout mode

layout src only shows source code

Ctrl+x+a Exit Layout

Layout ASM only Displays assembly code

Layout split display source code and assembly code

Layout regs Add Register content display

Focus Cmd/src/asm/regs/next/prev Toggle Current Window

Refresh refreshes all windows

TUI Reg Next Displays the next set of registers

TUI Reg System Display Systems registers

Update Updates Source code window and current execution point

Winheight name-+-line adjusts the height of the name window

Tabset nchar set tab to nchar characters

GDB will automatically track code in execution
To save and restore breakpoint information:
(GDB) Help save breakpoints
Save current breakpoint definitions as a script.
This is includes all types of breakpoints (breakpoints, watchpoints,
Catchpoints, tracepoints). Use the ' source ' command in another debug
Session to restore them.

Save Breakpoint
(GDB) Save Breakpoints Gdb.cfg Load Breakpoint
(gdb) Source Gdb.cfg

Breakpoint Settings

GDB Breakpoint Category:

To classify the commands that set breakpoints:

Breakpoint

You can generate breakpoints based on line numbers, functions, and conditions.

Watchpoint

A breakpoint is generated when the value of a monitoring variable or expression changes.

Catchpoint

The generation of monitoring signals. For example, C + + throw, or when loading libraries.

GDB in the variable starting from 1 label, different breakpoints using variable label the same management, you can use the Enable, disable and other command management, while supporting the operation of the scope of the breakpoint, such as some commands to accept the scope of the breakpoint as a parameter.

Specific commands slightly.

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.