Gdb debugger command learning summary notes STL printer

Source: Internet
Author: User
Tags bitset gdb debugger

Http://blog.csdn.net/sunlylorn/article/details/6788768

 

GDB user-defined commands are very useful. You can use user-defined commands to directly operate the data in the container and conveniently view the data in the STL container.

This link dbinit_stl_views is a custom command written by Dan C Marinescu to view STL containers (you can modify it if it is not suitable for your STL version ). Add it to your. gdbinit to conveniently view the STL container. It provides methods for viewing objects such as vector, list, MAP, multimap, set, Multiset, deque, stack, queue, priority_queue, bitset, string, and widestring!

1. Download http://www.yolinux.com/TUTORIALS/src/dbinit_stl_views-1.03.txt 2. # CatDbinit_stl_views-1.03.txt>~ /. Gdbinit 3. If it is in GDB, run the following command: (GDB) Source ~ /. Gdbinit 4. For exampleCode:

 

Some common built-in commands

Data Type GDB command
STD: vector pvector stl_variable
STD :: list plist stl_variable T
STD: Map pmap stl_variable
STD: multimap pmap stl_variable
STD:: Set pset stl_variable T
STD: Multiset pset stl_variable
STD: deque pdequeue stl_variable
STD :: stack pstack stl_variable
STD: queue pqueue stl_variable
STD: priority_queue ppqueue stl_variable
STD :: bitset TD> pbitset stl_variable
STD: String pstring stl_variable
STD: widestring pwstring stl_variable

 

Http://wiki.ubuntu.org.cn/index.php? Title = % E7 % 94% a8gdb % E8 % B0 % 83% E8 % af % 95% E7 % A8 % 8B % E5 % Ba % 8f & variant = ZH-Hans

Http://blog.csdn.net/haoel/article/details/2879http://coolshell.cn/articles/3643.html

 

Http://hily.me/blog/2006/05/gdb-learning-note/

Linux contains a very useful debugging tool, GDB (GNU debuger), which can be used to debug C and C ++.ProgramIt is no less powerful than many graphical interface debugging tools in windows.

Like all common debugging tools, GDB provides the following functions:
# Value of the variable in the Monitoring Program
# Set breakpoints in a program
# One-Step Program Execution

Before using GDB, you must first load the executable file. for debugging, the file must contain debugging information, therefore, when compiling with GCC or CC, you need to use the-G parameter to open the debugging options of the program.

When Debugging starts, you must first load the program to be debugged. You can use either of the following methods:
* After GDB is started, run the following command:
File executable file path
* Load the program at GDB startup:
GDB executable file path

After the program is loaded, the next step is to set the breakpoint and add the variables to be monitored. Next, we will introduce the commands commonly used in this process one by one:
* List : Display the code in the program. Common formats include:
List
Output 10 lines of program code after the last LIST command is called.
List-
Output 10 lines of program code starting from the last call of the list command.
List n
Output 10 lines of program code near line N.
List Function
Output 10 lines of program code before and after the function.
*Forward/search : Search for the program line that matches a string from the current row. Format:
Forward/search string
The searched row number is saved in the $ _ variable and can be viewed using the Print $ _ command.
* Reverse-search : Opposite to forward/search, search for strings forward. The same format is used.
* Break : Set a breakpoint in the program. When the program runs on the specified line, the execution is paused. Format:
The line number of the breakpoint to be set for the break.
* Tbreak : Sets a temporary breakpoint, which takes effect only once after the setting. Format:
The line number of the temporary breakpoint to be set for tbreak
* Clear : Opposite to break, clear is used to clear breakpoints. Format:
The row number of the breakpoint to be cleared.
* Run : Start the program. The program that is being debugged can be passed with parameters after run.
* Awatch : Add watch. The format is as follows:
Awatch variables or expressions
When the expression value changes or the expression value is read, the program stops running.
* Watch : Similar to awatch, it is used to set observation points, but the program stops running only when the expression value changes. Usage format:
Watch variable or expression
Note that both awatch and watch must set the observation point during the running of the program. You can only set it after running run.
* Commands : Set to execute specific commands when a breakpoint is encountered. The format is as follows:
Commands
Set the command to be executed when the last breakpoint is encountered
Commands n
Set the command to be executed when the breakpoint number N is encountered
Note that commands is followed by the breakpoint number, rather than the line number of the breakpoint.
After entering the command, you can enter the command to be executed after the breakpoint is met. Each command line contains one command. after entering the last command, enter end to end the input.
* Delete : Clear the breakpoint or automatically displayed expression. Format:
Delete breakpoint number
* Disable : Invalidates the specified breakpoint. Format:
Disable Checkpoint number list
Use spaces to separate breakpoint numbers.
* Enable : Unlike disable, resumable Recovery fails. Format:
Enable breakpoint number list
* Ignore : Ignore breakpoints. Format:
Number of ignore checkpoint numbers ignored
* Condition : Set the breakpoint to take effect under certain conditions. Format:
Condition breakpoint number condition expression
* Cont/continue : Enables the program to continue running after the breakpoint is paused. Format:
Cont
Skip the current breakpoint to continue running.
Cont n
Skip n breakpoints and continue running.
When N is 1, cont 1 is Cont.
* Jump : Let the program jump to the specified line to start debugging. Format:
Jump row number
* Next : Continue to execute the statement, but skip the call of the subroutine. Format:
Next
Execute a statement
Next n
Execute n statements
* Nexti : The statement is executed in one step. However, unlike next, it traces the subprogram, but does not print the statements in the subprogram. The same format is used.
* Step : Similar to next, but it will track the interior of the subprogram and display the execution of the subprogram. The same format is used.
* Stepi : Similar to step, but more detailed than step, is the combination of nexti and step. The same format is used.
* Whatis : Displays the Data Type of a variable or expression. Format:
Whatis variable or expression
* Ptype : Similar to whatis, it is used to display data types, but it can also display types defined by typedef. Format:
Ptype variable or expression
* Set : Set the value of the variable in the program. Format:
Set variable = expression
Set variable: = expression
* Display : Add the expression for displaying the value. Format:
Display expression
* Info display : Displays the expressions of all values to be displayed.
*Delete display/undisplay : Delete the expression of the value to be displayed. Format:
Delete display/undisplay expression no.
* Disable display : A value to be expressed is not displayed for the moment. Format:
Disable display expression no.
* Enable display : Opposite to disable display, use an expression to restore display. Format:
Enable display expression number
* Print : Print the value of a variable or expression. Format:
Print variable or expression
The expression has two special meanings: $ and $.
$ Indicates the first sequence number of a given sequence number. $ indicates the first two sequence numbers of a given sequence number.
If $ and $ are not followed by a number, the given sequence number is the current sequence number.
* Backtrace : Prints a specified number of stack frames ). Format:
Number of Backtrace stack Frames
* Frame : Print the stack frame. Format:
Frame Number of the frame Stack
* Info Frame : Displays the details of the current stack frame.
* Select-Frame : Select stack frame. After the stack frame is selected, you can use info frame to display stack frame information. Format:
Select-frame stack frame number
* Kill : End debugging of the current program.
* Quit : Exit GDB.

To view all gdb commands, enter the tab twice under GDB and run "Help Command" to view the detailed usage format of command.
This article only briefly summarizes the usage of some common commands during GDB debugging. For more information about GDB, see the official documentation of GDB:

http://www.gnu.org/software/gdb/documentation/

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.