<s>
Valgrind	B-Application
(	O
)	O
is	O
a	O
programming	B-Application
tool	I-Application
for	O
memory	B-General_Concept
debugging	I-General_Concept
,	O
memory	B-General_Concept
leak	I-General_Concept
detection	I-General_Concept
,	O
and	O
profiling	O
.	O
</s>
<s>
Valgrind	B-Application
was	O
originally	O
designed	O
to	O
be	O
a	O
free	B-Application
memory	B-General_Concept
debugging	I-General_Concept
tool	O
for	O
Linux	B-Application
on	O
x86	B-Operating_System
,	O
but	O
has	O
since	O
evolved	O
to	O
become	O
a	O
generic	O
framework	O
for	O
creating	O
dynamic	O
analysis	O
tools	O
such	O
as	O
checkers	O
and	O
profilers	O
.	O
</s>
<s>
Valgrind	B-Application
is	O
in	O
essence	O
a	O
virtual	B-Architecture
machine	I-Architecture
using	O
just-in-time	O
compilation	O
techniques	O
,	O
including	O
dynamic	O
recompilation	O
.	O
</s>
<s>
Nothing	O
from	O
the	O
original	O
program	O
ever	O
gets	O
run	O
directly	O
on	O
the	O
host	O
processor	B-General_Concept
.	O
</s>
<s>
Instead	O
,	O
Valgrind	B-Application
first	O
translates	O
the	O
program	O
into	O
a	O
temporary	O
,	O
simpler	O
form	O
called	O
intermediate	B-Application
representation	I-Application
(	O
IR	B-Application
)	O
,	O
which	O
is	O
a	O
processor-neutral	O
,	O
static	O
single	O
assignment	O
form-based	O
form	O
.	O
</s>
<s>
After	O
the	O
conversion	O
,	O
a	O
tool	O
(	O
see	O
below	O
)	O
is	O
free	B-Application
to	O
do	O
whatever	O
transformations	O
it	O
would	O
like	O
on	O
the	O
IR	B-Application
,	O
before	O
Valgrind	B-Application
translates	O
the	O
IR	B-Application
back	O
into	O
machine	O
code	O
and	O
lets	O
the	O
host	O
processor	B-General_Concept
run	O
it	O
.	O
</s>
<s>
Valgrind	B-Application
recompiles	O
binary	O
code	O
to	O
run	O
on	O
host	O
and	O
target	O
(	O
or	O
simulated	O
)	O
CPUs	O
of	O
the	O
same	O
architecture	O
.	O
</s>
<s>
It	O
also	O
includes	O
a	O
GDB	B-Language
stub	O
to	O
allow	O
debugging	O
of	O
the	O
target	O
program	O
as	O
it	O
runs	O
in	O
Valgrind	B-Application
,	O
with	O
"	O
monitor	O
commands	O
"	O
that	O
allow	O
querying	O
the	O
Valgrind	B-Application
tool	O
for	O
various	O
information	O
.	O
</s>
<s>
A	O
considerable	O
amount	O
of	O
performance	O
is	O
lost	O
in	O
these	O
transformations	O
(	O
and	O
usually	O
,	O
the	O
code	O
the	O
tool	O
inserts	O
)	O
;	O
usually	O
,	O
code	O
run	O
with	O
Valgrind	B-Application
and	O
the	O
"	O
none	O
"	O
tool	O
(	O
which	O
does	O
nothing	O
to	O
the	O
IR	B-Application
)	O
runs	O
at	O
20%	O
to	O
25%	O
of	O
the	O
speed	O
of	O
the	O
normal	O
program	O
.	O
</s>
<s>
There	O
are	O
multiple	O
tools	O
included	O
with	O
Valgrind	B-Application
(	O
and	O
several	O
external	O
ones	O
)	O
.	O
</s>
<s>
Memcheck	O
inserts	O
extra	O
instrumentation	B-Application
code	O
around	O
almost	O
all	O
instructions	O
,	O
which	O
keeps	O
track	O
of	O
the	O
validity	O
(	O
all	O
unallocated	O
memory	O
starts	O
as	O
invalid	O
or	O
"	O
undefined	O
"	O
,	O
until	O
it	O
is	O
initialized	O
into	O
a	O
deterministic	O
state	O
,	O
possibly	O
from	O
other	O
memory	O
)	O
and	O
addressability	O
(	O
whether	O
the	O
memory	O
address	O
in	O
question	O
points	O
to	O
an	O
allocated	O
,	O
non-freed	O
memory	O
block	O
)	O
,	O
stored	O
in	O
the	O
so-called	O
V	O
bits	O
and	O
A	O
bits	O
respectively	O
.	O
</s>
<s>
As	O
data	O
is	O
moved	O
around	O
or	O
manipulated	O
,	O
the	O
instrumentation	B-Application
code	O
keeps	O
track	O
of	O
the	O
A	O
and	O
V	O
bits	O
,	O
so	O
they	O
are	O
always	O
correct	O
on	O
a	O
single-bit	O
level	O
.	O
</s>
<s>
In	O
addition	O
,	O
Memcheck	O
replaces	O
the	O
standard	O
C	B-Language
memory	I-Language
allocator	I-Language
with	O
its	O
own	O
implementation	O
,	O
which	O
also	O
includes	O
memory	O
guards	O
around	O
all	O
allocated	O
blocks	O
(	O
with	O
the	O
A	O
bits	O
set	O
to	O
"	O
invalid	O
"	O
)	O
.	O
</s>
<s>
This	O
feature	O
enables	O
Memcheck	O
to	O
detect	O
off-by-one	B-Error_Name
errors	I-Error_Name
where	O
a	O
program	O
reads	O
or	O
writes	O
outside	O
an	O
allocated	O
block	O
by	O
a	O
small	O
amount	O
.	O
</s>
<s>
Programs	O
running	O
under	O
Memcheck	O
usually	O
run	O
20	O
–	O
30	O
times	O
slower	O
than	O
running	O
outside	O
Valgrind	B-Application
and	O
use	O
more	O
memory	O
(	O
there	O
is	O
a	O
memory	O
penalty	O
per	O
allocation	O
)	O
.	O
</s>
<s>
Thus	O
,	O
few	O
developers	O
run	O
their	O
code	O
under	O
Memcheck	O
(	O
or	O
any	O
other	O
Valgrind	B-Application
tool	O
)	O
all	O
the	O
time	O
.	O
</s>
<s>
In	O
addition	O
to	O
Memcheck	O
,	O
Valgrind	B-Application
has	O
several	O
other	O
tools	O
:	O
</s>
<s>
None	O
,	O
runs	O
the	O
code	O
in	O
the	O
virtual	B-Architecture
machine	I-Architecture
without	O
performing	O
any	O
analysis	O
and	O
thus	O
has	O
the	O
smallest	O
possible	O
CPU	O
and	O
memory	O
overhead	O
of	O
all	O
tools	O
.	O
</s>
<s>
Since	O
Valgrind	B-Application
itself	O
provides	O
a	O
trace	O
back	O
from	O
a	O
segmentation	B-Error_Name
fault	I-Error_Name
,	O
the	O
none	O
tool	O
provides	O
this	O
traceback	O
at	O
minimal	O
overhead	O
.	O
</s>
<s>
Massif	O
,	O
a	O
heap	B-General_Concept
profiler	O
.	O
</s>
<s>
The	O
separate	O
GUI	B-Application
massif-visualizer	O
visualizes	O
output	O
from	O
Massif	O
.	O
</s>
<s>
Cachegrind	O
,	O
a	O
cache	B-General_Concept
profiler	O
.	O
</s>
<s>
The	O
separate	O
GUI	B-Application
KCacheGrind	B-Application
visualizes	O
output	O
from	O
Cachegrind	O
.	O
</s>
<s>
Callgrind	B-Application
,	O
a	O
call	B-Application
graph	I-Application
analyzer	O
created	O
by	O
Josef	O
Weidendorfer	O
,	O
added	O
to	O
Valgrind	B-Application
as	O
of	O
version	O
3.2.0	O
.	O
</s>
<s>
KCacheGrind	B-Application
can	O
visualize	O
output	O
from	O
Callgrind	B-Application
.	O
</s>
<s>
DHAT	O
,	O
dynamic	O
heap	B-General_Concept
analysis	O
tool	O
which	O
analyzes	O
how	O
much	O
memory	O
is	O
allocated	O
and	O
for	O
how	O
long	O
,	O
as	O
well	O
as	O
patterns	O
of	O
memory	B-General_Concept
usage	I-General_Concept
.	O
</s>
<s>
One	O
such	O
tool	O
is	O
ThreadSanitizer	O
,	O
another	O
detector	O
of	O
race	B-Operating_System
conditions	I-Operating_System
.	O
</s>
<s>
As	O
of	O
version	O
3.4.0	O
,	O
Valgrind	B-Application
supports	O
Linux	B-Application
on	O
x86	B-Operating_System
,	O
x86-64	B-Device
and	O
PowerPC	B-Architecture
.	O
</s>
<s>
Support	O
for	O
Linux	B-Application
on	O
ARMv7	B-Architecture
(	O
used	O
for	O
example	O
in	O
certain	O
smartphones	B-Application
)	O
was	O
added	O
in	O
version	O
3.6.0	O
.	O
</s>
<s>
Support	O
for	O
Solaris	B-Application
was	O
added	O
in	O
version	O
3.11.0	O
.	O
</s>
<s>
Support	O
for	O
FreeBSD	B-Operating_System
x86	B-Operating_System
and	O
amd64	B-Device
was	O
added	O
in	O
version	O
3.18.0	O
.	O
</s>
<s>
There	O
are	O
unofficial	O
ports	O
to	O
other	O
Unix-like	B-Operating_System
platforms	O
(	O
like	O
OpenBSD	B-Operating_System
,	O
and	O
NetBSD	B-Device
)	O
.	O
</s>
<s>
Since	O
version	O
3.9.0	O
there	O
is	O
support	O
for	O
Linux	B-Application
on	O
MIPS64	O
little	O
and	O
big	O
endian	O
,	O
for	O
MIPS	O
DSP	O
ASE	O
on	O
MIPS32	O
,	O
for	O
s390x	O
Decimal	O
Floating	O
Point	O
instructions	O
,	O
for	O
POWER8	B-Device
(	O
Power	O
ISA	O
2.07	O
)	O
instructions	O
,	O
for	O
Intel	O
AVX2	B-General_Concept
instructions	O
,	O
for	O
Intel	O
Transactional	O
Synchronization	O
Extensions	O
,	O
both	O
RTM	O
and	O
HLE	O
and	O
initial	O
support	O
for	O
Hardware	O
Transactional	O
Memory	O
on	O
POWER	O
.	O
</s>
<s>
The	O
name	O
Valgrind	B-Application
is	O
a	O
reference	O
to	O
the	O
main	O
entrance	O
of	O
Valhalla	B-Application
from	O
Norse	O
mythology	O
.	O
</s>
<s>
The	O
original	O
author	O
of	O
Valgrind	B-Application
is	O
Julian	O
Seward	O
,	O
who	O
in	O
2006	O
won	O
a	O
Google-O	O
'	O
Reilly	O
Open	O
Source	O
Award	O
for	O
his	O
work	O
on	O
Valgrind	B-Application
.	O
</s>
<s>
It	O
is	O
used	O
by	O
a	O
number	O
of	O
Linux-based	O
projects	O
.	O
</s>
<s>
The	O
following	O
code	O
will	O
pass	O
the	O
Memcheck	O
tool	O
in	O
Valgrind	B-Application
without	O
incident	O
,	O
despite	O
containing	O
the	O
errors	O
described	O
in	O
the	O
comments	O
:	O
</s>
<s>
stack	B-General_Concept
smashing	I-General_Concept
exploit	I-General_Concept
.	O
</s>
