gdb调试工具简介
一、gdb参数:
Parameter Description
-b Set the line speed of the serial interface for remote debugging
-batch Run in batch mode
-c Specify the core dump file to analyze
-cd Specify the working directory
-d Specify a directory to search for source files
-e Specify the file to execute
-f Output filename and line numbers in standard format when debugging
-nx Do not execute commands from .gdbinit file
-q Quiet mode—don’t print introduction
-s Specify the filename for symbols
-se Specify the filename for both symbols and to execute
-tty Set device for standard input and output
-x Execute gdb commands from the specified file
二、gdb命令介绍:
Command Description
break Set a breakpoint in the source code to stop execution
watch Set a watchpoint to stop execution when a variable reaches a specific value
info Observe system elements, such as registers, the stack, and memory
x Examine memory location
print Display variable values
run Start execution of the program within the debugger
list List specified functions or lines
next Step to the next instruction in the program
step Step to the next instruction in the program
cont Continue executing the program from the stopped point
until Run the program until it reaches the specified source code line(or greater)
三、常用命令详细介绍:
1. print命令:
The print command can also be used to display individual register values. Including a modifier can
modify the output format of the print command:
? print/d to display the value in decimal
? print/t to display the value in binary
? print/x to display the value in hexadecimal
应用举例:(gdb) print/x $ebx
2. x命令:
The x command is used to display the values of specific memory locations. Similar to the print command,the x command output can be modified by a modifier. The format of the x command is
x/nyz
where n is the number of fields to display, y is the format of the output, and can be
? c for character
? d for decimal
? x for hexadecimal
and z is the size of the field to be displayed:
? b for byte
? h for 16-bit word (half-word)
? w for 32-bit word
应用举例:(gdb) x/42cb &output
一、gdb参数:
Parameter Description
-b Set the line speed of the serial interface for remote debugging
-batch Run in batch mode
-c Specify the core dump file to analyze
-cd Specify the working directory
-d Specify a directory to search for source files
-e Specify the file to execute
-f Output filename and line numbers in standard format when debugging
-nx Do not execute commands from .gdbinit file
-q Quiet mode—don’t print introduction
-s Specify the filename for symbols
-se Specify the filename for both symbols and to execute
-tty Set device for standard input and output
-x Execute gdb commands from the specified file
二、gdb命令介绍:
Command Description
break Set a breakpoint in the source code to stop execution
watch Set a watchpoint to stop execution when a variable reaches a specific value
info Observe system elements, such as registers, the stack, and memory
x Examine memory location
print Display variable values
run Start execution of the program within the debugger
list List specified functions or lines
next Step to the next instruction in the program
step Step to the next instruction in the program
cont Continue executing the program from the stopped point
until Run the program until it reaches the specified source code line(or greater)
三、常用命令详细介绍:
1. print命令:
The print command can also be used to display individual register values. Including a modifier can
modify the output format of the print command:
? print/d to display the value in decimal
? print/t to display the value in binary
? print/x to display the value in hexadecimal
应用举例:(gdb) print/x $ebx
2. x命令:
The x command is used to display the values of specific memory locations. Similar to the print command,the x command output can be modified by a modifier. The format of the x command is
x/nyz
where n is the number of fields to display, y is the format of the output, and can be
? c for character
? d for decimal
? x for hexadecimal
and z is the size of the field to be displayed:
? b for byte
? h for 16-bit word (half-word)
? w for 32-bit word
应用举例:(gdb) x/42cb &output