This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: why no stacktrace?


> 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

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]