How do I print functions as they are called?

You can do this with a trace function (props to Spacedman for improving the original version of this to trace returns and use some nice indenting): def tracefunc(frame, event, arg, indent=[0]): if event == “call”: indent[0] += 2 print(“-” * indent[0] + “> call function”, frame.f_code.co_name) elif event == “return”: print(“<” + “-” * indent[0], … Read more

Android Studio – Where can I see callstack while debugging an android app?

Seems like there is an UI-Bug in the Android Studio (1.x, 2.x and 3.x). For me the “Frames/Threads” Panel was completely hidden behind the toolbar, so I had to change the size from the “variable” panel by dragging its left border to reveal the “Frames/Threads”. [I have to admit, that @Greg added this picture after … Read more

What causes a java.lang.StackOverflowError

Check for any recusive calls for methods. Mainly it is caused when there is recursive call for a method. A simple example is public static void main(String… args) { Main main = new Main(); main.testMethod(1); } public void testMethod(int i) { testMethod(i); System.out.println(i); } Here the System.out.println(i); will be repeatedly pushed to stack when the … Read more

How exactly does the callstack work?

The call stack could also be called a frame stack. The things that are stacked after the LIFO principle are not the local variables but the entire stack frames (“calls”) of the functions being called. The local variables are pushed and popped together with those frames in the so-called function prologue and epilogue, respectively. Inside … Read more

print call stack in C or C++

For a linux-only solution you can use backtrace(3) that simply returns an array of void * (in fact each of these point to the return address from the corresponding stack frame). To translate these to something of use, there’s backtrace_symbols(3). Pay attention to the notes section in backtrace(3): The symbol names may be unavailable without … Read more