GDB Debug Command

Source: Internet
Author: User
Tags terminates

1. View Source code:

list [function name] [number of rows]

2. Suspend the program

(1) Set breakpoints:

A, break + [source code line number] [source code function name] [memory address]

B, break ... if condition ... Can be any one of these parameters, condition is a condition. For example, you can set the break in the loop body ... if i = 100来 Set the number of cycles

(2) Observe the breakpoint:

A, watch + [variable] [expression] stops the program when the variable or expression value changes.

b, Rwatch + [variable] [expression] when the variable or expression is read, stop the program.

C, Awatch + [variable] [expression] stops the program when a variable or expression is read or written.

(3) Set the snap point:

Catch + Event stops the program when the event occurs.

The event can be something as follows:

A, throw an exception thrown by C + +. (Throw is keyword)

b, catch an exception caught by C + +. (Catch as keyword)

C, when exec calls the system to call exec. (exec is the keyword, currently this feature is only useful under HP-UX)

D, fork calls when the system calls fork. (Fork is the keyword, currently this feature is only useful under HP-UX)

E, vfork call the system when calling Vfork. (Vfork is the keyword, currently this feature is only useful under HP-UX)

F, load, or load when loading a shared library (dynamic link library). (load is a keyword that currently works only on HP-UX)

g, unload, or unload when uninstalling a shared library (dynamic link library). (Unload is the keyword, currently this feature is only useful under HP-UX)

(4) Capture signal:

Handle + [ARGU] + signals

Signals:

is a signal defined by Linux/unix, SIGINT represents the interrupt character signal, which is the signal of CTRL + C, Sigbus indicates the signal of hardware failure, SIGCHLD indicates the child process status change signal, Sigkill indicates the signal to terminate the program operation, and so on.

Argu

Nostop when the program being debugged receives a signal, GDB does not stop the program from running, but it will give you a message telling you to receive the signal.

Stop when the program being debugged receives a signal, GDB will stop your program.

Print when the program being debugged receives a signal, GDB shows a message.

Noprint when the program being debugged receives a signal, GDB will not tell you the message that you received the signal.

Pass or Noignore GDB does not process the signal when the program being debugged receives a signal. This means that GDB will give this signal to the debug program to handle.

NoPass or ignore when the program being debugged receives a signal, GDB does not let the debugger process the signal.

(5) Thread Interrupt:

break [Linespec] thread [Threadno] [If ...]

Linespec the line number of the source code where the breakpoint is set. For example, Test.c:12 indicates that the file sets a breakpoint for line 12th in TEST.C.

The ID of the THREADNO thread. is a gdb assignment, and you can view the thread information for a running program by entering info threads.

If ... Set the break condition.

3. View information:

(1) View data:

Print variable View variables

Print *[email protected] View Array (array is a pointer to arrays, Len requires data length)

You can set the output format by adding parameters:
/x Displays the variable in hexadecimal format.
/d Displays the variable in decimal format.
/u displays unsigned integers in hexadecimal format.
/o Displays the variable in octal format.
/t displays the variable in binary format.
/A displays the variable in hexadecimal format.
/C Displays the variable by character format.
/f Displays variables in floating-point number format.

(2) View memory:

examine/n f U + memory address (pointer variable)
n indicates memory length shown
F represents the output format (see above)
U represents the number of bytes made (b single-byte; h DWORD; w four bytes; g eight bytes; default is four bytes)

Such as:
X/10CW Pfilepath (Pfilepath is a string pointer with a pointer of 4 bytes)
X is shorthand for the examine command.

(3) View stack information:
BackTrace [-n][n]
n is the stack information that prints only the N-tier on top of the stack.
-n means that only the stack information of the n layer on the bottom of the stack is printed.
Does not add parameters, indicating that all stack information is printed.

Basic GDB command:
---------------------------------------------------------------------
Command Shorthand function
---------------------------------------------------------------------
File loads the executable files that you want to debug.
Kill K Terminates the program being debugged.
List L lists part of the source code that generated the execution file.
Next N executes a line of source code but does not enter the inside of the function.
Step S executes a line of source code and goes inside the function.
Continue c continue with the program until the next interrupt or the end of the program.
Run R executes the program that is currently being debugged.
Quit Q terminates gdb.
Watch allows you to monitor the value of a variable regardless of when it is changed.
Catch to set the snap point.
Thread T to view the threads information for the currently running program.
Break B Sets a breakpoint in the code, which causes the program to be suspended when it is executed here.
Make enables you to regenerate executables without having to exit gdb.
The shell enables you to execute a UNIX shell command without leaving GDB.
Print p Prints the contents of the data.
Examine x print memory contents.
BackTrace BT View all the information for the function call stack.

GDB Debug Command

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.