3

I'm having problems with stack overflows and would like to see exactly what the contents on the stack are.

How can I examine the stack frame with GDB? is kind of the same question, however info locals looks fine here (few variables, most of them std::vectors and std::maps), so I wouldn't expect the stack to overflow from this. Moreover, I have set the stack limit to 32MB, so this should be plenty and no recursive functions are used.

Is there a tool that can show the complete contents of the stack, maybe ordered by size?

Community
  • 1
  • 1
bbtrb
  • 4,065
  • 2
  • 25
  • 30
  • 1
    It sounds like you don't actually have a stack overflow. What makes you think you do? –  May 24 '11 at 21:24
  • @Neil: please look at my related question: http://stackoverflow.com/questions/6084901/stackoverflow-and-function-pointers. Increasing the stack size helps indeed, but doesn't really cure the root of problem – bbtrb May 25 '11 at 00:27

4 Answers4

6

Stack overflows are better caught by special profilers rather than manually looking at variables in gdb. It is more likely that you have buffer overrun rather than stack overflow. In either case, here is a list of some profilers that can help you to point out the problem:

Good luck!

1

Even if you have no functions that call themselves, it's possible you've created a situation in which two or more functions are mutually recursive.

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

Nick Meyer
  • 39,212
  • 14
  • 67
  • 75
0

You can examine the current stack frame using the backtrace command.

Jon Trauntvein
  • 4,453
  • 6
  • 39
  • 69
0

You can also get the current stack pointer in gdb (e.g., by running 'info registers') and then dump the memory around that location using the examine (or 'x') command. Just be aware that the stack pointer points below the stack, so you need to start dumping from stack pointer - N to see the first N bytes on the stack.

BjoernD
  • 4,720
  • 27
  • 32