Learning stack

I had problems with stack overflow and would like to know exactly what the contents of the stack are.

How to check stack stack with gdb? is the same question, but info localsit looks great (several variables, most of them std :: vectors and std :: maps), so I did not expect the stack to jump from this. Moreover, I set the stack limit to 32 MB, so it should be a lot, and recursive functions are not used.

Is there a tool that can display the full contents of the stack, possibly sorted by size?

+3
source share
4 answers

Stack overflows are better caught by special profilers, rather than manually looking at variables in gdb. Most likely you have a buffer overflow, not a stack overflow. Anyway, here is a list of some profilers that can help you point out a problem:

Good luck

+5
source

Even if you do not have functions that call themselves, you may have created a situation in which two or more functions are mutually recursive.

A good starting point would be to consider not the current stack frame, but a list of stack frames using the "backtrace" command (or "bt" for short). If you see a repeated circuit of two or more functions that call each other, then you have mutual recursion.

+1

backtrace.

0
source

You can also get the current stack pointer in gdb (for example, by running "information registers"), and then unload the memory around this location with the check command (or "x"). Just keep in mind that the stack pointer is below the stack, so you need to start flushing from the stack pointer - N to see the first N bytes on the stack.

0
source

All Articles