Returning the Bounds: The vector_bounds Callback
The vector_bounds procedure returns the bounds of the object at an address. This returned value is a string in the syntax of the language in which the type was defined. TotalView calls this procedure whenever it is about to display a std::vector object. This example must use a callback since the vector type has dynamic bounds. If the type being mapped had static bounds, the routine could just return a string.
The vector_bounds procedure calculates the bounds by:
- Reading the base and end pointers.
- Subtracting one of these values from the other.
- Dividing this value by the element size.
Once again, this process is pretty simple because the vector_validate routine wrote much of this information into the _vector_type_info global variable.
proc vector_bounds {type_id address} {
global _vector_type_info
set vti $_vector_type_info($type_id)
set start [read_store [expr $address+[lindex $vti 1]]]
set finish [read_store [expr $address+[lindex $vti 2]]]
# Extract the length of the target type.
set type_size [TV::type get [lindex $vti 0] length]
set delta [expr ($finish-$start)/$type_size]
return "\[$delta\]"
}