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
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 und
is stopped by GDB, you can use the Info program to see if it is running, the process number, and why it was paused.In gdb, we can pause in the following ways: Breakpoints (breakpoint), Observation points (watchpoint), Snap points (catchpoint), signal (signals), thread stop (threads Stops). If you want to restore the program to run, you can use the C or Continue command.First, set breakpoints (breakpoint)We use the break command to set breakpoints. Th
to see if the application is running, the process number, and why it was paused.
In GdB, we can have several pauses: breakpoints (breakpoint), Observation points (Watchpoint), capture points (Catchpoint), signals (signals), thread stops (threads Stops). If you want to restore the program to run, you can use the C or Continue command.
One, set breakpoints (breakpoint)We use the break command to set the breakpoint. There are several ways to set breakpo
Assembly know that when the program runs, a register is used to hold the memory address where the current code resides. So, the jump command changes the value in this register. You can then use set $PC to change the address of the jump execution. Example: Set $pc = 0x485A. Return: Forces the function to return. You can specify a return valueIv. Program interrupt mechanism: monitoring points (Watchpoint), Breakpoints (breakpoint), and snap points (Catchpoint
). GDB provides a convenient mechanism: the breakpoint of the main function inherits the quilt process (after all, main is the entrance to any program).Note: After the program stops in main, you can try to set a breakpoint. Whether the breakpoint is valid depends on whether GDB has loaded the address space of the target program.Method 3:set Follow-fork-mode child + catch execThe cache point is a special breakpoint. GDB can catch a lot of events, such asthrow/catch/exception/syscall/exec/fork/vfo
. Because only the program jumps and does not change the stack value, jumping out of the function to another place can result in a return error. In addition, people familiar with the Assembly know that when the program runs, a register is used to hold the memory address where the current code resides. So, the jump command changes the value in this register. You can then use set $PC to change the address of the jump execution. Example: Set $pc = 0x485A. Return: Forces the function to return. You
can set the line under which the program is stopped, under what conditions, and when a signal is received, so that you can view the variables and processes at run time.
When the process is stopped by GDB, you can use info program to check whether the program is running, process number, and reason for suspension.
In GDB, there are several pause Methods: breakpoint, watchpoint, catchpoint, signals, and thread stops ).
To resume the program running, run
executing program to go to a line, or jump to an address. Because only the program jumps and does not change the stack value, jumping out of the function to another place can result in a return error. In addition, people familiar with the Assembly know that when the program runs, a register is used to hold the memory address where the current code resides. So, the jump command changes the value in this register. You can then use set $PC to change the address of the jump execution. Example: Set
To debug a program that is already running
Under UNIX, use PS to see the PID (Process ID) of the running program, and then use
the GDB PID format to hook up the running program.
First, using GDB to
correlate the source code, and GDB, in gdb with the attach command to hook up the process PID. Use the detach to cancel the hook process.
Pause/Resume Program runIn the debugger, it is necessary to pause the program, and GDB can conveniently pause th
Set breakpointsb Main; At the main () entranceb 148; In line 148thviewing breakpointsInfo bRun the programRSingle statement executionNContinue running the programCPrint the value of the variable iP IViewing the function stackBtExit functionFinishThe help command is just an example of the type of GDB command, and if you want to see the commands in the category, you can see all the commands that set a breakpoint by using the helps tab complements the function name, command nameIn gdb, we can pause
), Snap points (catchpoint), signal (signals), thread stop (threads Stops). If you want to restore the program to run, you can use the C or Continue command.First, set breakpoints (breakpoint)We use the break command to set breakpoints. There are several ways to set breakpoints on the front:Break Stops when the specified function is entered. The function name can be specified in C + + using the Class::function or functions (type,type) format.Break Sto
and/or numberscatch throw--Cat Ch an exceptioncatch vfork--Catch calls to Vforktype ' help catch ' followed by CATCH subcommand name Forfull Documentation. Type "Apropos word" to search for commands related to "word". Command name abbreviations is allowed if unambiguous. (GDB) (GDB) info breakpointsnum type disp Enb Address what7 breakpoint keep y 0x08048440 in foo at t.c:5 Breakpoint already hit 1 time8 catchpoint keep y syscall "" 9 breakpoin
points (catchpoint), signal (signals), thread stop (threads Stops). If you want to restore the program to run, you can use the C or Continue command.First, set breakpoints (breakpoint)We use the break command to set breakpoints. There are several ways to set breakpoints on the front:Break Stops when the specified function is entered. The function name can be specified in C + + using the Class::function or functions (type,type) format.Break Stops at t
it is executing. Process number, the reason for being paused.In GDB. We can have the following pause modes: Breakpoint (breakpoint), observer (watchpoint), Snap Point (catchpoint), signal (signals), thread stop (threads Stops). If you want to restore program execution, you can use the C or Continue command.First, set breakpoints (breakpoint)We use the break command to set breakpoints. There are several ways to set breakpoints on the front:Break Stops
the Visual Studio Tools, and includes features that it does not have. In addition to support, we generally set breakpoints, single-step tracking, step in, step out, step over, and some other powerful features. In gdb, we can pause in the following ways: Breakpoints (breakpoint), Observation points (watchpoint), Snap points (catchpoint), signal (signals), thread stop (threads Stops).Here are a few of the features that impressed me. 1) The Watch comman
the line pointed to by the breakpoint, but will point to the line pointed to by the breakpoint.GDB is executed in the unit of machine commands, not in the line of program code. This may cause some confusion. The following is an example.2. View GDB breakpoints
Command: I B = info breakpoints. The meaning of each column in the returned list is as follows:
Identi fi er: the unique identifier of breakpoints.Type: Which of the preceding three modes does this breakpoints belong to? (breakpoint, watchp
# Deleting breakpoints on the Main Function Deleted breakpoint 1
(GDB) Clear 26 # Delete a breakpoint of 26 rows Deleted breakpoint 2 (GDB) Clear Debug. C: Main
# Delete the breakpoint on the main function in the debug. c file
1.4.3 view breakpoint Information (GDB) info breakpoints
# View the breakpoint information num type disp ENB address what3 breakpoint keep y 0x080483dc in main at debug. C: 24
1.5Watch point monitoring point
1.5.1 set monitoring points
(GDB) Watch I # Monitor v
the PID of the process. Use detach to cancel the attached process.
6. Pause/resume the program running. when the process is stopped by gdb, you can use info program to check whether the program is running, process number, and cause of suspension. In gdb, we can use the following pause Methods: BreakPoint, WatchPoint, CatchPoint, Signals, and Thread Stops ), to resume the program running, run the c or continue command.
7. Thread (Stops)
If the program
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.