Use GDB debugging procedures (six)

zhaozj2021-02-08  332

7. Set display options

There are more options on the display in GDB. Here I will only exist of most common options.

Set Print Address Set Print Address ON Open Address Output, when the program displays the function information, GDB will display the parameter address of the function. The system defaults to open, such as: (GDB) F # 0 set_quotes (lq = 0x34c78 "<<", RQ = 0x34c88 ">>") AT INPUT.C: 530 530 IF (LQUOTE! = Def_lquote)

Set Print Address Off Parameter Address Display, such as: (GDB) Set Print Addr Off (GDB) F # 0 set_quotes (lq = "<<", RQ = ">>") AT INPUT.C: 530 530 IF (LQUOTE! = Def_lquote)

Show Print Address View whether the current address display option is open. Set Print Array Set Print Array ON ON ON Display, when the array is turned, each element occupies a row, if not open, each element is separated by a comma. This option is closed by default. The two commands related to it are as follows, I will not say more. Set Print Array Off Show Print Array

Set print elements> This option is primarily set to set an array. If your array is too big, you can specify a to specify the maximum length of the data display, when arriving When GDB is no longer displayed down. If set to 0, it is not limited. Show Print Elements View the option information for Print Elements. Set print null-stop If this option is opened, the end is displayed when the string is displayed. This option defaults to OFF. Set Print Pretty On If you open the PrintF pretty this option, it is more beautiful when the GDB displays the structure. Such as:

$ 1 = {Next = 0x0, Flags = {SWEET = 1, Sour = 1}, meat = 0x54 "pork"}

Set Print Pretty Off Close the Printf Pretty this option, the GDB displays the structure as follows: $ 1 = {Next = 0x0, Flags = {SWEET = 1, SOUR = 1}, meat = 0x54 "Pork"} show print Pretty View GDB How to display structures. Set print sevenbit-strings Settings the character display, press "/ nn" format display, if the string or character data is displayed / NNN, such as "/ 065". Show Print Sevenbit-Strings View the character display switch is open. Set Print Union Set whether or not the consortium within the display structure is explicit. For example, the following data structure: typedef enum {Tree, Bug} Species; typedef enum {Big_tree, Acorn, Seedling} Tree_forms; typedef enum {Caterpillar, Cocoon, Butterfly} Bug_forms; struct thing {Species it; union {Tree_forms tree; Bug_forms bug ,} Form;}; struct think = {Tree, {acorn}}; When this switch is turned on, after executing the P foo command, it will be displayed as follows: $ 1 = {it = Tree, form = {Tree = acorn, bug = Cocoon}} When the P foo command is executed, the P foo command is executed as follows: $ 1 = {it = Tree, form = {...}}

Show Print Union Display Methods SET Print Object In C , if an object pointer points to its partial class, if you open this option, GDB will automatically display the output according to the rule called by the virtual method, if closed If this option, GDB does not have a virtual function table. This option is OFF by default. Show Print Object View the setting of the object option. Set print static-members This option indicates whether the content in a C object is to display the static data member. The default is ON. Show Print Static-Members View Static Data Members Options Settings. Set Print VTBL When this option is turned on, GDB will display the virtual function table with a comparison format. Its default is closed. Show Print VTBL View options for virtual functions display format. 8. History When you use the GDB's Print to view the data running data, you will be recorded by GDB. GDB will make every print command for your way in a way in $ 1, $ 2, $ 3 ...... Thus, you can use this number to access the previous expressions, such as $ 1. The benefits of this feature are that if you have previously entered a relatively long expression, if you want to view the value of this expression, you can use history to access, save your duplicate input. Nine, GDB environment variables

You can define your own variables in the GDB debug environment to save running data in some debuggers. To define a variable of a GDB is simple. Use the GDB's set command. GDB's environment variables are the same as UNIX, is also a head. For example: SET $ foo = * Object_ptr When using environment variables, GDB will create this variable when you first use, and in later use, it assigns it directly. Environment variables have no type, you can define any type to the environment variable. Includes structures and arrays. Show convenience This command views all the environment variables currently set. This is a relatively powerful function, environmental variable, and program variable interaction, which will make program debugging and convenient. For example: SET $ I = 0 Print Bar [$ I ] -> Contents, when you don't have to, Print Bar [0] -> Contents, Print Bar [1] -> Contents Enter commands. After entering such a command, only the knock back, repeat the previous statement, the environment variable will be automatically accumulated, thereby completing the function of outputting one by one. Ten, check the register

To view the value of the register, it is easy, you can use the following command: Info Registers to view the register. (In addition to floating point registers) Info all-registers to view all registers. (Including floating point registers) Info registers View the situation of the specified register. The program is placed in the register, such as the currently running instruction address (IP), the current stack address (SP) of the program, and the like. You can also use the print command to access the register, just add a $ symbol before the register name. Such as: p $ EIP. <- Previous Next->

(All rights reserved, please indicate the author and the source when reproduced)

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

New Post(0)