|
From: Andres T. <and...@ta...> - 2015-03-16 13:57:16
|
Hi, I'm having a hard time wrapping functions like helgrind does.
My problem is the next:
I have this file (main.cpp):
-------------------main.cpp------------------------------------------
int testFunction(int a)
{
return a + 1;
}
int main(void)
{
int i;
for(i=0;i<2;++i)
cout << testFunction(1) << endl;
return 0;
}
---------------------------------------------------------------------------
And I have my valgrind tool:
---------------------------fb_main.c----------------------------------------
.
.
.
#define WRAP_FUNC(retType, macroName, f, args...) \
retType I_WRAP_SONAME_FNNAME_ZZ(macroName,f)(args); \
retType I_WRAP_SONAME_FNNAME_ZZ(macroName,f)(args)
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <errno.h>
#include <pthread.h>
WRAP_FUNC(int, NONE, testFunction, int a)
{
return 1;
}
------------------------------------------------------------------------------------------------------
And when I try to run the binary from main.cpp with my tool I get this:
------------------------------------------------------------------------------------------------------------
[andres@localhost valgrind]$
/home/andres/Documents/valgrind/install/bin/valgrind --tool=foobar
../test/a.out
==11636== Nulgrind, the minimal Valgrind tool
==11636== Copyright (C) 2002-2013, and GNU GPL'd, by Nicholas Nethercote.
==11636== Using Valgrind-3.11.0.SVN and LibVEX; rerun with -h for copyright info
==11636== Command: ../prueba/a.out
==11636==
valgrind: m_redir.c:605 (vgPlain_redir_notify_new_DebugInfo):
Assertion 'is_plausible_guest_addr(sym_avmas.main)' failed.
Segmentation fault (core dumped)
------------------------------------------------------------------------------------------------------------
I know I'm doing something wrong because helgrind works, but I don't
realize what. Maybe someone of you knows what's going on(I have the
preload.so).
ps: I'm using valgrind 3.11 from the svn repository.
Regards,
Andres
|
|
From: Julian S. <js...@ac...> - 2015-03-16 15:11:16
|
> I know I'm doing something wrong because helgrind works, but I don't > realize what. Maybe someone of you knows what's going on(I have the > preload.so). Possibly the problem is that you are using C++ and so the names in the generated machine code are different from those in your source. This is different from the situation in C, where there is a 1:1 mapping. You can find the names in the machine code using 'nm' on the .o or executable file. Passing the output of nm through c++filt is also useful. Or just write your test case in C instead. J |
|
From: Andres T. <and...@ta...> - 2015-03-16 15:17:33
|
I thought that, and I tried with this example:
------------- main.c -------------------------------
#include <stdio.h>
int testFunction(int a)
{
return a + 1;
}
int main(void)
{
int i;
for(i=0;i<2;++i)
printf("%d\n", testFunction(5));
return 0;
}
---------------------------------------------------------
but I'm having the same problem:
[andres@localhost valgrind]$
/home/andres/Documents/valgrind/install/bin/valgrind --tool=foobar
../test/a.out
==7052== Nulgrind, the minimal Valgrind tool
==7052== Copyright (C) 2002-2013, and GNU GPL'd, by Nicholas Nethercote.
==7052== Using Valgrind-3.11.0.SVN and LibVEX; rerun with -h for copyright info
==7052== Command: ../test/a.out
==7052==
valgrind: m_redir.c:605 (vgPlain_redir_notify_new_DebugInfo):
Assertion 'is_plausible_guest_addr(sym_avmas.main)' failed.
Segmentation fault (core dumped)
2015-03-16 12:11 GMT-03:00 Julian Seward <js...@ac...>:
>
>> I know I'm doing something wrong because helgrind works, but I don't
>> realize what. Maybe someone of you knows what's going on(I have the
>> preload.so).
>
> Possibly the problem is that you are using C++ and so the names in the
> generated machine code are different from those in your source. This is
> different from the situation in C, where there is a 1:1 mapping.
>
> You can find the names in the machine code using 'nm' on the .o or
> executable file. Passing the output of nm through c++filt is also
> useful.
>
> Or just write your test case in C instead.
>
> J
>
|
|
From: Josef W. <Jos...@gm...> - 2015-03-16 16:31:08
|
Am 16.03.2015 um 14:57 schrieb Andres Tiraboschi: > Hi, I'm having a hard time wrapping functions like helgrind does. > ... > And I have my valgrind tool: I think your problem is that wrappers must be part of guest code themself (a shared library to be preloaded), not defined in the tool. See the Makefile in helgrind: there is a separate VGPRELOAD_HELGRIND_SOURCES_COMMON = hg_intercepts.c in addition to the tool itself. Josef |