In the Linux system there are many command programs to assist the normal and convenient operation of the system, then there is a system called the GDB command program, then we today to understand the knowledge of the GDB command!
First, the general debugging
GDB is commonly used in Linux under the Program Debugging tools, of course, the premise is to compile with the gcc/g++-G parameters, so that the compiled executable program will add GDB debugging information.
GDB commands a number of, but commonly used mainly include the following command:
(1) List [File:]functuon
command abbreviation is L, see the source code, without parameters, the downward display of the source code, plus parameter-L, up to show the source code, the default display 10 lines.
can also be set in a function out of the list of source code, you need to pay attention to: if the function is not a member of the file:function can be, if the class member function is used Class::functuon.
(2) Edit [file:]function
The command abbreviation is e, edit the current line, or edit the source code of a function (the rule is the same list).
(3) Break [file:]function
The command abbreviation is B, set breakpoints, can be set in a row or a function (the rule of the same list), in addition, you can directly use the file name: line number to set breakpoints.
command abbreviation is I, list GDB subcommand information, such as: info break, info variables, info stack, etc.
(5) Run [arglist]
The command abbreviation is R, which stops at the breakpoint, and then the Run command can be followed by the parameters that the debugger needs.
The command abbreviation is n, the step debugging executes the statement, if encounters the function also when a single-step statement but does not enter the function, resembles in VC's F10.
The command abbreviation is s, the step debugging executes the statement, if encounters the function will enter directly inside the function, resembles in VC's F11.
The vanity abbreviation is C, continue to run the program to the next breakpoint.
View the variable type.
The command abbreviation is P, which prints the value of the variable.
The command abbreviation is BT, which looks at the stack information.
Enter, repeat the previous debug command.
(a) Help [name]
Displays help information for the specified GDB command.
The command abbreviation is Q, exiting GDB.
When GDB debugged the program, using the GDB. exe loader, when GDB debugged Core dump, with the GDB. exe. Core loader, execute the r command to start running the program. In gdb after editing the code, do not need to exit GDB, and directly in gdb make can, otherwise set the breakpoint and other information are flames.
Second, multithreading debugging
(1) Info threads
The command abbreviation is info THR, which displays all currently debugged threads, each thread has an ID assigned to it by GDB, and the ID is used when the thread is manipulated, with the previous * being the currently debugged thread.
(2) Thread ID
The command abbreviation is THR, which toggles the thread that is currently being debugged to the specified ID.
(3) thread apply ID1 ID2 command
The command abbreviation rule ibid., let one or more threads execute the GDB command.
(4) thread apply all command
The command abbreviation rule ibid., so that all the debugged threads execute the GDB command.
(5) Set scheduler-locking Off|on|step
When debugging a multithreaded application, when debugging the current thread using the step or Continue command, other threads are also executing concurrently, and this command can control the execution of the thread through Off|on|step, namely:
OFF: No threads are locked, that is, all threads are executing, which is the default value.
On: Only the currently debugged program will be executed.
Step: When stepping, except when Next has a function, only when the thread executes.