c++ - How to get a call stack backtrace? (deeply embedded, no library support) -


I want to be able to print call stack backtraces to my exception handlers and debug function, basically just backtrace () Unfortunately, my C library does not provide such calls in Glibc, just like the Library function.

I have found something like this:

  #include & lt; Regardless of the unwind.h & gt / gcc internal, part of libgcc _Unwind_Reason_Code trace_fcn (_Unwind_Context * ctx, void * d) {int * depth = (int *) D; Printf ("\ t #% d:% 08x on program counter \ n", * depth, _Unwind_GetIP (ctx)); (* Depth) ++; Return _URC_NO_REASON; } Zero print_backtrace_here () {int depth = 0; _Unwind_Backtrace (& trace_fcn, and depth); }  

which works basically but the resultant marks are not always complete. For example, if I do

  int func3 () { Print_backtrace_here (); Return 0; } Int func2 () {returnc func3 (); } Int func1 () {returnc func2 (); } Int main () {returnc func1 (); }  

The backtrace only shows func3 () and main (), this is a toy example, but I have examined the disassembly and confirmed that these functions are completely complete or Optimized or not inline.)

Update: I tried this backcount code on older ARM 7 systems, but with the same (or at least, as much as possible Equivalent) compiler option and linker script and make a correct, complete backcount print Received (ie throw 1 and not fun missing 2) and the last main Bakstrys also Boot Initialization code, so presumably the problem is not with the linker script or compiler options. (In addition, disassembly has confirmed that no frame pointer has been used in this ARM 7 test).

The code has been compiled with a compiled-frame-pointer, but my platform (bare metal ARM Cortex M3) defines an ABI which does not use any frame pointer. (In the previous version of this system, the old APCS AB was used on ARM 7, which had the forced stack frame and frame pointer and one backstrasse, which worked perfectly).

The entire system has been compiled -fessation, the required metadata ensures that _Unwind is included in the ELF file. (_Unwind is designed to deal with the exceptions I think).

So, my question is: Is using GCC a "standard" assuming reliable batteries in embedded systems?

I do not need to mess with the linker scripts and the CRT0 code, if necessary, but there is no need to create any chance on toolchain.

Thank you!

For this, you must have -funwind-tables or -fasynchronous- Unwind-tables in some goals it is necessary to work with _Unwind_Backtrace


Comments

Popular posts from this blog

Eclipse CDT variable colors in editor -

AJAX doesn't send POST query -

wpf - Custom Message Box Advice -