I want to write a debug printing function that prints LINE, FILE, func and some other stuff. The twist is that I'd like to automatically indent the printouts according to their depth in the call stack, so something like
main.c:55:main()
functions.c:33:function1()
functions.c:133:function2()
functions.c:33:function1()
functions.c:33:function1()
if function1 returns immediately, and function2 calls function1 twice.
I guess this could be done by using a global variable which is manually incremented each time a function is called and decremented whenever it is returned, but this would require quite the code base rehaul. I was wondering if there was an easier way to do it?
I don't mind if the solution is non-standard C, so long as it is standard GNU.