Returning the Address: The vector_address Callback
The vector_address procedure computes the address of an array element. TotalView calls it for each array element being displayed.
TotalView supplies the following three parameters when it calls your procedure:
- The type ID.
- The array's starting address.
- The index for which the address is required.
The callback returns an addressing expression that allows TotalView to generate the address of a vector element. In this example, the vector_address function returns an addressing expression. Here is an example:
{{addc 4} indirect {addc 4}}
Note: See Addressing Expressions for information on the operators and opcodes that you can use.
While an address procedure could return an absolute address, it should instead return an addressing expression. Returning a procedure is better because TotalView can then recalculate the address when you dive through an element in a Variable Window. If you had returned an absolute address, TotalView would use the address in the new Variable Window, even if the vector has changed.
proc vector_address {type_id address indices} {
global _vector_type_info
set vti $_vector_type_info($type_id)
set type_size [TV::type get [lindex $vti 0] length]
set offset [expr $type_size*$indices]
# We don't bother to worry about adding zero because
# TotalView will remove any unnecessary additions.
set result "{{addc [lindex $vti 1]} indirect {addc $offset}}"
return $result
}