Confused with valgrind and memmove

D

David RF

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(void)
{
char *s;

printf("======================================\n");
s = calloc(101, sizeof(char));
if (s != NULL) {
strcpy(s, "A Begoña le gusta el vino de Borgoña!!");
printf("%s\n", s);
while (*s) {
do memmove(s, s + 1, strlen(s) + 1); while ((*s & 0xc0) == 0x80);
printf("%s\n", s);
}
if (s) free(s);
}
printf("======================================\n");
return 0;
}

I don't see any mistake, but valgrind tells me:

david@debian:~$ valgrind --tool=memcheck --leak-check=yes -v ./demo

======================================
--3746-- REDIR: 0x4e9d680 (calloc) redirected to 0x4c20310 (calloc)
--3746-- REDIR: 0x4ea2eb0 (memcpy) redirected to 0x4c231d0 (memcpy)
--3746-- REDIR: 0x4ea2570 (mempcpy) redirected to 0x4c23d30 (mempcpy)
A Begoña le gusta el vino de Borgoña!!
--3746-- REDIR: 0x4ea22b0 (memmove) redirected to 0x4c23c70 (memmove)
Begoña le gusta el vino de Borgoña!!
Begoña le gusta el vino de Borgoña!!
egoña le gusta el vino de Borgoña!!
goña le gusta el vino de Borgoña!!
oña le gusta el vino de Borgoña!!
ña le gusta el vino de Borgoña!!
a le gusta el vino de Borgoña!!
le gusta el vino de Borgoña!!
le gusta el vino de Borgoña!!
e gusta el vino de Borgoña!!
gusta el vino de Borgoña!!
gusta el vino de Borgoña!!
usta el vino de Borgoña!!
sta el vino de Borgoña!!
ta el vino de Borgoña!!
a el vino de Borgoña!!
el vino de Borgoña!!
el vino de Borgoña!!
l vino de Borgoña!!
vino de Borgoña!!
vino de Borgoña!!
ino de Borgoña!!
no de Borgoña!!
o de Borgoña!!
de Borgoña!!
de Borgoña!!
e Borgoña!!
Borgoña!!
Borgoña!!
orgoña!!
rgoña!!
goña!!
oña!!
ña!!
a!!
!!
!

--3746-- REDIR: 0x4e9b9e0 (free) redirected to 0x4c21240 (free)
======================================
==3746==
==3746== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 8 from
1)


What does it mean REDIR? excuse this little OT but I don't find any
info in google about this point.
 
I

Igmar Palsenberg

I don't see any mistake, but valgrind tells me:

david@debian:~$ valgrind --tool=memcheck --leak-check=yes -v ./demo

======================================
--3746-- REDIR: 0x4e9d680 (calloc) redirected to 0x4c20310 (calloc)
--3746-- REDIR: 0x4ea2eb0 (memcpy) redirected to 0x4c231d0 (memcpy)
--3746-- REDIR: 0x4ea2570 (mempcpy) redirected to 0x4c23d30 (mempcpy)
A Begoña le gusta el vino de Borgoña!!
--3746-- REDIR: 0x4ea22b0 (memmove) redirected to 0x4c23c70 (memmove)
--3746-- REDIR: 0x4e9b9e0 (free) redirected to 0x4c21240 (free)
======================================
==3746==
==3746== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 8 from
1)


What does it mean REDIR? excuse this little OT but I don't find any
info in google about this point.

It says '0 errors'. So the message you are seeing are informational, and
bassically saying valgrind redirected your libc's memmove to it's own
implementation.



Igmar
 
D

David RF

[...]

I found it:

3.2.4. Debugging

Figuring out what's going on given the dynamic nature of wrapping can
be difficult. The --trace-redir=yes option makes this possible by
showing the complete state of the redirection subsystem after every
mmap/munmap event affecting code (text).

There are two central concepts:

*

A "redirection specification" is a binding of a (soname pattern,
fnname pattern) pair to a code address. These bindings are created by
writing functions with names made with the I_WRAP_SONAME_FNNAME_
{ZZ,_ZU} macros.
*

An "active redirection" is a code-address to code-address
binding currently in effect.

The state of the wrapping-and-redirection subsystem comprises a set of
specifications and a set of active bindings. The specifications are
acquired/discarded by watching all mmap/munmap events on code (text)
sections. The active binding set is (conceptually) recomputed from the
specifications, and all known symbol names, following any change to
the specification set.

--trace-redir=yes shows the contents of both sets following any such
event.

-v prints a line of text each time an active specification is used for
the first time.

Hence for maximum debugging effectiveness you will need to use both
options.

One final comment. The function-wrapping facility is closely tied to
Valgrind's ability to replace (redirect) specified functions, for
example to redirect calls to malloc to its own implementation. Indeed,
a replacement function can be regarded as a wrapper function which
does not call the original. However, to make the implementation more
robust, the two kinds of interception (wrapping vs replacement) are
treated differently.

--trace-redir=yes shows specifications and bindings for both
replacement and wrapper functions. To differentiate the two,
replacement bindings are printed using R-> whereas wraps are printed
using W->.
 
D

David RF

It says '0 errors'. So the message you are seeing are informational, and
bassically saying valgrind redirected your libc's memmove to it's own
implementation.

        Igmar

Thanks Igmar
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top