Common gdb commands

Source: Internet
Author: User
Local debugging with Parameters start gdb -- args./programarg1arg2arg3 after the main () breakpoint breakmain starts, set parameters run runarg1arg2arg3 cancel parameters start running setargsrun set parameters setargsarg1arg2arg3run analysis co... local debugging
Start with parameters
Gdb -- args./program arg1 arg2 arg3
 
Breakpoint at main ()
Break main
 
Set parameters for running after startup
Run arg1 arg2 arg3
 
Cancel the parameter and start running
Set args
Run
 
Set parameters
Set args arg1 arg2 arg3
Run
 
Analyze core files
Gdb./test./test. core
Gdb -- core =./test. core./test
Gdb./test 2640.
Gdb -- pid = 2640./test
 
 
Remote Debugging
Target machine
Gdbserver 127.0.0.1: 1234./test
Host:
Target remote 127.0.0.1: 1234
Break main
Run
 
Debug control commands:
Step: single step. parameter N indicates the number of single steps. generally, it can be used to step into the Subfunction call. (F11 of vc ++ and t of windbg)
Step of the stepi instruction set, which is generally called in the Assembly window.
 
Next is similar to a single step, except that the sub-function call is executed as an instruction in advance and is not followed in. (F10 of vc ++, p of windbg)
Next of the nexti instruction set, which is generally called in the Assembly window.
 
Until is executed until a row is larger than the current row number. Used as the out-of-step loop body. at this time, you can execute this out-of-step loop in the last row of the loop body.
 
Run finish to the position that the current stack is about to return. Returns the result after the current function is executed. (Shift + F11 of vc ++, pt, tt, wt of windbg)
 
Advance is pushed to a certain position. advance 27 indicates that it is pushed to 27 rows. (ctrl + F11 of vc ++, pa of windbg, "step to address ")
 
Jump jumps to a command for direct execution, and jump 27 jumps directly to line 27 to start execution. it is best to break a breakpoint somewhere after line 27. (R eip of windgb = 0x41000100)
 
 
Breakpoint command:
Break main function name breakpoint
Break test. c: 27-line breakpoint of the file
Break * 0x00000000004005f0 breakpoint at the assembly instruction address, with an asterisk in front
Hardware Data breakpoint
Awatch access breakpoint access watch; awatch I, when I is accessed, the program is disconnected. (Similar to windbg's ba breakpoint)
Watch writes a data breakpoint. watch I is disconnected when the value of I is modified.
Rwatch reads the breakpoint and is disconnected when the I value is read.
Hbreak hardware command breakpoint. hbreak x 0x0000000000400606 sets a hardware breakpoint at this address.
 
Conditional breakpoint:
When the 11-row breakpoint of the loop body is reached, it is disconnected only when the cycle counter is 20.
Www.2cto.com
(Gdb) break 11 if I = 20
Breakpoint 2 at 0x4005c9: file test. cxx, line 11.
(Gdb) info breaks
Undefined info command: "breaks". Try "help info ".
(Gdb) info break
Num Type Disp Enb Address What
1 breakpoint keep y 0x00000000004005c0 in foo () at test. cxx: 9
Breakpoint already hit 1 time
2 breakpoint keep y 0x00000000004005c9 in foo () at test. cxx: 11
Stop only if I = 20
(Gdb) c
Continuing.
0
 
Breakpoint 2, foo () at test. cxx: 11
11 printf ("% d \ n", I );
(Gdb) p I
$1 = 20
 
Data viewing command:
Print the value of the variable, print I, view the current value of the variable I.
X memory check, Examine the memory, x/nfs n = count of unit to examine. f = format, (x = hex; d = decimal, c = char); s = sizeof of unit
Display: when gdb obtains control, it prints the value of the variable, and displays I each time;
 
 
Stack operation commands:
Info stack: view the current thread stack and function call chain. Similar to bt;
Backtrace, stack backtracking
Info frame to view the information of the current function frame.
Move up to the upstream of the call chain to see who the caller is.
Move down to the downstream of the call chain to see who callee is.
Frame 2 moves to the second frame (count from callee-> caller)
Return: return from the selected stack to caller. similar to finish, return is a good function.
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.