|
From: Anuta M. <man...@gm...> - 2016-02-16 09:27:51
|
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}?*
Thanks in advance,
--
Anuta Mukherjee,
|
|
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
|
|
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 |
|
From: Anuta M. <man...@gm...> - 2016-02-22 09:22:35
|
To elaborate more on my implementation, I have written the wrapper inside a file called tr_wrapper.c and added this my Makefile: (as is seen in Helgrind's makefile) My tool is called tracker. *#----------------------------------------------------------------------------# vgpreload_tracker-<platform>.so#----------------------------------------------------------------------------noinst_PROGRAMS += vgpreload_tracker-@VGCONF_ARCH_PRI@-@VGCONF_OS@.soif VGCONF_HAVE_PLATFORM_SECnoinst_PROGRAMS += vgpreload_tracker-@VGCONF_ARCH_SEC@-@VGCONF_OS@.soendifif VGCONF_OS_IS_DARWINnoinst_DSYMS = $(noinst_PROGRAMS)endifVGPRELOAD_TRACKER_SOURCES_COMMON = tr_intercepts.cvgpreload_tracker_@VGCONF_ARCH_PRI@_@VGCONF_OS@_so_SOURCES = \ $(VGPRELOAD_TRACKER_SOURCES_COMMON)vgpreload_tracker_@VGCONF_ARCH_PRI@_@VGCONF_OS@_so_CPPFLAGS = \ $(AM_CPPFLAGS_@VGCONF_PLATFORM_PRI_CAPS@)vgpreload_tracker_@VGCONF_ARCH_PRI@_@VGCONF_OS@_so_CFLAGS = \ $(AM_CFLAGS_PSO_@VGCONF_PLATFORM_PRI_CAPS@)vgpreload_tracker_@VGCONF_ARCH_PRI@_@VGCONF_OS@_so_DEPENDENCIES = \ $(LIBREPLACEMALLOC_@VGCONF_PLATFORM_PRI_CAPS@)vgpreload_tracker_@VGCONF_ARCH_PRI@_@VGCONF_OS@_so_LDFLAGS = \ $(PRELOAD_LDFLAGS_@VGCONF_PLATFORM_PRI_CAPS@) \ $(LIBREPLACEMALLOC_LDFLAGS_@VGCONF_PLATFORM_PRI_CAPS@)if VGCONF_HAVE_PLATFORM_SECvgpreload_tracker_@VGCONF_ARCH_SEC@_@VGCONF_OS@_so_SOURCES = \ $(VGPRELOAD_TRACKER_SOURCES_COMMON)vgpreload_tracker_@VGCONF_ARCH_SEC@_@VGCONF_OS@_so_CPPFLAGS = \ $(AM_CPPFLAGS_@VGCONF_PLATFORM_SEC_CAPS@)vgpreload_tracker_@VGCONF_ARCH_SEC@_@VGCONF_OS@_so_CFLAGS = \ $(AM_CFLAGS_PSO_@VGCONF_PLATFORM_SEC_CAPS@)vgpreload_tracker_@VGCONF_ARCH_SEC@_@VGCONF_OS@_so_DEPENDENCIES = \ $(LIBREPLACEMALLOC_@VGCONF_PLATFORM_SEC_CAPS@)vgpreload_tracker_@VGCONF_ARCH_SEC@_@VGCONF_OS@_so_LDFLAGS = \ $(PRELOAD_LDFLAGS_@VGCONF_PLATFORM_SEC_CAPS@) \ $(LIBREPLACEMALLOC_LDFLAGS_@VGCONF_PLATFORM_SEC_CAPS@)endif* On Mon, Feb 22, 2016 at 1:07 PM, Anuta Mukherjee <man...@gm...> wrote: > 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 > -- Anuta Mukherjee, Dept of Computer Science Engg, CEG, Anna University |
|
From: Philippe W. <phi...@sk...> - 2016-02-22 22:38:23
|
On Mon, 2016-02-22 at 14:52 +0530, Anuta Mukherjee wrote:
Hello Anuta,
> 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)
>
One possible reason for the above is if the wrapping code is linked to
the tool,
rather than being in the tool preload file.
So, what you could do is (assuming you are on amd64, and that your
install is in the directory Inst):
nm Inst/lib/valgrind/vgpreload_helgrind-amd64-linux.so|grep -i pthreadZucreate
and the same command for your tool:
nm Inst/lib/valgrind/vgpreload_tracker-amd64-linux.so|grep -i pthreadZucreate
Both commands should output a line such as:
000000000000c0bc T _vgw00000ZZ_libpthreadZdsoZd0_pthreadZucreateZAZa
If the above is ok, then run with -v -v -v -d -d -d
The tracing should show something like:
--2338:2: initimg preload_string:
following by a line containing a.o. the aboslute path name of the
tracker preload .so.
If all the above is correct, then I have no idea.
Maybe compare a run of your tool and helgrind
with the options
-v -v -v -d -d -d --trace-redir=yes
The traces/differences might explain the problem.
Philippe
|
|
From: Anuta M. <man...@gm...> - 2016-02-23 05:02:48
|
Hi, I think I've found the problem. This is my output when I run the above commands: *anuta@anuta-ubuntu:/valgrind/valgrind-3.11.0$ nm inst/lib/valgrind/vgpreload_helgrind-amd64-linux.so|grep -i pthreadZucreate000000000000b84f T _vgw00000ZZ_libpthreadZdsoZd0_pthreadZucreateZAZaanuta@anuta-ubuntu:/valgrind/valgrind-3.11.0$ nm inst/lib/valgrind/vgpreload_tracker-amd64-linux.so|grep -i pthreadZucreatenm: 'inst/lib/valgrind/vgpreload_tracker-amd64-linux.so': No such file* My tool's preload file isn't in the inst/lib/valgrind directory at all. How do I fix this? My Makefile is exactly the same as Helgrind's, and I ran autogen, configure, make and make install as well. On Tue, Feb 23, 2016 at 4:11 AM, Philippe Waroquiers < phi...@sk...> wrote: > On Mon, 2016-02-22 at 14:52 +0530, Anuta Mukherjee wrote: > > Hello Anuta, > > > 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) > > > > One possible reason for the above is if the wrapping code is linked to > the tool, > rather than being in the tool preload file. > > So, what you could do is (assuming you are on amd64, and that your > install is in the directory Inst): > nm Inst/lib/valgrind/vgpreload_helgrind-amd64-linux.so|grep -i > pthreadZucreate > and the same command for your tool: > nm Inst/lib/valgrind/vgpreload_tracker-amd64-linux.so|grep -i > pthreadZucreate > > Both commands should output a line such as: > 000000000000c0bc T _vgw00000ZZ_libpthreadZdsoZd0_pthreadZucreateZAZa > > If the above is ok, then run with -v -v -v -d -d -d > The tracing should show something like: > --2338:2: initimg preload_string: > following by a line containing a.o. the aboslute path name of the > tracker preload .so. > > If all the above is correct, then I have no idea. > > Maybe compare a run of your tool and helgrind > with the options > -v -v -v -d -d -d --trace-redir=yes > > The traces/differences might explain the problem. > > Philippe > > > > -- Anuta Mukherjee, Dept of Computer Science Engg, CEG, Anna University |
|
From: Ivo R. <iv...@iv...> - 2016-02-23 06:53:38
|
2016-02-23 5:02 GMT+00:00 Anuta Mukherjee <man...@gm...>: > Hi, > > I think I've found the problem. This is my output when I run the above > commands: > > > > > > > > > *anuta@anuta-ubuntu:/valgrind/valgrind-3.11.0$ nm > inst/lib/valgrind/vgpreload_helgrind-amd64-linux.so|grep -i > pthreadZucreate000000000000b84f T > _vgw00000ZZ_libpthreadZdsoZd0_pthreadZucreateZAZaanuta@anuta-ubuntu:/valgrind/valgrind-3.11.0$ > nm inst/lib/valgrind/vgpreload_tracker-amd64-linux.so|grep -i > pthreadZucreatenm: 'inst/lib/valgrind/vgpreload_tracker-amd64-linux.so': No > such file* > > My tool's preload file isn't in the inst/lib/valgrind directory at all. > How do I fix this? My Makefile is exactly the same as Helgrind's, and I ran > autogen, configure, make and make install as well. > Just to make sure that you listed your tool (tracker) in: 1) configure.ac, AC_CONFIG_FILES 2) top-level Makefile.am, SUBDIRS I. |
|
From: Anuta M. <man...@gm...> - 2016-02-23 08:58:33
|
Hi Ivo, My tool was listed in: 1) configure.ac : AC_OUTPUT 2) Makefile.am : TOOLS I added the ones you mentioned - still the same error! I should mention : I was able to run my tool perfectly before I added another file with the wrapper (and changed my Makefile) On Tue, Feb 23, 2016 at 12:23 PM, Ivo Raisr <iv...@iv...> wrote: > > > 2016-02-23 5:02 GMT+00:00 Anuta Mukherjee <man...@gm...>: > >> Hi, >> >> I think I've found the problem. This is my output when I run the above >> commands: >> >> >> >> >> >> >> >> >> *anuta@anuta-ubuntu:/valgrind/valgrind-3.11.0$ nm >> inst/lib/valgrind/vgpreload_helgrind-amd64-linux.so|grep -i >> pthreadZucreate000000000000b84f T >> _vgw00000ZZ_libpthreadZdsoZd0_pthreadZucreateZAZaanuta@anuta-ubuntu:/valgrind/valgrind-3.11.0$ >> nm inst/lib/valgrind/vgpreload_tracker-amd64-linux.so|grep -i >> pthreadZucreatenm: 'inst/lib/valgrind/vgpreload_tracker-amd64-linux.so': No >> such file* >> >> My tool's preload file isn't in the inst/lib/valgrind directory at all. >> How do I fix this? My Makefile is exactly the same as Helgrind's, and I ran >> autogen, configure, make and make install as well. >> > > Just to make sure that you listed your tool (tracker) in: > 1) configure.ac, AC_CONFIG_FILES > 2) top-level Makefile.am, SUBDIRS > > I. > -- Anuta Mukherjee, Dept of Computer Science Engg, CEG, Anna University |
|
From: Anuta M. <man...@gm...> - 2016-02-24 06:30:06
|
Hi,
A few updates. I wrote a wrapper for a simple function in my client code
and that ran perfectly. However, my pthread_create wrapper still fails with
the following errors:
*--24067-- VG_USERREQ__CLIENT_CALL2: func=0x0--24067--
VG_USERREQ__CLIENT_CALL1: func=0x0Unexpected error.==24067== ==24067==
Process terminating with default action of signal 6 (SIGABRT)==24067==
at 0x5082267: raise (raise.c:55)==24067== by 0x5083EC9: abort
(abort.c:89)==24067== by 0x507B03C: __assert_fail_base
(assert.c:92)==24067== by 0x507B0F1: __assert_fail
(assert.c:101)==24067== by 0x4E376EF: pthread_create@@GLIBC_2.2.5
(allocatestack.c:591)==24067== by 0x400737: main (prog.c:18)==24067==
Aborted (core dumped)*
---------------------------------------------------------------------------------------------------------------------------------------
It is failing at prog.c:18 which is the pthread_create statement.
This is my wrapper code:
----------------------------------------------------------------------------------------------------------------------------------------
*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 wrapper
just got called!\n"); return ret;}*
On Tue, Feb 23, 2016 at 2:28 PM, Anuta Mukherjee <man...@gm...> wrote:
> Hi Ivo,
>
> My tool was listed in:
> 1) configure.ac : AC_OUTPUT
> 2) Makefile.am : TOOLS
>
> I added the ones you mentioned - still the same error!
>
> I should mention : I was able to run my tool perfectly before I added
> another file with the wrapper (and changed my Makefile)
>
> On Tue, Feb 23, 2016 at 12:23 PM, Ivo Raisr <iv...@iv...> wrote:
>
>>
>>
>> 2016-02-23 5:02 GMT+00:00 Anuta Mukherjee <man...@gm...>:
>>
>>> Hi,
>>>
>>> I think I've found the problem. This is my output when I run the above
>>> commands:
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>> *anuta@anuta-ubuntu:/valgrind/valgrind-3.11.0$ nm
>>> inst/lib/valgrind/vgpreload_helgrind-amd64-linux.so|grep -i
>>> pthreadZucreate000000000000b84f T
>>> _vgw00000ZZ_libpthreadZdsoZd0_pthreadZucreateZAZaanuta@anuta-ubuntu:/valgrind/valgrind-3.11.0$
>>> nm inst/lib/valgrind/vgpreload_tracker-amd64-linux.so|grep -i
>>> pthreadZucreatenm: 'inst/lib/valgrind/vgpreload_tracker-amd64-linux.so': No
>>> such file*
>>>
>>> My tool's preload file isn't in the inst/lib/valgrind directory at all.
>>> How do I fix this? My Makefile is exactly the same as Helgrind's, and I ran
>>> autogen, configure, make and make install as well.
>>>
>>
>> Just to make sure that you listed your tool (tracker) in:
>> 1) configure.ac, AC_CONFIG_FILES
>> 2) top-level Makefile.am, SUBDIRS
>>
>> I.
>>
>
>
>
> --
> Anuta Mukherjee,
> Dept of Computer Science Engg,
> CEG, Anna University
>
--
Anuta Mukherjee,
Dept of Computer Science Engg,
CEG, Anna University
|