The errors occurred because I included libreplacemalloc in my tool, which calls VG_USERREQ__GET_MALLOCFUNCS (getting a table full of NULL function values), and then tries to call those functions instead of malloc(). In hindsight, the "memory exhausted" error was a clue pointing to this.
Removing the dependencies on LIBREPLACEMALLOC in Makefile.am solved the problem. All the best, Serguei Makarov On Mon, Jun 26, 2017 at 5:41 PM, Serhei Makarov <serhei.pub...@gmail.com> wrote: > Hello all, > > I'm writing a Valgrind tool that makes use of function wrapping. From > what I understand, wrappers need to run on the simulated CPU. I wrote > a simple example which imitates the way Memcheck uses > mc_replace_strmem.c to generate a preloaded .so that contains my own > wrappers. A simplified version of my code is attached; I've been > having some problems with it. > > After compiling and running the tool (using the 3.12.0 codebase on > Linux), the instrumented programs crash in odd ways: > > $ inst/bin/valgrind --tool=simplewrap ls > ==1201== SimpleWrap, do only basic function wrapping > ==1201== basic example for mailing list > ==1201== Using Valgrind-3.12.0 and LibVEX; rerun with -h for copyright info > ==1201== Command: ls > ==1201== > --1201-- VG_USERREQ__CLIENT_CALL1: func=0x0 > --1201-- VG_USERREQ__CLIENT_CALL1: func=0x0 > --1201-- VG_USERREQ__CLIENT_CALL1: func=0x0 > --1201-- VG_USERREQ__CLIENT_CALL1: func=0x0 > --1201-- VG_USERREQ__CLIENT_CALL1: func=0x0 > --1201-- VG_USERREQ__CLIENT_CALL1: func=0x0 > --1201-- VG_USERREQ__CLIENT_CALL1: func=0x0 > ls: memory exhausted > ==1201== > > $ ./vg-in-place --tool=wrapsimple gcc --help > > ==1215== SimpleWrap, do only basic function wrapping > ==1215== basic example for mailing list > ==1215== Using Valgrind-3.12.0 and LibVEX; rerun with -h for copyright info > ==1215== Command: gcc --help > ==1215== > --1215-- VG_USERREQ__CLIENT_CALL1: func=0x0 > --1215-- VG_USERREQ__CLIENT_CALL1: func=0x0 > terminate called without an active exception > ==1215== > ==1215== Process terminating with default action of signal 6 (SIGABRT) > ==1215== at 0x516F91F: raise (raise.c:58) > ==1215== by 0x5171519: abort (abort.c:89) > ==1215== by 0x47347C: ??? (in /usr/bin/gcc) > ==1215== by 0x472F05: ??? (in /usr/bin/gcc) > ==1215== by 0x472F50: ??? (in /usr/bin/gcc) > ==1215== by 0x471C51: ??? (in /usr/bin/gcc) > ==1215== by 0x4717A7: ??? (in /usr/bin/gcc) > ==1215== by 0x4657B6: ??? (in /usr/bin/gcc) > ==1215== by 0x441FED: ??? (in /usr/bin/gcc) > ==1215== by 0x481AAC: ??? (in /usr/bin/gcc) > ==1215== by 0x515A38F: (below main) (libc-start.c:245) > ==1215== > Aborted (core dumped) > > These crashes also happen if I comment out the wrapper function and > compile the tool with an 'empty' sw_wrap.c, so the cause appears to > relate to something I'm (not) doing with the build system to set up > the preloaded .so, rather than the way the wrapper itself is written. > Does anyone have a suggestion for how to properly add function > wrappers to a Valgrind tool? > > All the best, > Serguei Makarov ------------------------------------------------------------------------------ Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot _______________________________________________ Valgrind-users mailing list Valgrind-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/valgrind-users