Hi,
I'm interested in writing a new skin around valgrind that will enable comprehensive memory profiling.
I haven't found many profiling tools, and one I found (MemProf) crashes on our code.
Also, our tool has a lot of dependencies on IS tools. This is a problem since many people here use allocators, and rebuilding everything from scratch without them can be very unfun :).
My skin basically enables wrapping any function the user chooses. I then do 2 things:
1. Save the stack.
2. Analyze the sources to understand which class has just been allocated, if any.
This means I can also detail how much objects of each class exist.
For example, a user can write a config similar to this:
{
alloc_fun: allocator<T>::allocate(n);
alloced = sizeof(T)*n;
}
{
dealloc_fun: allocator<T>::allocate(n);
dealloced = sizeof(T)*n;
}
or use wildcards, etc.
This way we can analyze our memory usage without having horrible compilations.
It seems to me like this might be worth getting into the core too perhaps: the ability to override allocation functions, so instead of re-compiling everything, I'll just instruct valgrind to do this:
{
func: allocate(n)
replace_by: malloc(n)
}
Unless of course I want to debug my allocators.. :)
At any rate, I'm trying to read the values passed to the allocate(..) function by doing the following code:
// ebp address
Addr ebp = (Addr)(VG_(baseBlock)[VGOFF_(m_ebp)]);
Addr eip = ((Uint*)ebp)[1];
int first_var = ((Uint*)ebp)[2];
This code is similar to what happens in VG_(get_ExeContext2), so I cannot see why it doesn't work.
I do notice however that ebp, eip are correct, but first_var always equals one.
Can anyone direct me how to obtain its value? Perhaps it can be done during instrumentation (I'm currently doing it when my hook is called at the function entry)?
Thanks,
Yair