Re: printing the values of arguments for strcpy(3), memmove(3), ...

Tom Hughes via Valgrind-users <[email protected]>
Newsgroups gmane.comp.debugging.valgrind
Message-ID <[email protected]>
On 26/01/2021 09:32, Matthias Apitz wrote:

> So far so good. What would have helped me is that vg could print in its
> replacement functions for memmove(3) ... (vg_replace_strmem.c:1270)
> the provided pointers and other args, and as well part of the src
> buffer. For sure vg knows exactly these values to watch the illegal
> memory access.

If the memory is uninitialised then printing it's contents
shouldn't really be useful as they will have no meaning...

Presumably it was partially initialised in this case but it
sounds like quite an edge case and it's easy enough to add
some custom debugging to your code when it does help in cases
like this. I'm not clear if you just printed everything but
you can conditionalise it to only print the failing case:

   if ( VALGRIND_CHECK_MEM_IS_DEFINED( src, n ) )
   {
     fprintf( stderr, "ERROR: %.*s\n", n, src );
   }

if you want to get really clever you can limit it to printing
the valid part:

   const char *fail = VALGRIND_CHECK_MEM_IS_DEFINED( src, n );

   if ( fail )
   {
     fprintf( stderr, "ERROR: %.*s\n", fail - src, src );
   }

Tom

-- 
Tom Hughes ([email protected])
http://compton.nu/
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.