|
From: Anuta M. <man...@gm...> - 2016-02-22 07:37:24
|
Hi Philippe, Thank you for taking the time to respond to a newbie like me! The tool I am trying to create is to perform race detection on sequential tests that call various API's of C libraries. Once I can pinpoint the data races in the libraries I will use the existing sequential tests to write multithreaded tests that when run on a dynamic race detector will expose the data races in the C libraries. I have read all the documentation you mentioned. I've created a simple tool that tracks thread creation using the VG_(track_pre_thread_ll_create) function. My next objective is to track mutex locks and unlocks. As far as I can see, Helgrind does this using some wrapper functions it defines inside hg_intercepts.c I have been trying to write my own wrapper functions to track pthread events (I have read this <http://valgrind.org/docs/manual/manual-core-adv.html#manual-core-adv.wrapping> to get a basic idea), but I am getting stuck and have some questions. To wrap the pthread_create() function, this is the wrapper I wrote: *int I_WRAP_SONAME_FNNAME_ZZ(**libpthreadZdsoZd0,* *pthreadZucreateZAZa)(pthread_t *thread,const pthread_attr_t *attr,void* (*start),void *arg){ int ret; OrigFn fn; VALGRIND_GET_ORIG_FN(fn); CALL_FN_W_WWWW(ret,fn,thread,* *attr,start,arg); printf("\nPthread create just happened\n"); return ret;}* When I try to run it, this is the error I'm getting: valgrind: m_redir.c:627 (vgPlain_redir_notify_new_DebugInfo): Assertion 'is_plausible_guest_addr(sym_avmas.main)' failed. Segmentation fault (core dumped) What am I missing? On Thu, Feb 18, 2016 at 3:26 AM, Philippe Waroquiers < phi...@sk...> wrote: > 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 > > > > -- Anuta Mukherjee, Dept of Computer Science Engg, CEG, Anna University |