A.D.A. Amiga Demoscene Archive

  Welcome guest! Please register a new account or log in




Demos Amiga Demoscene Archive Forum / Coding / Print backtrace from within demo (compiled with vbcc)


Author Message
#1 - Posted: 2 Sep 2017 16:00
Reply Quote
I'd like to print a backtrace from within a demo. For example if there is an error I can call print_backtrace_symbols() and get a debugger style view of call stack with function names etc. GCC or glib comes with such functions called backtrace()/backtrace_symbols(). Also there are utils like addr2line which can translate address to source line. However I can't see anything like this for vbcc.

Did anyone here write this kind of code before?

My guess is what needs to be done is:
1) Add debug symbols
2) Parse stack matching return addresses with the debug symbol info

------- Problem 1

Currently I've enabled the -g option for vbcc to get debug symbols. I can see symbols and some argument info is present by hexdump of the object file. However I don't know what kind of format it really is and when linking I'm getting lots of errors like:

Error 21: cctab.o (.debug_info+0x2a91): Reference to undefined symbol l1519.

I've tried to disable any kind of optimization that I theorized may strip compiler generated labels such as the one above, but so far no luck..

------- Problem 2

What does the stack frame look like on amiga? Is there a standard or is it compiler dependent. I heard some rough info like d0/d1/a0/a1 should be used for the first few arguments and then the rest of the arguments will be on stack, however would be nice with a doc which describes it precisely.

I could just scan the whole stack and print whenever there is a value which matches a function address as found in the debug_symbols as a start though.
#2 - Posted: 3 Sep 2017 14:36
Reply Quote
Upgrading vbcc got rid of the error in problem 1. Additionally the compiler injects prologue and epilogue when the profiling option is added. This adds the function names to the source code. By using the power of open source I can change the compiler to inject some additional code to create a trail of function names which could be printed on error.


  Please register a new account or log in to comment





A.D.A. Amiga Demoscene Archive, Version 3.0