China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --

Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!

中国DOS联盟论坛
The time now is 2026-06-24 11:26
中国DOS联盟论坛 » 网络日志(Blog) » Assembly language View 29,340 Replies 75
Floor 31 Posted 2016-06-26 19:11 ·  中国 海南 海口 电信
超级版主
★★★★
Credits 3,673
Posts 2,020
Joined 2016-02-01 00:00
10-year member
UID 181465
Gender Male
Status Offline
gdb Free Edit Add Term
B Add Term?
Belongs to the category: Software
Debugging tool under UNIX and UNIX-like. Perhaps, everyone may prefer the graphical interface way, like the debugging of IDEs such as VC, BCB, etc., but if you are doing software under the UNIX platform, you will find that the advantage of the GDB debugging tool compared with VC, z is that it has functions such as repairing network breakpoints and restoring links. The graphical debugger of BCB has more powerful functions. The so-called "each has its own strengths and weaknesses" is the reason.

Entry Encyclopedia Wonderful Information at a Glance
Basic Information
Foreign Name
GDB
Publishing Organization
GNU Open Source Organization

Type
Powerful program debugging tool under UNIX
Function
Dynamically change the execution environment of your program, etc.
Table of Contents
1 Function
2 Version Release
3 File List
4 Executing Program
5 Displaying Data
6 Breakpoints
7 Breakpoint Management
8 Variable Inspection and Assignment
9 Step-by-Step Execution
10 Function Call
11 Machine Language Tool
12 Signals
13 GDB Usage
Folding Edit Section Function

Generally speaking, GDB mainly helps you complete the following four aspects of functions:

1. Start your program, and you can run the program as you want according to your custom requirements.

2. Let the program being debugged stop at the set breakpoint. (The breakpoint can be a conditional expression)

3. When the program is stopped, you can check what is happening in your program at this time.

4. You can change your program, correct the impact caused by a bug, and then test other bugs.

Folding Edit Section Version Release

On December 29, 2009, the program debugging tool GDB 7.0.1 was released. The new version corrected some serious stack overflow bugs of the 7.0 version, which may cause the GDB debugging process to be interrupted. It corrected the problems that could not be compiled under FreeBSD and IRⅨ systems, added support for Thumb2 debugging, and other small bug fixes.

On March 19, 2010, GDB 7.1 was released,

Detailed improvement content: support for multi-program debugging;

Support for debugging position-independent executables (Pie);

New targets (including an emulator): Xilinx MicroBlaze and Renesas RX;

Enhanced Python support;

Extended C++ support;

New tracepoint function;

Improvement of process recording;

Remote protocol extension.

On September 6, 2010, GDB 7.2 was released,

Improvement records of this version:

1. Support for D language

2. C++ improvement, support for argument-dependent lookup ADL, static constant class members and improved support for user-defined operators

3. Improvement of Python debugging, including breakpoints, symbols, symbol tables, program spaces, threads, etc., which can be operated through the command line

4. Furthermore, enhancements were made for tracepoints and for GDBserver. Improvements were made in tracepoints and GDBserver.

5. Support for ARM Symbian platform

6. Other improvements and bug fixes.

On August 26, 2011, GDB 7.3a was released,

Changes:

1. GDB can understand the name of the thread.

2. The commands "thread name" (specify a name) and "thread find " (match name, target ID, or additional information) are added.

3. Python script support is greatly enhanced.

4. In C++ support, exception handling is improved, and template parameters are placed in the scope when debugging an instance.

5. Core dump of thread debugging under GNU/Linux becomes possible.

6. Initial support for the C language version of OpenCL.

7. Many other improvements.

Folding Edit Section File List

List

(gdb) list line1,line2

View the source code

list lineNum Display the source code before and after lineNum

list + List the code lines after the current line

list - List the code lines before the current line

list function

set listsize count

Set the number of lines to display code

show listsize

Display the number of lines to print code

list first,last

Display the source code lines from first to last

Folding Edit Section Executing Program

To run the program to be debugged, you can use the run command. After it, you can follow any parameters sent to the program, including standard input and output specifiers (<; and>;) and shell wildcards (*,?, ) and so on. If you use the run command without parameters, gdb will use the parameters you gave to the previous run command again, which is very useful. You can use the set args command to modify the parameters sent to the program, and use the show args command to view the list of its default parameters.

(gdb) file a.out //Load the executable program file to be debugged.

(gdb) set args –b –x

(gdb) show args

(gdb) r //Execute the program

The backtrace command provides backtracking function for the stack.

The Backtrace command generates a list containing all valid processes starting from the most recent process and the parameters of calling these processes.

Folding Edit Section Displaying Data

You can use the print command to check the values of each variable.

(gdb) print p (p is the variable name)

print is a very powerful command of gdb. With it, you can display any valid expression in the debugged language. The expression can not only contain variables in your program but also include the following:

Call to a function in the program

(gdb) print find_entry(1,0)

Data structures and other complex objects

(gdb) print *table_start

={e=reference='\000',location=0x0,next=0x0}

Historical components of values

(gdb) print (For the historical record variable, the value that can be directly referenced later)

Artificial array

The artificial array provides a method to display the content of a memory block (array section or dynamically allocated storage area). Early debugging programs did not have a good way to convert any pointer into an array. Just like treating parameters, let's look at 10 integers after the variable h. The syntax of a dynamic array is as follows:

base@length

Therefore, to display 10 elements after h, you can use h@10:

(gdb) print h@10

=(-1,345,23,-234,0,0,0,98,345,10)

The whatis command can display the type of a certain variable

(gdb) whatis p

type = int *

Folding Edit Section Breakpoints

The break command (can be abbreviated as b) can be used to set breakpoints in the program being debugged. This command has the following four forms:

break line-number Make the program stop just before executing the given line.

break function-name Make the program stop just before entering the specified function.

break line-or-function if condition If condition (condition) is true, the program stops when reaching the specified line or function.

break routine-name Set a breakpoint at the entry of the specified routine

If the program is composed of many source files, you can set breakpoints in each source file instead of in the current source file. The method is as follows:

(gdb) break filename:line-number

(gdb) break filename:function-name

To set a conditional breakpoint, you can use the break if command, as follows:

(gdb) break line-or-function if expr

Example:

(gdb) break 46 if testsize==100

Continue running from the breakpoint: continue command

Folding Edit Section Breakpoint Management

Folding 1. Display the current breakpoint information of gdb:

(gdb) info break

It will display all breakpoint information in the following form:

Num Type Disp Enb Address What

1 breakpoint keep y 0x000028bc in init_random at qsort2.c:155

2 breakpoint keep y 0x0000291c in init_organ at qsort2.c:168

Delete a specified breakpoint:

(gdb) delete breakpoint 1

This command will delete the breakpoint with number 1. If there is no number parameter, all breakpoints will be deleted

(gdb) delete breakpoint

Disable a certain breakpoint

(gdb) disable breakpoint 1

This command will disable breakpoint 1, and the (Enb) field of the breakpoint information will become n

Enable a certain breakpoint

(gdb) enable breakpoint 1

This command will enable breakpoint 1, and the (Enb) field of the breakpoint information will become y

Clear all breakpoints on a certain code line in the source file

(gdb) clear number

Note: number is the line number of a certain code line in the source file

Folding 2. Set conditional breakpoints

Example:

gdb can set conditional breakpoints, that is, the breakpoint will only be triggered when the condition is met. The command is "break … if cond". Take the above program as an example:

It can be seen that the set breakpoint is only triggered when the value of i is 101. At this time, the value of sum is printed as 5050.

Folding Edit Section Variable Inspection and Assignment

whatis: Identify the type of array or variable

ptype: More powerful than whatis, it can provide the definition of a structure

set variable = value: Assign a value to a variable

print variable = value or p variable = value: In addition to displaying the value of a variable, it can also be used for assignment

Folding Edit Section Step-by-Step Execution

next Step-by-step execution without entering

step Step-by-step execution with entering. If you have entered a certain function and want to exit the function and return to its calling function, you can use the command finish

Folding Edit Section Function Call

call name Call and execute a function

(gdb) call gen_and_sork(1234,1,0)

(gdb) call printf("abcd")

=4

finish Finish executing the current function and display its return value (if any)

Folding Edit Section Machine Language Tool

There is a group of dedicated gdb variables that can be used to check and modify the general-purpose registers of the computer. gdb provides the standard names of the 4 registers actually used in each current computer:

$pc : Program counter

$fp : Frame pointer (current stack frame)

$sp : Stack pointer

$ps : Processor status

Folding Edit Section Signals

gdb can usually catch most of the signals sent to it. By catching the signals, it can decide what to do with the running process. For example, pressing CTRL-C sends an interrupt signal to gdb, which usually terminates gdb. But you may not want to interrupt gdb. The real purpose is to interrupt the program that gdb is running. Therefore, gdb will catch the signal and stop the program it is running, so that some debugging operations can be performed.

The Handle command can control the processing of signals. It has two parameters, one is the signal name, and the other is what to do when the signal is received. Several possible parameters are:

nostop When receiving the signal, do not send it to the program, and do not stop the program.

stop When receiving the signal, stop the execution of the program, so as to allow program debugging; display a message indicating that the signal has been received (except for the forbidden message)

print When receiving the signal, display a message

noprint When receiving the signal, do not display a message (and implicitly do not stop the program from running)

pass Send the signal to the program, so as to allow your program to handle it, stop running or take other actions.

nopass Stop the program from running, but do not send the signal to the program.

For example, suppose you intercept the SIGPIPE signal to prevent the program being debugged from receiving the signal, and whenever the signal arrives, require the program to stop and notify you. To complete this task, you can use the following command:

(gdb) handle SIGPIPE stop print

Please note that the signal names of UNⅨ are always in uppercase letters! You can use the signal number instead of the signal name. If your program is to perform any signal processing operations, you need to be able to test its signal processing program. For this, you need a convenient way to send signals to the program. This is the task of the signal command. The parameter of this command is a number or a name, such as SIGINT. Suppose your program has set a dedicated SIGINT (keyboard input, or CTRL-C; signal 2) signal processing program to take some cleaning actions. To test this signal processing program, you can set a breakpoint and use the following command:

(gdb) signal 2

continuing with signal SIGINT⑵

The program continues to execute, but immediately transmits the signal, and the processing program starts to run.

Folding Edit Section GDB Usage

GDB is a powerful command-line debugging tool. Everyone knows that the power of the command line lies in that it can form an execution sequence and form a script. The software under UNⅨ is all command-line, which provides great convenience for program development. The advantage of command-line software is that they can be integrated together very easily. Using a few simple commands of existing tools, a very powerful function can be made.

Therefore, the software under UNⅨ can be more organically combined than the software under Windows, each giving full play to its own strengths, and combining into a more powerful function. And the graphical software under Windows is basically self-contained and cannot call each other, which is not conducive to the mutual integration of various software. It is not to compare with Windows here. The so-called "each has its own strengths and weaknesses", and the graphical tool sometimes has places worse than the command line.

[ Last edited by zzz19760225 on 2017-11-13 at 14:07 ]
1<词>,2,3/段\,4{节},5(章)。
Floor 32 Posted 2016-06-26 19:14 ·  中国 海南 海口 电信
超级版主
★★★★
Credits 3,673
Posts 2,020
Joined 2016-02-01 00:00
10-year member
UID 181465
Gender Male
Status Offline
1<词>,2,3/段\,4{节},5(章)。
Floor 33 Posted 2016-06-26 19:17 ·  中国 海南 海口 电信
超级版主
★★★★
Credits 3,673
Posts 2,020
Joined 2016-02-01 00:00
10-year member
UID 181465
Gender Male
Status Offline
1<词>,2,3/段\,4{节},5(章)。
Floor 34 Posted 2016-06-26 19:19 ·  中国 海南 海口 电信
超级版主
★★★★
Credits 3,673
Posts 2,020
Joined 2016-02-01 00:00
10-year member
UID 181465
Gender Male
Status Offline
1<词>,2,3/段\,4{节},5(章)。
Floor 35 Posted 2016-06-26 19:26 ·  中国 海南 海口 电信
超级版主
★★★★
Credits 3,673
Posts 2,020
Joined 2016-02-01 00:00
10-year member
UID 181465
Gender Male
Status Offline
1<词>,2,3/段\,4{节},5(章)。
Floor 36 Posted 2016-06-26 19:27 ·  中国 海南 海口 电信
超级版主
★★★★
Credits 3,673
Posts 2,020
Joined 2016-02-01 00:00
10-year member
UID 181465
Gender Male
Status Offline
1<词>,2,3/段\,4{节},5(章)。
Floor 37 Posted 2016-06-26 19:28 ·  中国 海南 海口 电信
超级版主
★★★★
Credits 3,673
Posts 2,020
Joined 2016-02-01 00:00
10-year member
UID 181465
Gender Male
Status Offline
1<词>,2,3/段\,4{节},5(章)。
Floor 38 Posted 2016-06-26 19:33 ·  中国 海南 海口 电信
超级版主
★★★★
Credits 3,673
Posts 2,020
Joined 2016-02-01 00:00
10-year member
UID 181465
Gender Male
Status Offline
1<词>,2,3/段\,4{节},5(章)。
Floor 39 Posted 2016-06-26 19:34 ·  中国 海南 海口 电信
超级版主
★★★★
Credits 3,673
Posts 2,020
Joined 2016-02-01 00:00
10-year member
UID 181465
Gender Male
Status Offline
1<词>,2,3/段\,4{节},5(章)。
Floor 40 Posted 2016-06-26 19:35 ·  中国 海南 海口 电信
超级版主
★★★★
Credits 3,673
Posts 2,020
Joined 2016-02-01 00:00
10-year member
UID 181465
Gender Male
Status Offline
1<词>,2,3/段\,4{节},5(章)。
Floor 41 Posted 2016-06-26 19:36 ·  中国 海南 海口 电信
超级版主
★★★★
Credits 3,673
Posts 2,020
Joined 2016-02-01 00:00
10-year member
UID 181465
Gender Male
Status Offline
1<词>,2,3/段\,4{节},5(章)。
Floor 42 Posted 2016-06-26 19:37 ·  中国 海南 海口 电信
超级版主
★★★★
Credits 3,673
Posts 2,020
Joined 2016-02-01 00:00
10-year member
UID 181465
Gender Male
Status Offline
1<词>,2,3/段\,4{节},5(章)。
Floor 43 Posted 2016-06-26 19:38 ·  中国 海南 海口 电信
超级版主
★★★★
Credits 3,673
Posts 2,020
Joined 2016-02-01 00:00
10-year member
UID 181465
Gender Male
Status Offline
1<词>,2,3/段\,4{节},5(章)。
Floor 44 Posted 2016-06-26 19:40 ·  中国 海南 海口 电信
超级版主
★★★★
Credits 3,673
Posts 2,020
Joined 2016-02-01 00:00
10-year member
UID 181465
Gender Male
Status Offline
1<词>,2,3/段\,4{节},5(章)。
Floor 45 Posted 2016-06-26 19:40 ·  中国 海南 海口 电信
超级版主
★★★★
Credits 3,673
Posts 2,020
Joined 2016-02-01 00:00
10-year member
UID 181465
Gender Male
Status Offline
1<词>,2,3/段\,4{节},5(章)。
Forum Jump: