GNU libc’s backtrace and In-circuit emulators/debuggers are not always available when porting code to a new platform, especially when the target is a micro C compiler such as for the Z80. (Typically a program bug would “just hang” somewhere, or crash the gadget.)
Is there an alternative to the classic “wolf fencing” method of manually inserting printf? Something simple and portable (using no C extensions) that a coder can do while developing a program that includes tracing and backtracing into a C program?
BTW: Here are a couple of other question on stackoverflow that are related, but these both use GNU GLIBC’s backtrace and backtrace is often compiler/implementation specific:
There is an implementation at RosettaCode.org which uses the same basic idea as @jsl4tv’s suggestion.
Example, given the following classic C code with built in “hang“:
#define STACK_TRACE_ON and #include “stack_trace.h” from RosettaCode.org then insert BEGIN(f)/ENDs where required:
Produces:
A well polished [open source] version of this BEGIN ~ END method would be perfect. (Esp if it has a “FINALLY” clause for exception handling).
Hints/URLs appreciated.