Chapter 14. Examining Data

Table of Contents
14.1. Expressions
14.2. Program Variables
14.3. Artificial Arrays
14.4. Output Formats
14.5. Examining Memory
14.6. Automatic Display
14.7. Print Settings
14.8. Value History
14.9. Convenience Variables
14.10. Registers

The usual way to examine data in your program is with the print command (abbreviated p), or its synonym inspect. It evaluates and prints the value of an expression of the language your program is written in (see Chapter 15.).

print exp, print /f exp

exp is an expression (in the source language). By default the value of exp is printed in a format appropriate to its data type; you can choose a different format by specifying /f, where f is a letter specifying the format; see Section 14.4..

print, print /f

If you omit exp, the debugger displays the last value again (from the value history; see Section 14.8.). This allows you to conveniently inspect the same value in an alternative format.

A more low-level way of examining data is with the x command. It examines data in memory at a specified address and prints it in a specified format. See Section 14.5.

If you are interested in information about types, or about how the fields of a struct or class are declared, use the ptype exp command rather than print. See Chapter 16: Symbols.

14.1. Expressions

print and many other the debugger commands accept an expression and compute its value. Any kind of constant, variable or operator defined by the programming language you are using is valid in an expression in the debugger. This includes conditional expressions, function calls, casts and string constants. It unfortunately does not include symbols defined by preprocessor #define commands.

The debugger now supports array constants in expressions input by the user. The syntax is {element, element...}. For example, you can now use the command print {1, 2, 3} to build up an array in memory that is malloc'd in the target program.

Because C is so widespread, most of the expressions shown in examples in this manual are in C. See Chapter 15, for information on how to use expressions in other languages.

In this section, we discuss operators that you can use in the debugger expressions regardless of your programming language.

Casts are supported in all languages, not just in C, because it is so useful to cast a number into a pointer in order to examine a structure at that address in memory.

The debugger supports these operators, in addition to those common to programming languages:

@

@ is a binary operator for treating parts of memory as arrays. See Section 14.3: Arrays, for more information.

::

:: allows you to specify a variable in terms of the file or function where it is defined. See Section 14.2.

{type} addr

Refers to an object of type type stored at address addr in memory. addr may be any expression whose value is an integer or pointer (but parentheses are required around binary operators, just as in a cast). This construct is allowed regardless of what kind of data is normally supposed to reside at addr.