This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: why no stacktrace?
- To: Ulrich dot Lauther at mchp dot siemens dot de
- Subject: Re: why no stacktrace?
- From: "Martin v. Loewis" <martin at loewis dot home dot cs dot tu-berlin dot de>
- Date: Tue, 4 Jan 2000 23:31:59 +0100
- CC: gcc at gcc dot gnu dot org
- References: <200001041246.NAA16260@fubini.mchp.siemens.de>
> All these languages, i.e., its compilers, (even Fortran) provided a stack
> trace when a program crashed. Not so gcc/g++. Why not?
I think this question has not been answered, yet (instead, the
question: What can I do instead? has been answered).
I believe the reason is that it is not possible, atleast without
sacrificing a good deal of performance, and without a major
re-engineering.
To provide a reliable back-trace, you must have a reliable stack
unwinder. The C ABI of most architectures does not have this built-in,
so gcc would have to emulate that function. For example, it could have
and alternative back-trace stack, and put a pointer to a string onto
that stack every time a function is entered, and pop it when the
function returns. Of course, that convention would not be honored by
the non-gcc-compiled functions (e.g. the C library), and it would add
noticable overhead.
This is much easier achieved in the source code:
int foo()
{
TraceEnter();
do_something();
TraceReturn(4);
}
TraceEnter and TraceReturn would be macros, and use __func__ to
produce the trace. Control of the overhead would be at the user, and
it would not only allow to produce a backtrace, but also a "forward"
trace. Of course, I've just answered "What to do instead", as well :)
If you know a clever way to achieve all your desired functionality
with little overhead, please let us know.
Regards,
Martin