This is the second of a series of "hands-on-the-go" GDB, with the main content being the Breakpoints (breakpoint), the monitoring point (Watchpoint), and the snapping point (catchpoint) that are commonly used in the GDB debugger. Although the functions of these three types of point are different, they are very similar in usage. Therefore, this article will take the break breakpoint as an example, carries on the detailed introduction, about Watchpoint and Catchpoint's introduction is relatively rough, believes the reader friend if can understand breakpoint's part, then can comprehend by analogy, Learn how to use Watchpoint and Catchpoint.
1. Breakpoint: The role is to let the program execution to a specific place to stop running
(1) Set breakpoint:
A. Break function: Set breakpoint at the function funtion entrance
B. Break +offset: Set breakpoint at the line where the program is currently stopped forward offset
C. Break–offset: Set breakpoint on the line where the program is currently stopped to the NGA offset line
D. Break LineNum: Set LineNum line at the current source file breakpoint
E. Break Filename:linenum: Set the LineNum line at the source file named filename Breakpoint
F. Break filename:function: Set breakpoint at the entry of function functions in the source file named filename
G. Break *address: Set breakpoint at address of the program
H. Break ... if cond: ... On behalf of any of the possible arguments mentioned above, a breakpoint is set somewhere, but only if cond is true, the program stops
I. Tbreak args: Sets a breakpoints that stops only once, with the same args as the break command. Such a breakpoint will be deleted by itself when it is first stopped.
K. Rbreak regex: Set breakpoint at all functions that conform to regular expression regex
(2) info breakpoints [n]:
View information about nth breakpoints, and if n is omitted, displays information about all breakpoints (3) pending breakpoints:
A breakpoints that sets the location in a dynamic library that is loaded after the program starts debugging
A. Set breakpoint pending auto:gdb default setting, ask the user if you want to set pending breakpoint
B. Set breakpoint pending ON:GDB currently unrecognized breakpoint automatically become pending breakpoint
C. Set breakpoint pending OFF:GDB does not currently recognize a breakpoint, direct error
D. Show breakpoint pending: View GDB's behavior on pending breakpoint settings (auto, on, off)
(4) Deletion of breakpoints:
A. Clear: Clears all breakpoints after the next instruction in the current stack frame
B. Clear function & Clear filename:function: Clear breakpoints at the entrance to function functions
C. Clear LineNum & Clear Filename:linenum: Clear the breakpoints at line LineNum
D. Delete [breakpoints] [range ...]: Delete range specified by Range Breakpoints,range range refers to breakpoint's serial number
(5) Disable and enable the breakpoints:
A. Disable [breakpoints] [range ...]: Disables breakpoints in the range specified by range
B. Enable [breakpoints] [range ...]: Enables breakpoints in the range specified by range
C. Enable [breakpoints] once [range ...]: Enables only one breakpoints in the range specified by range, and when the program stops, it is automatically set to Disabled
D. Enable [breakpoints] Delete [range ...]: Enable breakpoints within range specified, and the breakpoints is automatically deleted after the program has stopped
(6) Conditions breakpoints related commands:
A. Setting conditions breakpoints can be set by break ... if cond, or by condition bnum expression, where you first set the breakpoints by the command described in (1). The condition command is then used to specify the condition of a breakpoint, which is specified by the Bnum, and the condition is specified by expression.
B. Condition Bnum: Conditions for the abolition of Bnum breakpoint
C. Ignore Bnum count: First Bnum breakpoint Skip count and start in effect
(7) Specifies that the program stops after a breakpoint to execute a sequence of commands:
A. Format: commands [Bnum]
..... command-list ...
End
B. Purpose: Specifies that the command string specified by Command-list is executed after the program stops at Bnum Breakpoint, and the last breakpoint is in effect if no bnum is specified
C. List of CANCELLATION commands: commands [Bnum]
End
D. Examples:
Break Foo if x>0
Commands
Silent
printf "x is%d\n", X
Continue
End
The above example means: When x>0, stop at the Foo function, then print out the value of X and then continue running the program
2. Watchpoint: Its role is to allow the program to stop running when the value of an expression changes, to "monitor" the expression's purpose
(1) Set watchpoints:
A. Watch expr: Set write Watchpoint, when the application writes expr, modifies its value, the program stops running
B. Rwatch expr: Set read Watchpoint, when the application reads expression expr, the program stops running
C. Awatch expr: Set read-write Watchpoint, when the application reads or writes the expression expr, the program stops running
(2) info watchpoints:
View watchpoints information that is set in the currently debugged Program (3) Watchpoints and breakpoints are very similar, there are enable/disabe/delete and other operations, using the same method as breakpoints
3. Catchpoint: The function is to let the program in the event of a time to stop running, such as C + + in the event of an exception, loading dynamic library events
(1) Set catchpoints:
A. catch Event: When the event occurs, the program stops running, where the value of the event is: 1) throw:c++ throws an exception
2) catch:c++ catch to exception
3) Exec:exec is called
4) Fork:fork is called
5) Vfork:vfork is called
6) Load: Load Dynamic Library
7) Load Libname: Load a dynamic library named Libname
8) Unload: Uninstalling the dynamic library
9) Unload Libname: unload a dynamic library named Libname
Syscall [args]: Invoke system call, args can specify system call number, or system name
B. Tcatch Event: Set the Catchpoint to stop only once, the Catchpoint is automatically deleted after the first entry (2) catchpoints and breakpoints are very similar, there are enable/disabe/ Delete and other operations, using the same method is similar to breakpoints