[Mono-dev] MSVC compiled mono_jit_walk_stack problems

Sebastien Pouliot sebastien.pouliot at gmail.com
Tue Jan 17 13:23:28 EST 2006


Hello Aras,

On Tue, 2006-01-17 at 19:02 +0100, Aras Pranckevicius wrote:
> Just got libgc/libmono compiling under microsoft VC7/VC8 (wasn't that
> hard), but I'm having problems with mono_jit_walk_stack.
> 
> Basically, it uses MONO_INIT_CONTEXT_FROM_CALLER, which for MSVC is
> defined as inline assembly using ebp register:
>     unsigned int stackptr, retaddr;
>     {
>         __asm mov stackptr, ebp
>         __asm mov eax, DWORD PTR [ebp + 4]
>         __asm mov retaddr, eax
>     }
> 
> As such, it requires the compiler to maintain "frame pointers" via
> ebp. The problem is, MSVC in default "optimize for speed" mode quite
> often omits them - the result is that ebp is often zero, and this code
> tries to read from memory location 0x4 - a segfault.

The VS2005 solution file (in Mono's SVN) only "works" for the DEBUG
targets - i.e. it was never (at least by me) tested under "Release" or
with any optimization enabled.

> At the moment I've forced MSVC to maintain frame pointers for the
> whole mini-exceptions.c file: placed
>     #ifdef _MSC_VER
>     #pragma optimize("y",off)
>     #endif
> at beginning and
>     #ifdef _MSC_VER
>     #pragma optimize("",on)
>     #endif
> at the end of it.
> 
> However, I'm not sure if that produces the correct results for stack
> walking (but it gets rid of segfault).

It's not 100% correct as there are other issues as well. See the known
issues section of the README.vsnet file
http://svn.myrealbox.com/viewcvs/trunk/mono/README.vsnet?view=markup

But it works well enough for debugging purposes :-)

> The stack walk is a result of calling mono_method_get_last_managed,
> which our codebase uses to do something with mono exceptions.
-- 
Sebastien Pouliot  <sebastien at ximian.com>
Blog: http://pages.infinit.net/ctech/




More information about the Mono-devel-list mailing list