Start and stop:
GDB <gropram>//using GDB to debug the program executable, notice that GCC joins the-G parameter when it is being translated.
GDB <program> core//use GDB to debug a running program and core file at the same time, core is the file generated after core dump after the program terminates abnormally.
GDB <program> <PID>//If your program is a service program, you can specify the process ID at which the service program runs. GDB will automatically attach up and debug him. The program should be searched in the PATH environment variable.
Run or R//running the program (give command-line arguments here)
Kill//Stop program
Display code:
List==l
list<linenum>//Show programs around line LineNum
List<functiont>//show the source of functions named function
List//Displays the source program behind the current line
list-//Display the source program in front of the current line
Breakpoint:
break = = B
Break <function>//Set breakpoints at function functions entrance
Break <linenum>//stop at the specified line number
Break *addreee//stop at address location
Info Break[n] or info breakpoints[n]//view breakpoint information, n = breakpoint number
Delete[breakpoints][range]//Delete the specified breakpoint, breakpoints as the breakpoint number, or delete all breakpoints if you do not specify a breakpoint number. Range represents the range of breakpoint numbers (for example: 3-7). Its shorthand command is D.
Recovery program run and single-step debugging:
Step<count> or s<count>//single-step tracking, if there is a function call, he will enter the function. The prerequisite for entering a function is that this function is compiled with debug information. Very much like the VC and other tools in the step in. The following can be added to count or not, without adding a line to execute, plus the execution of the following count instructions, and then stop.
Next<count> or n<count>//is also single-step tracking, and if there is a function call, he will not enter the function. Very much like the VC and other tools in step over. The following can be added to count or not, without adding a line to execute, plus the execution of the following count instructions, and then stop.
Finish//Run the program until the current function finishes returning. and prints information such as the stack address and return value and parameter values when the function returns.
Until or u//When you are tired of stepping through a loop, this command can run the program until you exit the loop body.
Output:
print = = P
Print $eax//output%eax content in decimal
print/x $eax//hexadecimal output%eax content
print/t $eax//binary output%EAX content
Print 0x100//decimal representation of output 0x100
print/x 555//hexadecimal representation of output 555
print/x ($EBP + 8)//hexadecimal output%EBPD content plus 8
Print * (int*) 0xfff076b0//output at address 0xfff076b0
Print * (int*) ($EBP +8)//output is an integer at address%ebp+8
x/2w 0xfff0760b0//Check for double word starting from address 0xfff076b0
x/20b sum//Check the first 20 bytes of a function sum
P *[email protected]//All elements of an array, a is the name of the array, and Len is the number of elements in the array. If it is a static array, you can display the contents of all the data in the array directly with the print array name.
Check the code :
Disas//Disassembly current function
Disas sum//Disassembly function sum
Disas 0x8048397//Disassembly function located near address 0x8048397
Disas 0x8048394 0X80483A4//Disassembly code within the specified address range
Stack:
BackTrace or BT//view function stack
Multithreading:
Info Threads shows all threads currently available for debugging, each with a GDB-assigned ID, which is used when the thread is being manipulated. The previous ones are the threads currently being debugged.
The thread ID Toggles the currently debugged thread for the specified ID.
The thread apply all command lets all the debugged threads execute GDB command commands.
Resources:
1. "In-depth understanding of computer Systems" (second edition) mechanical industry press P175
GDB Common Commands