GDB Common commands Reference Manual

Source: Internet
Author: User
Tags gdb debugger

Original article link

GDB Common commands Reference Manual

  • GDB command line parameters
  • GDB command
  • GDB operation prompt
  • GDB Manual
  • Related Links

 

 

 

GDB command line parameters

Start GDB:

    • GDBExecutable
    • GDB-eExecutable-CCore-File
    • GDBExecutable-PIDProcess-ID 
      (Use commands'Ps-auxw'View the PID of the process)
Option Description
-- Help
-H
LIST command line parameters.
-- Exec =File
-EFile
Specifies the executable file.
-- Core =Core-File
-CCore-File
Specify the core file.
-- Command =File
-XFile
Read the gdb command from the specified file.
-- Directory =Directory
-DDirectory
Add the specified directory to the source file search path.
-- Cd =Directory Run GDB using the specified directory as the current path.
-- NX
-N
Do not run the command in the. gdbinit file. By default, commands in this file will be executed after all command line parameters are processed.
-- Batch Run GDB in non-interactive mode. Read commands from files, so you need-X.
-- Symbols =File
-SFile
Read the symbol table from a specified file.
-Write Allows you to write executable files and core files.
-- Quiet
-Q
Do not print the description or copyright information.
-- Tty =Device SpecifyDeviceFor runningProgram.
-- Pid =Process-ID
-PProcess-ID
ID of the process to attach.

 

GDB command

Command Used in GDB:

 

Command Description
Help Lists GDB help information.
HelpTopic List the gdb commands in related topics.
HelpCommand Lists command descriptions.
AproposSearch-word Search for related topics.
Info ARGs
I ARGs
List the command line parameters of the running program.
Info breakpoints List breakpoints.
Info break List breakpoint numbers.
Info breakBreakpoint-Number Lists information about a specified breakpoint.
Info watchpoints Lists observation points.
Info registers List the registers used.
Info threads List the current threads.
Info set Lists the options that can be set.
Break and watch  
BreakFuntion
BreakLine-Number
Set a breakpoint at the specified function or row number.
Break +Offset
Break-Offset
Set a breakpoint in the front or back of the current position.
BreakFile: func InFileFileFunc.
BreakFile: nth InFileTheNthSet a breakpoint for the row.
Break *Address Set a breakpoint at the specified address. GenerallySource code.
BreakLine-NumberIfCondition If the conditions are met, set the breakpoint at the specified position.
BreakLineThreadThread-Number Interrupt in the specified thread. UseInfo threadsDisplays the thread number.
Tbreak Set a temporary breakpoint. After one interruption, the breakpoint will be deleted.
WatchCondition Set an observation point when the conditions are met.
Clear
ClearFunc
ClearNth
Clear FunctionFunc.
ClearNthThe breakpoint at the row.
Delete
D
Delete all breakpoints or observation points.
DeleteBreakpoint-Number
DeleteRange
Delete the specified breakpoint, observation point.
DisableBreakpoint-number-or-Range
EnableBreakpoint-number-or-Range
If you do not delete a breakpoint, set it to invalid or valid.
Example:
Display breakpoint:Info break
Invalid settings:Disable 2-9
Enable onceBreakpoint-Number Set the specified breakpoint to be valid, and set it to invalid when the breakpoint is reached.
Enable delBreakpoint-Number Set the specified breakpoint to be valid. Delete it when it reaches the breakpoint.
Finish The execution continues until the function ends.
Line execution  
Step
S
StepNumber-of-steps-to-perform
Enter the next lineCodeWill enter the function.
Next
N
NextNumber
Execute the next line of code. But does not enter the function.
Until
UntilLine-Number
Continue to run until the specified row number, function, address, and so on are reached.
Return
ReturnExpression
The selected stack frame is displayed ). If a parameter is specified later, the value of the expression is returned.
Stepi
Si
Nexti
Ni
Execute the next Assembly/CPU command.
Info Signals
Info handle
HandleSignal-nameOption
When receiving a signal, perform the following actions: nostop (do not stop the program), stop (Stop program execution), print (display signal), noprint (do not show ), pass/noignore (allow the program to process signals), nopass/ignore (do not allow the program to accept signals)
Where Displays the current row number and function.
Program Stack  
Backtrace
BT
BTInner-function-nesting-Depth
BT-Outer-function-nesting-Depth
Displays the trace of the current stack, the current function.
Backtrace full Print the values of all local variables.
FrameNumber
FNumber
Select the stack frame.
UpNumber
DownNumber
Move the specified number of stack frames up or down.
Info FrameADDR Description of the selected stack frame.
Info ARGs
Info all-Reg
Info locals
Info catch
Displays the stack frame parameters, local variables, and exception handling functions.All-RegThe floating-point registers are also listed.
Source code  
List
L
ListLine-Number
ListFunction
List-
ListStart #, end #
ListFilename: Function
List the source code.
Set listsizeCount
Show listsize
SetListCommand to print the number of lines in the source code.
DirectoryDirectory-name
DirDirectory-name
Show Directories
Add the specified directory before the source code path.
Directory Clear the source code directory if no parameters are followed.
Examine Variables  
PrintVariable
PVariable
PFile: Variable
P'File'::Variable
Print the value of the specified variable.
P *Array-VaR@Length PrintArrary-VaRBeforeLength.
P/xVaR Print Integer Variables in hexadecimal notationVaR.
P/dVaR Set VariablesVaRPrint as a signed integer.
P/uVaR Set VariablesVaRPrint as an unsigned integer.
P/oVaR Set VariablesVaRPrint it as an octal number.
P/TVaR
X/BAddress
X/B &Variable
Print in integer binary formatVaRVariable value.
P/CVariable When the character is printed.
P/FVariable Print variables in floating point formatVaR.
P/Variable Print the hexadecimal address.
X/WAddress
X/4B &Variable
Print the specified address in a group of four bytes.
CallExpression SimilarPrint, But do not print void.
DisassemADDR Deassembles the commands in a specified address.
Controlling GDB  
SetGDB-Option Value Set GDB options.
Set print array on
Set print array off
Show print Array
Print the array in readable form. The default value is off.
Set print array-indexes on
Set print array-indexes off
Show print array-Indexes
Print the subscript of the array element. The default value is off.
Set print pretty on
Set print pretty off
Show print pretty
Format and print the output of the C struct.
Set print Union on
Set print Union off
Show print Union
Print the Consortium in C. The default value is on.
Set print demangle on
Set print demangle off
Show print demangle
Control the printing of names in C ++. The default value is on.
Working files  
Info files
Info share
Lists the current files and shared libraries.
FileFile SetFileAs a program for debugging. If no parameter is specified, it is discarded.
CoreFile SetFileAs a core file. If no parameter is specified, it is discarded.
ExecFile SetFileAs the execution program. If no parameter is specified, it is discarded.
SymbolFile SlaveFile. If no parameter is specified, it is discarded.
LoadFile Dynamic LinkFileFile and read its symbol table.
PathDirectory DirectoryDirectoryAdd to the path for searching executable files and symbolic files.
Start and Stop  
Run
R
RunCommand-line-arguments
Run <Infile>OUTFILE
You can also execute programs from the beginning and redirect them.
Continue
C
Continue until the next breakpoint or observation point.
ContinueNumber Continue execution, but the current breakpoint is ignoredNumberTimes. It is useful when a breakpoint is in a loop.
Kill Stop program execution.
Quit
Q
Exit the gdb debugger.

 


GDB operation prompt

 

    • When compiling an executable file, you must add the "-G" option to GCC so that it can add additional debugging information to the generated executable file.
    • Do not use Compiler optimization options, such as "-o" and "-O2 ". Because the compiler will change the program process for optimization, It is not conducive to debugging.
    • You can run the following shell command in GDB:ShellCommand
    • The GDB command can be supplemented by the tab key. Press the tab twice to see all possible matches.
    • For exampleInfo breInBreEquivalentBreakpoints.
    • Operations of GDB in Emacs:
Emacs buttons action
M-x GDB switch to GDB mode.
C-H m display the gdb mode Introduction Information.
M-S it is equivalent to the step command in GDB.
M-n it is equivalent to the next command in GDB.
M-I it is equivalent to the stepi command in GDB.
C-F it is equivalent to the finish command in GDB.
M-C it is equivalent to the continue command in GDB.
m-u it is equivalent to the up command in GDB.
M-D it is equivalent to the down command in GDB.

 


GDB manuals:

 

    • GDB-GNU Debugger
    • LD-the GNU linker
    • Gcc/g ++-GNU Project C and C ++ Compiler
Related Article

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.