Totalview® User Guide : PART II Debugging Tools and Tasks : Chapter 9 Examining and Editing Data and Program Elements : Changing a Variable’s Data Type : Type-Casting Examples
Type-Casting Examples
This section contains three type-casting examples:
Displaying Declared Arrays
Displaying Allocated Arrays
Displaying the argv Array
Displaying Declared Arrays
TotalView displays arrays the same way it displays local and global variables. In the Stack Frame or Source Pane, dive on the declared array. A Variable Window displays the elements of the array.
CLI: dprint array-name
Displaying Allocated Arrays
The C Language uses pointers for dynamically allocated arrays; for example:
int *p = malloc(sizeof(int) * 20);
Since TotalView doesn’t know that p actually points to an array of integers, you need to do several things to display the array:
1. Dive on the variable p of type int*.
2. Change its type to int[20]*.
3. Dive on the value of the pointer to display the array of 20 integers.
Displaying the argv Array
Typically, argv is the second argument passed to main(), and it is either a char **argv or char *argv[ ]. Suppose argv points to an array of three pointers to character strings. Here is how you can edit its type to display an array of three pointers:
1. Select the type string for argv.
CLI: dprint argv
2. Edit the type string by using the field editor commands. Change it to:
$string*[3]*
CLI: dprint {($string*[3]*)argv}
3. To display the array, dive on the value field for argv.
Figure 144 – Editing the argv Argument
Changing the Address of Variables
You can edit the address of a variable in a Variable Window by editing the value shown in the Address field. When you edit this address, the Variable Window shows the contents of the new location.
You can also enter an address expression such as 0x10b8 - 0x80 in this area.
Displaying C++ Types
RELATED TOPICS 
 
STL variable display
Changing the data type of a variable
A variable’s scope
Viewing Classes
TotalView displays C++ classes and accepts class as a keyword. When you debug C++, TotalView also accepts the unadorned name of a class, struct, union, or enum in the type field. TotalView displays nested classes that use inheritance, showing derivation by indentation.
NOTE >> Some C++ compilers do not write accessibility information. In these cases, TotalView cannot display this information.
For example, Figure 145 displays an object of a class c.
Figure 145 – Displaying C++ Classes That Use Inheritance
Its definition is as follows:
class b {
char * b_val;
public:
b() {b_val = “b value“;}
};
class d : virtual public b {
char * d_val;
public:
d() {d_val = “d value“;}
};
class e {
char * e_val;
public:
e() {e_val = “e value“;}
};
class c : public d, public e {
char * c_val;
public:
c() {c_val = “c value“;}
};
TotalView tries to display the correct data when you change the type of a Variable Window while moving up or down the derivation hierarchy. Unfortunately, many compilers do not contain the information that TotalView needs so you might need to cast your class.
 
RELATED TOPICS 
 
More on using C++ with TotalView