<s>
In	O
computing	O
,	O
a	O
stack	B-Language
trace	I-Language
(	O
also	O
called	O
stack	O
backtrace	B-Language
or	O
stack	O
traceback	B-Language
)	O
is	O
a	O
report	O
of	O
the	O
active	O
stack	O
frames	O
at	O
a	O
certain	O
point	O
in	O
time	O
during	O
the	O
execution	O
of	O
a	O
program	B-Application
.	O
</s>
<s>
When	O
a	O
program	B-Application
is	O
run	O
,	O
memory	O
is	O
often	O
dynamically	O
allocated	O
in	O
two	O
places	O
;	O
the	O
stack	O
and	O
the	O
heap	O
.	O
</s>
<s>
Stack	O
also	O
refers	O
to	O
a	O
programming	O
construct	O
,	O
thus	O
to	O
differentiate	O
it	O
,	O
this	O
stack	O
is	O
referred	O
to	O
as	O
the	O
program	B-Application
's	O
function	B-General_Concept
call	I-General_Concept
stack	I-General_Concept
.	O
</s>
<s>
Each	O
time	O
a	O
function	O
is	O
called	O
in	O
a	O
program	B-Application
,	O
a	O
block	O
of	O
memory	O
called	O
an	O
activation	O
record	O
is	O
allocated	O
on	O
top	O
of	O
the	O
call	B-General_Concept
stack	I-General_Concept
.	O
</s>
<s>
Programmers	O
commonly	O
use	O
stack	B-Language
tracing	I-Language
during	O
interactive	O
and	O
post-mortem	O
debugging	O
.	O
</s>
<s>
End-users	O
may	O
see	O
a	O
stack	B-Language
trace	I-Language
displayed	O
as	O
part	O
of	O
an	O
error	B-Error_Name
message	I-Error_Name
,	O
which	O
the	O
user	O
can	O
then	O
report	O
to	O
a	O
programmer	O
.	O
</s>
<s>
A	O
stack	B-Language
trace	I-Language
allows	O
tracking	O
the	O
sequence	O
of	O
nested	O
functions	O
called	O
-	O
up	O
to	O
the	O
point	O
where	O
the	O
stack	B-Language
trace	I-Language
is	O
generated	O
.	O
</s>
<s>
Sibling	B-Language
calls	I-Language
do	O
not	O
appear	O
in	O
a	O
stack	B-Language
trace	I-Language
.	O
</s>
<s>
Many	O
programming	O
languages	O
,	O
including	O
Java	B-Language
and	O
C#	B-Application
,	O
have	O
built-in	O
support	O
for	O
retrieving	O
the	O
current	O
stack	B-Language
trace	I-Language
via	O
system	O
calls	O
.	O
</s>
<s>
Before	O
std::stacktrace	O
was	O
added	O
in	O
standard	O
library	B-Library
as	O
a	O
container	O
for	O
std::stacktrace_entry	O
,	O
pre-C	O
++23	O
has	O
no	O
built-in	O
support	O
for	O
doing	O
this	O
,	O
but	O
C++	B-Language
users	O
can	O
retrieve	O
stack	B-Language
traces	I-Language
with	O
(	O
for	O
example	O
)	O
the	O
library	B-Library
.	O
</s>
<s>
In	O
JavaScript	B-Language
,	O
exceptions	B-General_Concept
hold	O
a	O
stack	O
property	O
that	O
contain	O
the	O
stack	O
from	O
the	O
place	O
where	O
it	O
was	O
thrown	O
.	O
</s>
<s>
As	O
an	O
example	O
,	O
the	O
following	O
Python	B-Language
program	I-Language
contains	O
an	O
error	O
.	O
</s>
<s>
Running	O
the	O
program	B-Application
under	O
the	O
standard	O
Python	B-Language
interpreter	O
produces	O
the	O
following	O
error	B-Error_Name
message	I-Error_Name
.	O
</s>
<s>
The	O
stack	B-Language
trace	I-Language
shows	O
where	O
the	O
error	O
occurs	O
,	O
namely	O
in	O
the	O
c	B-Language
function	O
.	O
</s>
<s>
It	O
also	O
shows	O
that	O
the	O
c	B-Language
function	O
was	O
called	O
by	O
b	O
,	O
which	O
was	O
called	O
by	O
a	O
,	O
which	O
was	O
in	O
turn	O
called	O
by	O
the	O
code	O
on	O
line	O
15	O
(	O
the	O
last	O
line	O
)	O
of	O
the	O
program	B-Application
.	O
</s>
<s>
The	O
activation	O
records	O
for	O
each	O
of	O
these	O
three	O
functions	O
would	O
be	O
arranged	O
in	O
a	O
stack	O
such	O
that	O
the	O
a	O
function	O
would	O
occupy	O
the	O
bottom	O
of	O
the	O
stack	O
and	O
the	O
c	B-Language
function	O
would	O
occupy	O
the	O
top	O
of	O
the	O
stack	O
.	O
</s>
<s>
In	O
Java	B-Language
,	O
stack	B-Language
traces	I-Language
can	O
be	O
dumped	O
manually	O
with	O
Thread.dumpStack( )	O
Take	O
the	O
following	O
input	O
:	O
</s>
<s>
Both	O
C	B-Language
and	O
C++	B-Language
(	O
pre-C	O
++23	O
)	O
do	O
not	O
have	O
native	O
support	O
for	O
obtaining	O
stack	B-Language
traces	I-Language
,	O
but	O
libraries	O
such	O
as	O
glibc	B-Language
and	O
boost	B-Language
provide	O
this	O
functionality	O
.	O
</s>
<s>
In	O
these	O
languages	O
,	O
some	O
compiler	O
optimizations	O
may	O
interfere	O
with	O
the	O
call	B-General_Concept
stack	I-General_Concept
information	O
that	O
can	O
be	O
recovered	O
at	O
runtime	O
.	O
</s>
<s>
For	O
instance	O
,	O
inlining	O
can	O
cause	O
missing	O
stack	O
frames	O
,	O
tail	B-Language
call	I-Language
optimizations	I-Language
can	O
replace	O
one	O
stack	O
frame	O
with	O
another	O
,	O
and	O
frame	O
pointer	O
elimination	O
can	O
prevent	O
call	B-General_Concept
stack	I-General_Concept
analysis	O
tools	O
from	O
correctly	O
interpreting	O
the	O
contents	O
of	O
the	O
call	B-General_Concept
stack	I-General_Concept
.	O
</s>
<s>
For	O
example	O
,	O
glibc	B-Language
's	O
backtrace( )	O
function	O
returns	O
an	O
output	O
with	O
the	O
program	B-Application
function	O
and	O
memory	O
address	O
.	O
</s>
<s>
As	O
of	O
C++23	B-Language
,	O
stack	B-Language
traces	I-Language
can	O
be	O
dumped	O
manually	O
by	O
printing	O
the	O
value	O
returned	O
by	O
static	O
member	O
function	O
std::stacktrace::current( )	O
:	O
</s>
<s>
Rust	B-Application
has	O
two	O
types	O
of	O
errors	O
.	O
</s>
<s>
However	O
,	O
recoverable	O
errors	O
cannot	O
generate	O
a	O
stack	B-Language
trace	I-Language
as	O
they	O
are	O
manually	O
added	O
and	O
not	O
a	O
result	O
of	O
a	O
runtime	O
error	O
.	O
</s>
<s>
As	O
of	O
June	O
2021	O
,	O
Rust	B-Application
has	O
experimental	O
support	O
for	O
stack	B-Language
traces	I-Language
on	O
unrecoverable	O
errors	O
.	O
</s>
<s>
Rust	B-Application
supports	O
printing	O
to	O
stderr	O
when	O
a	O
thread	O
panics	O
,	O
but	O
it	O
must	O
be	O
enabled	O
by	O
setting	O
the	O
RUST_BACKTRACE	O
environment	O
variable	O
.	O
</s>
<s>
When	O
enabled	O
,	O
such	O
backtraces	B-Language
look	O
similar	O
to	O
below	O
,	O
with	O
the	O
most	O
recent	O
call	O
first	O
.	O
</s>
