Hi all,
there is a good way to obtain the 'call stack' when errors occur ?
On Linux the S.O. create a core dump file with the debug information, but
I would like to have a similar information inside the program, to log
ever the error and send for an application/email/etc.
C itself provides no means to do this, short of keeping track
of all the calls and returns manually. However, many debuggers and
core-dump analyzers and so on can do this -- at least, they can
do it if the program is built in a prescribed way ("unstripped,"
for example).
Since you're interested in generating reports of programs that
are known to be in trouble, it may be best not to rely on the dying
program itself to do its own post-mortem. An attractive approach on
systems that allow more than one program to execute (again, this is
beyond the realm of the C language) is to write a simple "watchdog"
program that just observes the "worker" program. If the worker runs
to completion successfully, the watchdog just exits silently. But if
the worker completes unsuccessfully or abnormally, the watchdog can
scoop up core dumps or whatever other last-gasp breadcrumbs the worker
was able to strew. Since the watchdog is (presumably) not subject to
the same error that brought down the worker, it has a better chance of
getting the job done than the dying worker does.
However, all this is well outside what the C language provides.
The systems in which you run C programs quite probably offer some
tools to help with this sort of thing, but C itself does not.