Hi,
yes, that is perfectly possible.
I implemented this for a Coldfire/m68k system in eCos v2_0_40, but it should
be fairly similar for your target platform and a current eCos.
In the following description, i will refer to m68k.
In ecos/packages/hal/m68k/arch/current/src/hal_m68k.c, there is the function
"void hal_m68k_exception_handler(HAL_SavedRegisters* regs)".
With the right options enabled (or a little hack), it will stop there, or,
with a kernel, call cyg_hal_deliver_exception() in
ecos/packages/kernel/current/src/common/except.cxx.
This in turn calls Cyg_Thread::deliver_exception() in
ecos/packages/kernel/current/src/common/thread.cxx, which would call
Cyg_Exception_Control::deliver_exception() back in except.cxx.
There, simply extend cyg_null_exception_handler() to print all the debugging
information desired, including the saved registers, a few stack bytes, and a
call trace. The cleaner way is to register a handler doing that for all
(or all relevant) exceptions.
Hopping through the stack to follow the function calls may be
non-trivial with
various pitfalls to be avoided, so do add many plausibility and memory range
checks there to prevent from exceptions on exceptions.
The above approach replaces GDB handling with a console printout of
debugging
information. Changing it to decide at run-time between printing or
handling GDB
should be fairly simple.
Note that during the product's life cycle, i also added
core-dump/stack-trace
like features in places other than handling CPU exceptions, to ease
debugging.
This includes allocation failures, assertions, and watchdog warnings, which
would report the current thread and a trace shortly before an impending
watchdog
time-out reset (but keep running the program, as it might service the
watchdog
just in the nick of time).
(Also note that the latter included a few fundamental changes in the context
switching logics, as the watchdog warning was implemented using a timer,
whose
handler may be called from ISR/DSR limbo rather than an actual thread
context.)
Regards
gunnar.
On 2013-05-09 09:19, Elad Yosef wrote:
Hi all,
I want to implement back-trace that will dump the stack into console
when exception occurs.
The GDB stub is in the RedBoot and I can't run the GDB all the time in
all systems.
Is there a way to dump the stack (linux like back-trace) with having
the GDB connected?
Sub-contractors that are willing to take the challenge are welcomed.
--
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss