On Friday 22 February 2008, Konstantin Serebryany wrote:
> Hi,
> 
> A question similar to the one discussed in 'thread-change callback' thread.
> How can I see context change events (i.e. when some thread enters or
> exits a function)?

Possibilities:

* At instrumentation time, check if a given instruction is the first of
a function according to debug information. This way, you get "enter function"
events, but not "exit" events. Instrumenting also every exit can get complex,
and you probably end with something similar to part of Callgrinds functionality.

* Extract the according functionality from Callgrind into a core module to
make it usable by every tool. There is a shadow callstack which is
resynchronized with the real one, making this approach quite robust. E.g.
it works with recursion, longjmps etc.
Drawback aside from not-existing module: slowdown because of an
instrumented callback at beginning of every basic block (could be optimized
to do the callback at end of BBs instead at beginning, and only when
changing the context).

* For specific functions, functions wrappers can be installed. This redirects
jumps to the given function to another one you provide in a shared lib which
will be loaded by valgrind dependent on the tool. Function exits work this
way, as the wrapper has its stack frame on the client stack. Callbacks into
your tool have to be done via client requests from the wrapper. AFAIK, this
has problems with recursion and longjmps.

In general, as VG is running machine code, and you probably define "context 
change"
as C/C++/... function changes, there is not always an exact relation among them,
and thus sometimes difficult whether a given execution should really trigger a
context change or not (e.g. with end recursion optimization).

Josef




-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Valgrind-developers mailing list
Valgrind-developers@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/valgrind-developers

Reply via email to