Evaluating and Displaying Data |
6 |
![]() |
The chapter is organized into the following sections:
Basic Concepts
In dbx you can perform two types of data checking:
To see other functions and files in which a variable name is defined, use the whereis command.
To evaluate a variable or expression:
print expression |
Evaluating Pascal Character Strings
To evaluate a Pascal character string in dbx, use the double quote ("") syntax to identify the string as a character string, as opposed to a character constant. This dbx convention also applies to passing parameters when calling a Pascal function.
print "abc" |
Printing C++
In C++ an object pointer has two types, its static type, what is defined in the source code, and its dynamic type,what an object was before any casts were made to it. dbx can sometimes provide you with the information about the dynamic type of an object. Evaluating Unnamed Arguments in C++ Programs
C++ allows you to define functions with unnamed arguments. For example:
void tester(int) main(int, char **) |
_ARG_%n_ |
where dbx assigns an integer to %n.
(dbx) whatis tester void tester(int _ARG_0_); (dbx) whatis main int main(int _ARG_1_, char **_ARG_2_); |
To evaluate (or display) an unnamed function argument,
(dbx) print _ARG_1_ _ARG_1_ = 4 |
Dereferencing Pointers
When you dereference a pointer, you ask for the contents of the container the pointer points to.
(dbx) print *t *t = { a = 4 } |
Monitoring Expressions
Monitoring the value of an expression each time the program stops is an effective technique for learning how and when a particular expression or variable changes. The display command instructs dbx to monitor one or more specified expressions or variables. Monitoring continues until you turn it off with the undisplay command.
display expression, ... |
display |
Turning Off Display (Undisplay)
dbx continues to display the value of a variable you are monitoring until you turn off display with the undisplay command. You can turn off the display of a specified expression or turn off the display of all expressions currently being monitored.
undisplay expression |
To turn off the display of all currently monitored variables:
undisplay 0 |
Assigning a Value to a Variable
To assign a value to a variable:
assign variable = expression |
Evaluating Arrays
You evaluate arrays the same way you evaluate other types of variables. For more information on working with arrays in Fortran, see the chapter, Debugging with Fortran later in this manual.
integer*4 arr(1:6, 4:7) |
print arr(2,4) |
Array Slicing for Arrays
The dbx print command allows you to evaluate part of a large array. Array evaluation includes:
Array-slicing syntax for C and C++, where:
print arr-exp [first-exp .. last-exp : stride-exp} |
The first, last, and stride expressions are optional expressions that should evaluate to integers.
(dbx) print arr[2..4] arr[2..4] = [2] = 2 [3] = 3 [4] = 4 (dbx) print arr[..2] arr[0..2] = [0] = 0 [1] = 1 [2] = 2 (dbx) print arr[2..6:2] arr[2..8:2] = [2] = 2 [4] = 4 [6] = 6 |
(dbx) print arr(exp1:exp2:exp3) |
exp1 |
start_of_slice |
exp2 |
end_of_slice |
exp3 |
length_of_stride (the number of elements skipped is exp3 - 1) |
For an n-dimensional slice, separate the definition of each slice with a comma:
(dbx) print arr(exp1:exp2:exp3, exp1:exp2:exp3,...) |
Slices
Here is an example of a two-dimensional, rectangular slice, with the default stride of 1 omitted:
print arr(201:203, 101:105) |
The third expression in the array slicing syntax, (exp3), specifies the length of the stride. The value of exp3 specifies the elements to print; the number of elements skipped is equal to exp3 -1. The default stride value is 1, meaning: evaluate all of the elements in the specified slices.
Here is the same array used in the previous example of a slice; this time the print command includes a stride of 2 for the slice in the second dimension.
print arr(201:203, 101:105:2) |
For a one-dimensional array:
print arr |
Prints entire array, default boundaries. |
print arr(:) |
Prints entire array, default boundaries and default stride of 1. |
print arr(::exp3) |
Prints the whole array with a stride of exp3. |
For a two-dimensional array the following command prints the entire array:
print arr |
To print every third element in the second dimension of a two-dimensional array:
print arr (:,::3) |
Command Reference
print
To print the value of the expression(s) expression:
print expression, ... |
In C++, to print the value of the expression expression including its inherited members:
print -r expression |
print -r expression |
In C++, to print the derived type of expression expression instead of the static type:
print -d [-r] expression |
In C++, to print the static type of expression expression when the dbxenv output_dynamic_type is on:
print -d [-r] expression |
To call the prettyprint function:
print -p expression |
To not call the prettyprint function when the dbxenv output_pretty_print is on:
print -p expression |
print -l expression |
To use format as the format for integers, strings, or floating point expressions:
print -f format expression |
To use the given format without printing the left hand side (the variable name or expression):
print -F format expression |
To signal the end of flag arguments. Useful if expression starts with a plus or minus:
print -- expression |