Reputation: 61
I'm writing a valgrind tool which as part of it's instrumentation, replaces certain function calls using the function replacement mechanism valgrind supplies. The replacement function immediately finesses the arguments and calls into the tool code using the client request mechanism. The thing is, once I'm in the tool I want to know the location where the replacement function was called, so I can use it to accurately report results to the user. But I can't find a reliable, cross-platform way to do this. So far I've gotten it working on Linux by instrumenting every AbiHint to store it's address in tool memory if it appears to be in a user code location, and then picking up that address once we're in the tool code called by the replacement function. But from what I've read, I won't be able to rely on these AbiHints cross-platform, and it seems like a hacky, brittle solution anyway. Is there a good way to do this?
Upvotes: 2
Views: 40
Reputation: 3807
A tool reports errors to user use the functions available in pub_tool_errormgr.h
These will report the guest stack trace, which should give the location at which
the replaced function was called.
You can also if needed directly get a guest stack trace using functions from pub_tool_execontext.h
.
Upvotes: 2