Let the error in the shape of the GDB tired tool Basic usage

xiaoxiao2021-04-10  380

When the program is wrong and generates a way to quickly locate the error function, the GDB program name Core file name (usually core, may also be Core.xxxx)

Debugging the key used

R Run running. The program has not run before running

cuntinue continues to run. Continue to run after the interrupt is running

Q exit

Kill terminates debugging procedures

H help help

Command completion function

STEP keeps functions

NEXT does not keep functions

B BreakPoint Sets breakpoints.

usage:

B function name interrupt this function

b File Name: The line number is interrupted in this file. If it is the current file, then the file name and: number can be omitted

See the current breakpoint number using info break. Forbidden DISABLE breakpoint. Delete the delete break point number.

l List lists the code line. One column 10 lines. Connection uses List will scroll the display. You can also keep up with the file name behind List: The line number Watch observes the value of a variable. The value of this variable prints a variable is printed at each interruption. Different from Watch is that Print only shows how to change a value here. When you undermate P, for example, you will use PB, this time you will see B Value, that is, the above = 15. You It can also be used to change a value, such as the next command PB = 100, this time you will find that the value of B turns 100: = 100.

Online transcription

Basic How to Use

Foreword

The error in the program code can be divided into number categories. In addition to the most likely fallen grammar errors, the compiler will tell you that most of the errors can be classified as execution errors. The function of GDB is to find an error when executing. If there is no error program, we can only add an instruction of the output variable value to the state of the program execution. With GDB unligerator, we can set up the execution of the program anywhere, and then check the variable values ​​and more variables at will, and execute the program line by line. The process of unligerated program is usually true:

1. Enter the error program and specify the executable.

2. Specify the directory where the program code is located.

3. Set the execution program after breakpoint.

4. After the program is interrupted, it can be (1) to see the program execution state; check the variable value or change the variable value (2) step-by-step execution, or the full-speed execution program to the next breakpoint or until the end of the program.

5. Leaving the error procedure.

The following will be divided into the following references:

1. Enter GDB and specify the executable

2. Specify the directory and view program code where the program code is located

3. Setting and cleaning of breakpoints

4. Full-speed and gradual implementation procedures

5. Viewing and changing the variable value

6. View the program execution status

7. Read more file information

Enter GDB and specify the executable:

1. Enter GDB and read the executable (filed to 'program'), ready for the error.

GDB Program

Specify the directory and view program code where the program code is located

1. Add directory DIR to the directory list (if your program code and executive file are placed in the same directory, you do not have to specify the directory where the program code is located.):

(GDB) Directory Dir

2. View the program code, the format is:

(GDB) List => Displays the program code of the five lines of the current executive program code; or display the program code from last LIST

(GDB) List function => Displays the program code before and after the program starts.

(GDB) List - => The last ten lines of the last display of the program code.

Setting and cleaning of breakpoints

1. Set the breakpoint (the instruction is BREAK, you can be ignored (b), and the format has:

(GDB) Break filename.c: 30 => Stop execution in the thirtieth row of FileName.c.

(GDB) BREAK FUNCTION => The execution of the interrupt program when entering the function. (GDB) Break filename.c: function => Sets the breakpoint at the function function in the program code file filename.c.

(GDB) BREAK => Sets the breakpoint in the next command.

(GDB) BREAK ... IF COND => It is only interrupted when Cond is established. Cond must be written in a C language.

2. Display information of each breakpoint.

(GDB) Info Break

3. Clear the breakpoint (command to clear), format with BREAK. E.g :

(GDB) Clear FileName.c: 30

4. Clear breakpoints, NUM is the breakpoint number displayed in Info Break.

(GDB) Delete Num

Full-speed and gradual implementation procedures

1. Execute the program from the beginning of the program until the breakpoint is encountered or the program is executed.

(GDB) RUN

2. After the program is interrupted, the full-speed execution program to the next breakpoint or the program ends (the Continue instruction can be short-written).

(GDB) Continue

3. Implement a row. If the call function is called, the program code is considered to be a row (NEXT instructions can be short-written).

(GDB) Next

4. Implement a row. If the call function, enter the functional line (STEP instructions can be short-written).

(GDB) STEP

5. Execute a line of programs. If the program is at the last line of the for / while / do loop loop, the first line of the loop has been executed after the end of the cycle is stopped (the Until instruction can be short-handed as u).

(GDB) Until

6. Execute the existing program to return to the previous layer.

(GDB) Finish

Viewing and changing variable values

1. Print describes the result of the description of the description (Print instructions can be short-handed as P). Such as

(GDB) Print A => Displays the contents of the A variable.

(GDB) Print SizeOf (a) => Displays the length of the A variable.

2. DISPLAY describes the narrative value when each breakpoint or one step is performed. Such as

(GDB) Display a

3. Change the variable value:

(GDB) Print (a = 10) => sets the value of the variable A to 10.

Viewing program execution status

1. The program is executed to this time, which is the program that passes the program (Backtrace instructions can be short-written), which is to view the function call stack.

(GDB) BackTrace

Read Core file information

1. Read the Program and Program.core files to view the program variable value and program process status when Core Dump.

GDB Program Core

Note: The 'Core' file is executed by the Program file, and the Core file name generated when Core DUMP is encountered. If you still need this CORE file, we recommend that you change the file name to Program.core. After entering the above command, you can read the status of the program core DUMP with the view variable value provided by GDB and the program execution status.

Give a little more

(I have just used GDB recently, it feels good, but when you are, it's better to add PrintF.

Make)

I am more direct debugging the program with GDB, not Core.

GDB executable file name (enter GDB environment)

Set AGS -? (Set the parameters, you can debug the program you want to debug)

In addition, all breakpoints can be set with BREAK FUNCTIONNAME and BREAK LINENUM to view the information of the current breakpoint. When clearing the breakpoint, if it is comparable to Break If it is a breakpoint set by functionName, only Clear functionname is used in LINENUM The set break can only be used to download GDB to www.sunfreeWare.com.

The above is a little experience in learning GDB in recent days. It is a place I have made mistakes to help with my GDB rookie with me.

If it is just the beginning, DDD graphics can be used.

In addition to breakpoints, you can use the Delete break point number to remove the breakpoint number can be obtained using INFO BREAK.

I also talk about my experience:

R (the parameters of the program run) can set the parameter shell running at the run, such as shell make, after completion of the RAM, you can run the last parameter, no need to knock the parameters

B file name: The number of line numbers is useful, 嘿嘿

INFO B looks fault information

Disable breakpoint suspend a breakpoint

Enable break point number starts a breakpoint

Delete (breakpoint) deletes a breakpoint, does not break the point, all delete

The x / 32uxb pointer indicates the 32-byte data pointed to the pointer in 16.

But I still will not debug it with Core.

转载请注明原文地址:https://www.9cbs.com/read-133364.html

New Post(0)