vicky lin <vicky....@gmail.com> writes:
>     There was something strange happened when I used valgrind.  I run
> my linux program written in c++ and it threw a "segment fault", but
> when I tried " valgrind --tool=memcheck -v ./mycode ", the program
> did't throw segment fault and continued to run and returned the
> experimental results.
[snip]
> Are the results got from running under valgrind environment valid?

Well, your program is buggy, but valgrind is doing the best it can
under the circumstances.  In that sense, the results are "valid".

Your code almost definitely has some statement:

  *x = 42;

in it, where `x' points to memory you do not own.  In your normal
environment, `x' probably points to either memory you don't own,
or read-only memory, etc., and thus you get lucky and your program
crashes.

Under valgrind, that memory is memory that the process owns.  This is
most likely because valgrind allocates a lot of memory behind your
back, and you're happily writing into that "extra" memory.

This is basically the same reason that you'll get a segmentation fault
on one machine and the program would run to completion on others.

The good news is that the "invalid write"s that valgrind reports are
almost assuredly the reason for your segfault.  That said, if you've
got a reproducible case, you're much better off fixing that segfault
using gdb before running valgrind.  Valgrind tends to be more useful in
finding those invalid writes that *don't* cause your program to crash,
because those are less visible under normal execution.

Cheers,

-tom

------------------------------------------------------------------------------
The Planet: dedicated and managed hosting, cloud storage, colocation
Stay online with enterprise data centers and the best network in the business
Choose flexible plans and management services without long-term contracts
Personal 24x7 support from experience hosting pros just a phone call away.
http://p.sf.net/sfu/theplanet-com
_______________________________________________
Valgrind-users mailing list
Valgrind-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/valgrind-users

Reply via email to