The print Command

You can print the values of one or more expressions or all local variables. You can also use the print command to evaluate complex expressions involving typecasts, pointer dereferences, multiple variables, constants, and any legal operators allowed by the language of the program you are debugging:

DBX Mode

 

print_command

        : print [ expression ,... ]

        | print rescoped_expression

        | print printable-type

        | printb [ expression ,... ]

        | printd [ expression ,... ]

        | printo [ expression ,... ]

        | printx [ expression ,... ]

 

rescoped_expression

        : filename ` qual_symbol

        | ` qual_symbol

 

qual_symbol

        : expression

        | qual_symbol ` expression

 

For an array, the debugger prints every cell in the array if you do not specify a specific cell.

Use the $hexints, $decints, or $octints variables to select a radix for the output of the print command. If you do not want to change the radix permanently, use the printx, printd, printo, and printb commands to print expressions in hexadecimal, decimal, octal, or binary base format, respectively.

GDB Mode

 

print_command

        : print [/format specifier][expression]

 

format specifier

        : x | d | u | o | t | a | c | f

 

By default, GDB prints a value according to its data type. But user might want to print a number in hex, or a pointer in decimal. Or user might want to view data in memory at a certain address as a character string or as an instruction. In this case user should specify an output format.
To specify how to print a value already computed a user should print after the print command a slash and a format letter. The format letters supported are:

For an array, the debugger prints every cell in the array if you do not specify a specific cell.

Use the set output-radix xxx command to select a radix for the output of the print command, where xxx can be values: 8, 10 or 16.

Consider the following declarations in a C++ program:

DBX Mode

 

(idb) list 59:2

     59 const unsigned int biggestCount = 10;

     60 static Moon *biggestMoons[biggestCount];

GDB Mode

 

(idb) list 59,+2

59 const unsigned int biggestCount = 10;

60 static Moon *biggestMoons[biggestCount];

 

The following example uses the print command to display a non-string array:

DBX Mode

 

(idb) print biggestMoons

[0] = 0x806e5b0,[1] = 0x806e8c8,[2] = 0x806e608,[3] = 0x806e500,[4] = 0x806e348,[5] = 0x806e558,[6] = 0x806ec38,[7] = 0x806eb30,[8] = 0x806e870,[9] = 0x806eb88

GDB Mode

 

(idb) print biggestMoons

$4 = {0x806e5b0, 0x806e8c8, 0x806e608, 0x806e500, 0x806e348, 0x806e558, 0x806ec38, 0x806eb30, 0x806e870, 0x806eb88}

 

The following example shows how to print individual values of an array:

DBX Mode

 

(idb) print biggestMoons[3]

0x806e500

(idb) print *biggestMoons[3]

class Moon {

  _radius = 1815;

  _name = 0x805c5c0="Io";         // class Planet::HeavenlyBody

  _innerNeighbor = 0x0;           // class Planet::HeavenlyBody

  _outerNeighbor = 0x806e558;     // class Planet::HeavenlyBody

  _firstSatellite = 0x0;          // class Planet::HeavenlyBody

  _lastSatellite = 0x0;           // class Planet::HeavenlyBody

  _primary = 0x806e4a8;           // class Planet::Orbit

  _distance = 422;                // class Planet::Orbit

  _name = 0x806e530="Jupiter 1";  // class Planet::Orbit

}

GDB Mode

 

(idb) print biggestMoons[3]

$7 = (Moon *) 0x806e500

(idb) print *biggestMoons[3]

$8 = {<Planet> = {<HeavenlyBody> = {_name = 0x805c5c0 "Io", _innerNeighbor = 0x0, _outerNeighbor = 0x806e558, _firstSatellite = 0x0, _lastSatellite = 0x0}, <Orbit> = {_primary = 0x806e4a8, _distance = 422, _name = 0x806e530 "Jupiter 1"}}, _radius = 1815}