Fourth, maintain the stop point
The above mentioned how to set the stop point of the program, the stop point in the GDB is the three classes described above. In GDB, if you feel that the defined stop point is not used, you can use the delete, clear, disable, and enable, these commands to maintain.
Clear clears all defined stoppoints.
Clear
Clear
Delete [BreakPoints] [Range ...] Deletes the specified breakpoint, BreakPoints is a breakpoint. If the break point is not specified, it means deleting all breakpoints. Range represents the range of breakpoints (such as: 3-7). Its shorthand command is D.
A better way to delete is the disable stop point. The stop point of Disable, the GDB will not be deleted. When you need it, Enable is as follows.
Disable [BreakPoints] [Range ...] Disable, the stop point specified by Disable, BreakPoints is the stop point number. If nothing is specified, it means all stop points for Disable. The shorthand command is DIS.
Enable [Breakpoints] [Range ...] Enable The stoppoint specified, Breakpoints is the stop point number.
Enable [BreakPoints] Once Range ... Enable The stop point specified once, when the program is stopped, the stop point is automatically disabled by GDB.
Enable [BreakPoints] delete Range ... Enable The stop point specified once, when the program is stopped, the stop point is automatically deleted by GDB.
5. Stop condition maintenance
As mentioned earlier, when we mentioned the breakpoint, we mentioned that you can set a condition. When the conditions are set up, the program is automatically stopped. This is a very powerful function. Here, I want to tell the relevant maintenance commands for this condition. In general, set a condition for breakpoints, we use the IF keyword, followed by its breakpoint conditions. Moreover, after the condition is set, we can use the construct command to modify the conditions of the breakpoint. (Only Break and Watch Commands Support IF, Catch does not currently support IF)
Condition
Condition
There is also a particularly special maintenance command ignore, you can specify the program run, ignore the stop condition a few times.
Ignore
6. Set the run command for the stop point
We can use the Command command provided by GDB to set the run command of the stop point. That is, when the running program is stopped, we can make it automatically run for some other commands, which is advantageous to automate debugging. GDB-based automation debugging is a powerful support.
Commands [BNUM] ... command-list ... End
Write a list of commands for the breakpoint BNUM. When the program is stopped by the breakpoint, the GDB will run the command in the command list.
E.g:
Break foo if x> 0 Commands Printf "x IS% D / N", X Continue End breakpoint is set in the function foo, the breakpoint condition is x> 0, if the program is broken, that is, once X In the FOO function is greater than 0, GDB automatically prints the value of X and continues to run the program.
If you want to clear the command sequence on the breakpoint, just make a commands command, and you will do it directly.
Seven, breakpoint menu
In C , you may repeat the function of the same name (function overload), in which case BREAK
(GDB) B String :: after [0] Cancel [1] all [2] file: string.cc; line number: 867 [3] file: string.cc; line number: string.cc; line number: string.cc Line Number: 875 [5] file: string.cc; line number: 853 [6] file: string.cc; line number: 846 [7] file: string.cc; line number: 735> 2 4 6 Breakpoint 1 at 0xb26c: file String.cc, line 867. Breakpoint 2 at 0xb344: file String.cc, line 875. Breakpoint 3 at 0xafcc:. file String.cc, line 846. Multiple breakpoints were set Use the "delete" command to delete UNWANTED BREAKPOINTS. (GDB)
It can be seen that GDB lists all After's overloaded functions, you can choose the list number. 0 indicates that the setting breakpoint is given, and 1 means that all functions set breakpoints.
Eight, recovery procedures running and single-step debugging
When the program is stopped, you can use the Continue command to recover the run until the end of the program, or the next breakpoint. You can also use the STEP or NEXT command single-step tracker.
Continue [ignore-count] c [ignore-count] FG [ignore-count] recovery program runs until the program ends, or the next breakpoint arrival. Ignore-count indicates that the number of breakpoints is ignored. The three commands of Continue, C, and FG are the same meaning.
Step
Next
Set Step-Mod Off Turns the Step-Mode mode.
Finish running procedure until the current function completes the return. And print functions returned to the stack address and return value and parameter value.
Until or u When you are tired of walking in a cyclic body, this command can run the program until the cyclic body is exited.
Stepi or Si nexti or Ni single step tracking one machine directive! A program code may be completed by several machine instructions, STEPI and NEXTI can perform machine instructions in a single step. As with the same function as the same function is "Display / I $ PC", after running this command, single-step tracking will play machine instructions while playing the program code (that is, assembly code)
Nine, signals (SIGNALS)
The signal is a soft interrupt, a method of processing an asynchronous event. In general, the operating system supports many signals. Especially UNIX, compare important applications generally process signals. Unix defines a number of signals, such as Sigint represents the interrupt character signal, that is, the signal of Ctrl C, Sigbus represents the signal of the hardware fault; SIGCHLD represents the signal of the child process; Sigkill indicates the signal of the termination program, and the like. Semicidal programming is a very important technology under UNIX.
GDB has the ability to deal with any signal when you debug the program, you can tell GDB which signal needs to process. You can ask GDB When you receive the signal you specified, you will stop running the program that is running for you to debug. You can use the GDB's handle command to complete this feature.
Handle
Nostop When the debugging program receives a signal, GDB does not stop the running of the program, but the message tells you that this signal is received. When the STOP receives the signal when the debugged program, GDB will stop your program. Print When the debugging program receives the signal, GDB will display a message. NOPRINT When the debugging program receives the signal, GDB will not tell you information about the signal. PASS NOIGNORE When the debugging program receives the signal, the GDB does not process the signal. This means that GDB will hand over this signal to the debugged program. When NOPASS IGNORE receives a signal when the debugged program receives the signal, the GDB will not let the debug program process this signal. Info Signals Info Handle View which signals are in GDB detection.
Ten, thread stops
If your program is multi-thread, you can define if your breakpoint is on all threads or in a particular thread. GDB is easy to help you have completed this.
BREAK
When your program is parked by GDB, all running threads will be stopped. This makes it easy you to view the overall situation of the running program. And all threads are still running when you are running in your recovery program. It is afraid that the main process is in a single step of debugging.
<- Previous Next -> (All rights reserved, please indicate the author and source)