As a very useful enhancement, could we have a way of programmatically generating a backtrace when a crash occurs and outputting that on the serial? The ability to turn that feature on or off could even be controlled by one of the configuration options. Also the depth of the backtrace too.
execinfo. h’s backtrace() and backtrace_symbols() could be used to accomplish this. Alternatively, there is libunwind which could also be leveraged to implement this. It should be very straightforward. Thanks.
I tried implementing this myself by adding a hook into __verbose_terminate_handler() but unfortunately, execinfo.h is not included in MbedOS even though, surprisingly, MbedTLS conditionally includes that file. Anyway, I will attach my attempt as an addendum to this post and perhaps it can help expedite this enhancement being implemented. Thanks again.
If you glance over my code, you will realize that it is all practically there; all we now need is to have execinfo.h in the code base. So perhaps the task simply devolves into porting execinfo.h into MbedOS. Thanks.
Interesting issue, but AFAIK this is in general not trivial for Cortex-M microcontrollers, let alone Mbed. A simpler method would be to generate a core dump and analyze it with respect to the ELF file at the host side. There are projects which do this, but of course it would be much easier to have at least a guide to integrate it into Mbed.
Indeed @boraozgen, it is not as straightforward as other platforms, say for example, Linux. I wonder if Cortex-M microcontrollers can be ‘helped along in that direction’ by leveraging intrinsics such as the below which MbedOS is already leveraging. And on that note there are also other projects that I came across and researched that are trying to accomplish similar goals for embedded platforms. I will share their links too in the addendum.
Regards, and thanks for responding.
Nuertey
Excerpted from “./mbed-os/platform/include/platform/mbed_toolchain.h”
@boraozgen here are the relevant links below. I think that several great folks have been taking a stab at this “particular interesting issue” for some time now. Even the last link’s author’s code (and comments) on Stackoverflow is very instructive. I will excerpt his code in the next addendum but his whole comment (on ARM processors in general) needs to be read hence being linked by me; he and his team apparently leveraged the intrinsics, see? I think the intrinsics have all the information that we need, and the Mbed OS team ought to know this better than us, so I am trusting that they have insight into the issue better than us. Delving even within their backlog of closed issues even, I see that other folks have also attempted to request this same feature … Great minds thinking (and needing certain useful features in such a great embedded OS such as Mbed OS) after all :).