|
From: Oriol P. <aut...@gm...> - 2007-08-27 14:46:45
|
Hi, I'm going to explain a bit tricky situation, you are advised :-) I'm trying to integrate a Valgrind tool with another tool, MPItrace. This tool traces MPI calls in a trace file that you can view later with a program called Paraver and simulate it changing network parameters like bandwith, latency, etc with another tool called Dimemas. MPItrace allows you to call a client function from the instrumented program to insert events in the trace. I want to use this client function to pass information from a Valgrind tool to MPItrace at runtime. MPItrace is loaded dynamically with LD_PRELOAD mechanism, like Valgrind. The problem: if I try to compile Valgrind tool whith MPItrace library, for the linker to know where is the function address, the compiler fails to solve all libc symbols inside MPItrace library (because the -nodefaultlibs -nostartfiles flags in Valgrind compilation). So, I need to know at runtime (not at linking time) the function address in MPItrace without linking with MPItrace library. I tried to use dlopen, dlsym... but symbols are not found at linking time. I resolved partially the problem of the function address. I've loaded the both tools with the program. Inside the program I printed /proc/self/maps. With the mappings, now I know where libmpitrace.so is loaded (the base address). With nm program I found the offset of the function descriptor of the user function that I want to call from Valgrind, so I've defined a function pointer inside Valgrind tool and I've assigned to it the address (base + offset) hard coded. How I run it (from mpirun): LD_PRELOAD=/pathtompitrace/libmpitrace.so valgrind --tool=mytool program unset LD_PRELOAD When I call to the MPItrace client function from Valgrind tool, it surprisingly works correct with a few calls. When the number of calls is bigger, it fails. I investigated a bit and I found that the problem could be when MPItrace client function calls to a libc function. MPItrace have an event buffer that is flushed when is full. If this event buffer is not full, no libc functions are called from the client function. When the program ends, MPItrace flushes the buffer but from the program context. Is the intercepted PMPIFinalize function who calls flush (write or fwrite libc function) at the end. Could be a problem to call another preloaded library function (with this tricky method) from Valgrind? There is another way to know the address of the function of the preloaded library from Valgrind and call it? Thanks, Oriol |