How TotalView Intercepts Memory Data
TotalView intercepts calls made by your program to heap library functions that allocate and deallocate memory by using the malloc() and free() functions and related functions such as calloc() and realloc(). The technique it uses is called interposition. TotalView’s interposition technology uses an agent routine to intercept calls to functions in this library. This agent routine is sometimes called the Heap Interposition Agent (HIA).
You can use TotalView with any allocation and deallocation library that uses such functions as malloc() and free(). Typically, this library is called the malloc library. For example, the C++ new operator is almost always built on top of the malloc() function. If it is,TotalView can track it. Similarly, if your Fortran implementation use malloc() and free() functions to manage memory,TotalView can track Fortran heap memory use.
You can interpose the agent in two ways:
![*](p4-bullet.jpg)
TotalView can preload the agent. Preloading means that the loader places an object before the object listed in the application’s loader table.
When a routine references a symbol in another routine, the linker searches for that symbol’s definition. Because the agent’s routine is the first object in the table, your program invokes the agent’s routine instead of the routine that was initially linked in.
On Linux and Sun, TotalView sets an environment variable that contains the pathname of the agent’s shared library. For more information, see
Using env to Insert the Agent.
If your program attaches to an already running program, you must explicitly link this other program with the agent.
After the agent intercepts a call, it calls the original function. This means that you can use TotalView with most memory allocators.
Figure 143 shows how the agent interacts with your program and the heap library.
Because TotalView uses interposition, memory debugging can be considered non-invasive. That is,TotalView doesn’t rewrite or augment your program’s code, and you don’t have to do anything in your program. Because the agent lives in the user space, it will add a small amount of overhead to the program’s behavior, but it should not be significant.