Introduction to command knowledge of GDB program debugging tools in Linux system

Source: Internet
Author: User
Tags thread

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.

(4) Info

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.

(6) Next

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.

(7) Step

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.

(8) Continue

The vanity abbreviation is C, continue to run the program to the next breakpoint.

(9) What

View the variable type.

(Ten) Print

The command abbreviation is P, which prints the value of the variable.

(one) BackTrace

The command abbreviation is BT, which looks at the stack information.

() Enter

Enter, repeat the previous debug command.

(a) Help [name]

Displays help information for the specified GDB command.

(quit)

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.

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.