|
From: Barrie W. <bw...@cs...> - 2004-01-19 15:40:16
|
> -----Original Message-----
> From: Jeremy Fitzhardinge [mailto:je...@go...]
> Sent: 16 January 2004 18:54
> To: Barrie Walker
> Cc: 'val...@li...'
> Subject: Re: [Valgrind-users] Use of
> VALGRIND_DISCARD_TRANSLATIONS with nested functions
>
>
> On Fri, 2004-01-16 at 09:58, Barrie Walker wrote:
> > [snip] valgrind
> > [snip] nested functions
> > [snip] VALGRIND_DISCARD_TRANSLATIONS
> > [snip] what the parameters should be
> > [snip] where in the code it should be placed
> It's tricky - it isn't the proper solution, but more a hack
> to get you going. The trouble is that gcc generates a piece
> of code dynamically on the stack when you call a nested
> function; for each call, it generates a different piece of
> code. Valgrind sees this the first time, and generates its
> own instrumented code, but if gcc later uses the same stack
> location to generate code for a new call to a different
> function, Valgrind won't notice, and use the old cached code.
>
> Therefore, to use VALGRIND_DISCARD_TRANSLATIONS you need to
> guess the location and size of the code which gcc is
> generating. Something like this (before each call to a
> nested function) might work:
>
> int myfunc()
> {
> int mynestedfunc() {
> }
> char local;
>
> VALGRIND_DISCARD_TRANSLATIONS(&local-32, 128); // guessing
> mynestedfunc();
> }
>
> It gets more complex if you're passing a pointer to
> mynestedfunc elsewhere, and/or you use dynamically sized
> arrays or alloca(). &local is basically a guess at the value
> of %esp - you could also use:
> unsigned int esp;
>
> asm volatile("mov %%esp,%0" : "=r" (esp));
> VALGRIND_DISCARD_TRANSLATIONS(esp-32, 128); // guessing
>
> The real fix is for Valgrind to cope with this automatically
> (bug http://bugs.kde.org/show_bug.cgi?id=69511).
>
> J
Hi Jeremy,
Thank you, that was helpful.
I found that the address given for the function was a stack one in amongst
the local data (at least when passed to printf) and it seems to make a
difference when using that one.
Far from ideal, thought.
Barrie
|