GDB Debugging Pristine

Source: Internet
Author: User
Tags stack trace

List of listed documents

list/l

List part of the source code that generated the execution file

Lists the source code
(GDB) list line1 between line1 and Line2 lines, line2

//output from the last call to the list command 10 lines of program code
(GDB) List

//output nth Line 10 line of program code
(GDB) list n

//output function function 10 lines of program code
(GDB) List function

II. Implementation Procedures

Run/r

Run the program you want to debug, after which you can follow any parameters that are sent to the program, including standard input and standard output specifiers (< and >) and Shell wildcard characters (*,. , [,]).

If you use the Run command with no parameters, GDB will use the parameters you gave to the previous run command again, which is useful.

Set args

command, you can modify the parameters sent to the program, and use the

Show args

command, you can view a list of its default parameters.

(GDB) Set args–b–x
(GDB) show args

third, display data

print/p

To view the value of a variable

You can use the Print command to check the values of individual variables.
(GDB) print p (p is the variable name)

Print is a powerful command of GDB that can be used to display any valid expression in the language being debugged. In addition to the variables contained in your program, an expression can include the following:

Calls to functions in programs
(GDB) print find_entry (1, 0)

//data structures and other complex objects
(gdb) print *table_start
$8={e=reference= ' \ location=0x0,next=0x0}

//value Historical component
(GDB) print (is a history variable, you can directly reference the value in the future)

Whatis

To view the type of a variable

The Whatis command can display the type of a variable
(gdb) Whatis p
type = int *

Iv. setting and clearing breakpoints

Break/b
Can be used to set breakpoints in a debugged program, which has the following four forms

Stops the break Line-number///causes the program to stop the break before it is executed just before

the specified function is performed

function-name

// If the condition (condition) is true, the program stops the break when it reaches the specified line or function
line-or-function if condition
 
//Set breakpoint breaks at the entrance of the specified routine
Routine-name
If the program is made up of a number of original files, you can set breakpoints in each of the original files instead of setting breakpoints in the current original file, as follows:
(GDB) Break Filename:line-number

(gdb) Break Filename:function-name
Break if

To set a conditional breakpoint, you can take advantage of the break if command as follows:

(GDB) Break line-or-function if expr

(gdb) Break-if testsize==100
Clean Number

Clears all breakpoints on a line of code in the original file

Note: number is the line of a line of code for the original file

V. The management of breakpoints

1. Display the current GDB breakpoint information

Info Break

2. Delete Deletes a specified breakpoint

Delete Breakpoint

This command will delete the breakpoint
(GDB) with number 1 (breakpoint 1

/////If no number parameter is taken, all breakpoints
(GDB) Delete Breakpoint
3. Prohibit, allow to use a breakpoint

Disable Breakpoint 1

Enable Breakpoint 1

This command disables, allows breakpoint 1, and the (ENB) field of the breakpoint information changes to N, y

Vi. Single Step Implementation

next/n

Stepping without entry

Step

Stepping into

Finish

If you have entered a function and want to exit the function and return it to its calling function, you can use the command finish

until

End Current Loop

Seven, the function of the call

Call name

Calling and executing a function

(GDB) Call Gen_and_sork (1234,1,0)
(gdb) call printf ("ABCD")
$1=4
Finish finishes executing the current function, displaying its return value (if any)

Eight, the original document search

Search Text

This command displays the next line that contains the text string in the current file.

Reverse-search Text

The command can display the previous line containing text.

Summary: Commonly used GDB commands

BACKTRACE/BT Displays the current position in the program and the stack trace that represents how to get to the current location (synonym: where)

breakpoint/b Set a breakpoint in the program

CD changes current working directory

Clear Deletes the breakpoint just stopped

Lists the commands to be executed when commands breakpoint.

continue continues execution from breakpoint

Delete Deletes a breakpoint or monitoring point, or it can be used with other commands

displays variables and expressions when the display program stops

down to move the stack frame so that another function becomes the current function

frame To select the frames of the next continue command

Info Displays various information about the program

Jump Another point in the source program to start running

Kill Exception terminates program running under GDB control

List Lists the contents of the original file corresponding to the program being executed

Next executes a function in its entirety by executing the next line of the source program

Print shows the value of a variable or an expression

pwd Display current working directory

ptype Displays the contents of a data structure (such as a struct or C + + Class)

quit Exit GDB

Reverse-search The normal expression in the source file in reverse search

Run executes the program

Search searches for regular expressions in source files

Set Variable assign values to variables

signal sends a signal to a running process

Step executes the next source line and, if necessary, goes to the next function

undisplay The display command's reverse command, do not show an expression

until end of current loop

up to move the stack frame to make another function the current function

Watch set up a monitoring point (i.e. data breakpoint) in the program

whatis Display variable or function type

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.