From: Gunnar Ruthenberg <krill.plush@gmx.net>
To: ecos-discuss@ecos.sourceware.org, ecos-discuss@sources.redhat.com
Cc: Elad Yosef <elad.yosef@gmail.com>
Subject: Re: [ECOS] Fwd: How to dump the stack to serial without running GDB?
Date: Thu, 09 May 2013 11:16:00 -0000 [thread overview]
Message-ID: <518B8573.9030109@gmx.net> (raw)
In-Reply-To: <CAOFa9c1CBZGF2MeKawp77-vHctax4sBXoenFGQ27mOQFd1eiNg@mail.gmail.com>
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
prev parent reply other threads:[~2013-05-09 11:16 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <CAOFa9c3C+Fy53Nv-BPLR+dKype6RLsQ0v9iakfe=fbae=XZGiw@mail.gmail.com>
[not found] ` <CAOFa9c0Mryq0yL9gwZQkRLMGQ=Sibs9FCbC0T31vvWddKYqraw@mail.gmail.com>
2013-05-09 7:19 ` Elad Yosef
2013-05-09 11:16 ` Gunnar Ruthenberg [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=518B8573.9030109@gmx.net \
--to=krill.plush@gmx.net \
--cc=ecos-discuss@ecos.sourceware.org \
--cc=ecos-discuss@sources.redhat.com \
--cc=elad.yosef@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).