GDB command outline -------
After starting the GDB, you can use the GDB command to start the debugger using the GDB command, and the gdb command can use the HELP command to view, as shown below:
/ Home / hchen> gdb GNU gdb 5.1.1 Copyright 2002 Free Software Foundation, Inc. GDB is free software, covered by the GNU General Public License, and you are welcome to change it and / or distribute copies of it under certain conditions. Type "Show Copying" to see the conditions. There is absolutely no warranty for gdb. Type "Show Warranty" for details. This GDB WAS Configured AS "i386-suse-linux". (GDB) Help List of classs of Commands:
aliases - Aliases of other commands breakpoints - Making program stop at certain points data - Examining data files - Specifying and examining files internals - Maintenance commands obscure - Obscure features running - Running the program stack - Examining the stack Status - Status Inquiries Support - Support Facilities TracePoints - Tracing of Program Execution WITHOUT Stopping The Program User-Defined - User-Defined Commands
Type "Help" Followed by a class name for a list of commists in That class. Type "Help" Followed by Command Name for Full Documentation. Command name abbreviations are allowed if unambiguous. (GDB)
There are a lot of GDB commands, and GDB is divided into many types. The HELP command is just a command type of GDB. If you want to see the command in the species, you can use the help
In the GDB, when entering the command, you can use the first few characters that only use the command, of course, the first few characters of the command should mark a unique command, under Linux, you can knock The full name of the Tab key to make up the command, if there is repetitive, then GDB will come out. Example 1: Set a breakpoint when entering the function FUNC. Can be knocked into Break func, or is directly b func breakpoint 1 at 0x8048458: file hello.c, line 10. Example 2: Typing B Press twice Tab keys, you will see all B heads Command: (GDB) B Backtrace Break BT (GDB) Example 3: Remember the function's prefix, so that: (gdb) b beam_
Example 4: When debugging the C program, there is a function name. Such as: (GDB) b 'Bubble (INT, INT) B' BUBBLE (You can see all overload functions and parameters in C . (Note: m -? And "according to the Tab key" "
When you want to quit GDB, just send quit or command to Q.
Running UNIX in GDB ------------
In the GDB environment, you can execute the unix shell command, complete using the gdb's shell command:
Shell
Another GDB command is make: make
Run out in GDB --------
When GDB is started in GDB
In GDB, run the program using R or the run command. The operation of the program, you may need to set the following four aspects. 1, the program runs the parameters. Set Args Specifies the runtime parameter. (, Such as: SET ARGS 10 20 30 40 50) The show args command can view the setup run parameters.
2, the operating environment. Path
3, work catalog. CD
4, the input and output of the program. INFO TERMINAL displays the mode of the terminal you use. Use the redirection control program to output. Such as: run> outfile tty command can write the terminal device input and output. Such as: TTY / DEV / TTYB
Debugging the running program --------
Two methods: 1. View the PID (process ID) of the running program with PS under UNIX, and then mount the running program with GDB
Pause / recovery program run ---------
In the debugger, the suspension program is required, and GDB can easily pause the operation of the program. You can set the program where you have stopped, stop under what conditions, or stop when you receive a signal. To allow you to view runtime variables, as well as runtime processes.
When the process is parked by GDB, you can use Info Program to see if the program is running, the process number, and is suspended.
In GDB, we can have the following pauses: breakpoint, watchpoint, catchpoint, signal (Signals), thread stops. If you want to recover the program, you can use C or the Continue command.
First, set breakpoints, we use the break command to set the breakpoint. There are several ways to set breakpoints on the front: BREAK
Break
Break Offset Break -offset Announces the offset line in front of the current line number. OFFSET is natural number.
Break FileName: Linenum Announced on the Linenum line of the source file filename.
Break filename: Function is stopped at the entrance to the function function of the source file filename.
Break * address stops at the memory address running.
When the BREAK BREAK command does not have a parameter, it is said to stop at the next instruction.
Break ... if
Second, setting the WatchPoint observation point General to observe if a certain expression (variable is also an expression) value varies, if there is a change, stop the program immediately. We have the following ways to set the observation point: Watch
Third, set the capture point (CatchPoint)
You can set the capture point to make some events at runtime. Such as: Load shared library (dynamic link library) or C exception. Set the format of the capture point to: catch
Tcatch
<- Previous Next->
(All rights reserved, please indicate the author and the source when reproduced)