Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Stack overflow in unmanaged: IP: 0x26eb76, fault addr: 0xbf808ffc

My Mono application crashes on Mac with this message (Full log):

$ mono --debug bin/Debug/SparkleShare.app/Contents/MonoBundle/SparkleShare.exe
[...]
Stack overflow in unmanaged: IP: 0x26eb76, fault addr: 0xbf808ffc
[...]

"in unmanaged" implies that the stack overflow is not in my code (I only have managed code) but rather in a library I embed (SQLite, DotCmis, NewtonSoft.Json) or in Mono's code.

Even though I compile and run in Debug mode, all I get is these two hexadecimals.

QUESTION: How can I investigate this stack overflow? Any trick?

Note: The same libraries (with pretty much the same code) run fine on Linux and Windows.

like image 821
Nicolas Raoul Avatar asked Dec 03 '12 11:12

Nicolas Raoul


1 Answers

Handling stack overflow is quite tricky (for mono), so it might very well be that the stack overflow is actually yours. The problem lies in figuring out the stack trace.

I usually run with gdb:

gdb --args mono --debug bin/Debug/SparkleShare.app/Contents/MonoBundle/SparkleShare.exe

And then try to hit Ctrl+C after the stack has begun to grow, but before it has actually overflown (gdb gets seriously confused with stack overflows, and you'll usually have to exit gdb when that happens, which is why you'll need to catch the overflow in action).

After hitting Ctrl+C, do a thread apply all backtrace, and you'll know if a stack overflow is about to happen (one thread will have thousands of frames).

Once you have an enormous stack trace in gdb, you need to identify the cycle. This is usually quite easy just by looking at the addresses of the stack trace. Once you have this data, you can get the managed frame like this:

(gdb) p mono_pmip (0xdeaddead)
$1 = 0x0000dead  "Managed frame information shows up here"

Then just do the same for all the frames in the cycle you found.

There are more tips for debugging mono with gdb here.

like image 77
Rolf Bjarne Kvinge Avatar answered Sep 19 '22 14:09

Rolf Bjarne Kvinge