Common GDB Commands Chinese quick glance

Source: Internet
Author: User

Transferred from: Https://linux.cn/article-8900-1.html?utm_source=index&utm_medium=moremore

Directory
  • Break-Sets a breakpoint at the specified line or function, abbreviated asb
  • Info Breakpoints--Print a list of all breakpoints, observers, and capture points that have not been deleted, abbreviated asi b
  • Disable--disables breakpoints, abbreviated todis
  • Enable--Enables breakpoints
  • Clear-Clears the breakpoint at the specified line or function
  • Delete--Deletes the breakpoint, abbreviated tod
  • Tbreak--Set a temporary breakpoint, the same parameters break , but will be automatically deleted after the first time the program has stopped
  • Watch-Sets the observer point for an expression (or variable) and pauses the execution of the program when the value of the expression (or variable) changes
  • Step--Single step tracking, if there is a function call, will enter the function, abbreviated tos
  • Reverse-step--Reverse single-step tracking, if there is a function call, will enter the function
  • Next--single-step tracking, if there is a function call, does not enter the function, abbreviated ton
  • Reverse-next--Reverse single-step tracking, if there is a function call, does not enter the function
  • Return--Returns the selected stack frame to its caller
  • Finish-executes until the selected stack frame is returned, abbreviated tofin
  • Until-executes until a line after the current line in the current stack frame is reached (for skipping loops, recursive function calls), abbreviated tou
  • Continue--Recovery program execution, abbreviated toc
  • Print--Prints the value of EXP for the expression, abbreviated top
  • X--View memory
  • Display-Prints the value of EXP (auto-display) of an expression each time the program stops
  • Info Display-Prints the list of expressions that were previously set to auto-display
  • Disable Display-disables auto-show
  • Enable Display--turn on auto show
  • Undisplay--delete auto Display items
  • Help--Print a list of commands (helps to find commands with parameters), abbreviated ash
  • Attach--hook up to a process that is already running to debug
  • Run-Starts the program being debugged, abbreviated tor
  • BackTrace--View information for the program call stack, abbreviated tobt
  • PType--Definition of type of printing
Break

Use the break command (abbreviation b ) to set breakpoints.

Usage:

    • breakWhen no parameters are taken, breakpoints are set at the next instruction executed in the selected stack frame.
    • break <function-name>Break points at the entrance of the function body, which can be used class::function 或 function(type, ...) to specify the function name in C + +.
    • break <line-number>Breaks the point at the beginning of the specified line in the current source file.
    • break -Nbreak +Nbreaks the point at the beginning of a line before or after the current source line N , N as a positive integer.
    • break <filename:linenum>filenamebreak point at the line of the source file linenum .
    • break <filename:function>filenamebreak point at the function entrance of the source file function .
    • break <address>Breaks the point at the address of the program instruction.
    • break ... if <cond>Sets a conditional breakpoint, which ... represents one of the above parameters (or no argument), and cond is a conditional expression that pauses the execution of the program only when the cond value is not zero.

See official documentation.

Info Breakpoints

View a list of breakpoints, observer points, and capture points.

Usage:

    • info breakpoints [list...]
    • info break [list...]
    • list...The number used to specify a number of breakpoints (which can be omitted), can be 2 , 1-3 , and 2 5 so on.
Disable

Disable some breakpoints. The parameter is a space-delimited breakpoint number. To disable all breakpoints, do not add parameters.

Disabled breakpoints are not forgotten, but are not valid until re-enabled.

Usage:

    • disable [breakpoints] [list...]
    • breakpointsis disable the Sub-command (which can be omitted), list... info breakpoints in the same description.
      See official documentation.
Enable

Enable some breakpoints. Give the breakpoint number (separated by a space) as the parameter. When there are no parameters, all breakpoints are enabled.

Usage:

    • enable [breakpoints] [list...]Enables the specified breakpoint (or all defined breakpoints).
    • enable [breakpoints] once list...Temporarily enables the specified breakpoint. GDB disables these breakpoints immediately after stopping your program.
    • enable [breakpoints] delete list...Causes the specified breakpoint to be enabled once and then deleted. Once your program stops, GDB will delete these breakpoints. Equivalent to tbreak the breakpoint set with.

breakpointsdisabledescription in the same.

See official documentation.

Clear

Clears the breakpoint at the specified line or function. A parameter can be a line number, a function name, or * an address.

Usage:

    • clearClears all breakpoints in the source line of the selected stack frame when no parameters are taken.
    • clear <function>, clear <filename:function> Remove any breakpoints that are set at the entrance of the named function.
    • clear <linenum>, removes any breakpoints that are set in the code that specifies the clear <filename:linenum> line number of the specified file.
    • clear <address>Clears the breakpoint at the address of the specified program directive.

See official documentation.

Delete

Remove some breakpoints or auto-display expressions. The parameter is a space-delimited breakpoint number. To delete all breakpoints, do not add parameters.

Usage:delete [breakpoints] [list...]

See official documentation.

Tbreak

Sets a temporary breakpoint. The Parameter form is the same break .

Except that the breakpoint is temporary, the other is the same break , so it is deleted when hit.

See official documentation.

Watch

Sets the observer point for an expression.

Usage: watch [-l|-location] <expr> The Observer pauses program execution whenever the value of an expression changes.

If given -l or -location , it expr evaluates the value and observes the memory it points to. For example, watch *(int *)0x12345678 a 4-byte area will be observed at the specified address (assuming an int occupies 4 bytes).

See official documentation.

Step

Step through the program until you reach a different source line.

Usage: The step [N] parameter N means to execute N times (or for another reason until the program stops).

Warning: If you use a command in a function that controls compilation without debugging information, step execution continues until the control reaches the function that has the debug information. Again, it does not go into a function that compiles without debugging information.

To perform a function without debugging information, use the stepi command, as described later in this article.

See official documentation.

Reverse-step

The reverse step executes the program until it reaches the beginning of another source line.

Usage: The reverse-step [N] parameter N means to execute N times (or for another reason until the program stops).

See official documentation.

Next

Step through the program and execute the subroutine call.

Usage:next [N]

In contrast step , if the current source line calls a subroutine, the command does not go into the subroutine, but instead treats it as a single source line and continues execution.

See official documentation.

Reverse-next

The reverse step program executes the subroutine call.

Usage:reverse-next [N]

If the source line to execute calls the subroutine, the command does not enter the subroutine, and the call is treated as a directive.

The parameter N indicates execution N times (or for another reason until the program stops).

See official documentation.

Return

You can use return the command to cancel the execution of a function call. If you give an expression argument, its value is used as the return value of the function.

Usage: return <expression> takes expression the value as the function's return value and causes the function to return directly.

See official documentation.

Finish

Executes until the selected stack frame is returned.

Usage: finish when returned, the returned value is printed and placed in the value history.

See official documentation.

Until

Executes the source line until the program reaches the current line in the current stack frame (the break same parameters as the command). This command is used to pass a multiple loop to avoid stepping.

To use: until <location> or u <location> continue to run the program until the specified location is reached, or the current stack frame is returned.

See official documentation.

Continue

After the signal or breakpoint, continue to run the program being debugged.

Usage: continue [N] If you start from a breakpoint, you can use N a number as a parameter, which means that the ignore count of the breakpoint is set to N - 1 (so that the breakpoint does not break before nth arrival). If non-stop mode is enabled (using show non-stop view), only the thread continues, otherwise all threads in the program will continue.

See official documentation.

Print

Evaluates and prints the value of the expression EXP. The accessible variables are the lexical environment for the selected stack frame, and all variables that are scoped to the global or entire file.

Usage:

print [expr]Or print /f [expr] expr is an expression (in the source code language).
By default, expr the value is printed in a format that is appropriate for its data type; You can /f select a different format by specifying, where F is a letter in the specified format; see output format.

If omitted expr , GDB displays the last value again.

To print a struct variable in a format indented by one member of each line, use the command set print pretty on , and then use the command to cancel set print pretty off .

You can use commands to show print view all the printed settings.

See official documentation.

X

Check the memory.

Usage: x/nfu <addr> or x <addr> n , f and u are optional parameters that specify the memory to display and how to format it. addris an expression to begin displaying the address of the memory.

nThe number of repetitions (the default is 1), which specifies how many units (by u specified) the memory value to display.

fDisplay format (initial default is x ), display format is print(‘x‘,‘d‘,‘u‘,‘o‘,‘t‘,‘a‘,‘c‘,‘f‘,‘s‘) one of the formats used, plus i (machine instruction).

uThe unit size, which represents a single byte, represents a b h double byte, representing w four bytes, g representing eight bytes.

For example:

x/3uh 0x54320Indicates that 3 memory values are displayed in double-byte units starting from address 0x54320 in the form of unsigned decimal integers.

x/16xb 0x7f95b7d18870Represents the 16 memory values that are displayed in single-byte units, starting with the address 0x7f95b7d18870, in hexadecimal integer format.

See official documentation.

Display

The value of the expression EXP is printed each time the program pauses.

Usage: display <expr> , display/fmt <expr> or display/fmt <addr> fmt used to specify the display format. printjust like in the order /f .

For formatting i or s , or including unit size or number of units, add an expression to addr the memory address to check each time the program stops.

See official documentation.

Info display

Prints a list of expressions that are automatically displayed, each with an item number, but not its value.

Includes disabled expressions and expressions that cannot be displayed immediately (automatic variables that are not currently available).

Undisplay

Cancels the automatic display of some expressions when the program is paused. The parameter is the number of the expression (using the info display query number). All automatic display expressions are canceled without parameters.

delete displayHas the same effect as this command.

Disable Display

Disables the automatic display of certain expressions when a program is paused. Disabled display items are not automatically printed, but are not forgotten. It may be enabled again later.

The parameter is the number of the expression (using the info display query number). Disables all automatic display expressions without an argument.

Enable display

Enables some expressions to be displayed automatically when a program is paused.

The parameter is the number of the re-displayed expression (using the info display query number). With no parameters, all automatic display expressions are enabled.

Help

Print a list of commands.

You can use a short list of the category names of the commands without parameters help (abbreviated as h ).

Use help <class> you to get a list of the individual commands in the class. Use help <command> the show how to use the command.

See official documentation.

Attach

Attach to a process or file other than GDB. The command can take a process ID or a device file as an argument.

For the process ID, you must have permission to send a signal to the process, and must have the same valid UID as the debugger.

Usage: The attach <process-id> GDB first thing to do after scheduling a specified process is to pause the process.

attach run You can use the GDB command to inspect and modify a hooked process, whether it is a process that is hooked up through a command or a command-initiated process.

See official documentation.

Run

Start the program that is being debugged.

You can specify the parameters directly, or you can set args set (start the required) parameters.

For example: run arg1 arg2 ... equivalent to

set args arg1 arg2 ...run

Also allows > the use of, < or >> input and output redirection.

See official documentation.

BackTrace

Prints the overall stack frame information.

    • btPrints the overall stack frame information, one row per stack frame.
    • bt nSimilar to the above, but only the most inner layer of n stack frames is printed.
    • bt -nSimilar to the above, but only the outermost stack frames are printed.
    • bt full nSimilarly bt n , the value of the local variable is also printed.

whereand info stack (abbreviated info s ) is backtrace the alias. The call stack information resembles the following:

(gdb) where#0  vconn_stream_run (vconn=0x99e5e38) at lib/vconn-stream.c:232#1  0x080ed68a in vconn_run (vconn=0x99e5e38) at lib/vconn.c:276#2  0x080dc6c8 in rconn_run (rc=0x99dbbe0) at lib/rconn.c:513#3  0x08077b83 in ofconn_run (ofconn=0x99e8070, handle_openflow=0x805e274 

See official documentation.

PType

The definition for the type of printing.

Usage:ptype[/FLAGS] TYPE-NAME | EXPRESSION

Parameters can be typedef defined by the type name, or either or either struct STRUCT-TAG class CLASS-NAME union UNION-TAG enum ENUM-TAG .

Finds the name based on the lexical context of the selected stack frame.

A similar command is that the difference is that the whatis whatis data type defined is not expanded, typedef and PType is expanded, for example, as follows:

/* 类型声明与变量定义 */typedef double real_t;struct complex {    real_t real;    double imag;};typedef struct complex complex_t;complex_t var;real_t *real_pointer_var;

These two commands give the following output:

(gdb) whatis vartype = complex_t(gdb) ptype vartype = struct complex {    real_t real;    double imag;}(gdb) whatis complex_ttype = struct complex(gdb) whatis struct complextype = struct complex(gdb) ptype struct complextype = struct complex {    real_t real;    double imag;}(gdb) whatis real_pointer_vartype = real_t *(gdb) ptype real_pointer_vartype = double *

See official documentation.

Resources

Debugging with GDB

Common GDB Commands Chinese quick glance

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.