|
From: Philippe W. <phi...@sk...> - 2016-02-17 21:53:57
|
On Tue, 2016-02-16 at 14:57 +0530, Anuta Mukherjee wrote:
> Hi,
> I am very new to Valgrind and am trying to write a tool where I need
> to track:
> - Variable declarations (global and local variables)
> - Reads/writes to these variables
> - Locks and unlocks of mutexes
> How do I track reads/writes to variables declared by my test program?
> How do I track pthread_mutex_{lock,unlock}?
>
It would be good to indicate what documentation and/or code
you have already read and explain more in details what you have
tried/not understood/...
But ok, let's assume you have not read much :).
If you want to write a tool, you must have a good idea of
how valgrind works.
So, read the 'introduction' papers/doc such as:
http://www.valgrind.org/docs/valgrind2007.pdf
and
http://www.valgrind.org/docs/manual/tech-docs.html
Look at the code of an easy tool (typically, lackey).
Maybe others valgrind developers might give additional relevant pointers
if I missed some interesting introductory documentation ?
After that, the best is to read the source.
E.g. scan the interfaces that valgrind provides to tools
(these are include/pub_tool_*.h).
Read the implementation of a tool that does somewhat
similar things to what you want to do.
For your objective above, helgrind is a good example:
* it intercepts (a.o.) lock/unlocks
* and it tracks read/write to the memory.
That being said, valgrind tools are working on binary code : tools do
not track variable declarations and/or read/write to variables.
They (can) track read/write to memory, or stack pointer modifications
(e.g. the sp changes that are done at entry of a function).
There is no 'high level interface' to track variables declaration or rw.
valgrind provides some support to translate an address
into e.g. global and/or stack variables.
See e.g. pub_tool_addrinfo.h
It would be interesting also to describe the kind of tool you
want to write.
After that, once you have read doc and code, if you have more
specific questions, do not hesitate to ask, but you must first
read and understand the bulk by yourself, otherwise you will
have to send hundreds of mails with questions :).
Hoping this helps ...
Philippe
|