Improve unwind support on Windows x64.
authorlateralusX <lateralusx.github@gmail.com>
Thu, 2 Feb 2017 11:51:17 +0000 (12:51 +0100)
committerlateralusX <lateralusx.github@gmail.com>
Tue, 28 Feb 2017 13:52:41 +0000 (14:52 +0100)
commitd135465fba59f7257e2d225564df7c601015fee8
tree5fddfacfe326049daa9cae7c622b3830c22411d5
parentd899b02874a476290f6e8cd54d40e0eaba2ecf04
Improve unwind support on Windows x64.

This commit improves the unwind support on Windows x64 by implementing a number
of missing features. It also adds support for out of proc function table callback
module on older OS versions and switch to different function table methods
(growable function tables) on Win8/Win2012Server and later OS versions.

Commit aligns more to the windows x64 prolog/epilog ABI, but since mono
uses negative offsets from frame pointer while x64 windows uses positive, it is
not possible to do a 100% "correct" representation in the prolog, but if we don’t
give the OS unwinder the full unwind metadata in the frame pointer use case,
we can trick unwinder to do the right thing presenting correct callstacks in
debuggers.

Commit includes representation of windows unwind info in mono's unwind data
using extensions to better integrate windows specific unwind info in
areas currently not supported (like trampolines). It will also be easier to implement
unwind info in full AOT objects in the future, if windows specific unwind data is
included in mono’s unwind data structures.

On Win8/Win2012Server and later OS versions, all function table data is registered
using growable function tables giving full support for callstacks on live debug targets
and crash dumps. On previous OS versions function table callbacks are used together
with an out of proc module. This works for live debugging in WinDBG and Visual Studio
(if right permissions are given to the debuggers to load out of proc unwind module).
Crash dumps works as expected in WinDBG but currently not in Visual Studio for older OS
versions using callback support. If that use case needs to be supported it needs to be
solved in a separate PR, but since we support crash dumps in Visual Studio on later OS
versions and in WinDBG on earlier, it is still possible to analyze crash dumps by picking
the right tool.

Debuggers needs some additional information to work with function table callbacks out of proc
modules (NOTE, this is NOT needed on Win8/Win2012Server and later).

WinDBG:

To just do live debugging, it is possible to run the following command in WinDBG,

settings set EngineInitialization.VerifyFunctionTableCallbacks=false

To do crash dump analysis the following registry key needs to be set,

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\KnownFunctionTableDlls

Add the full path to mono-2.0-dac-sgen.dll matching the mono-2.0-sgen.dll as a 32-bit REG_DWORD.

NOTE, adding the registry key removes the need to set the setting.

Visual Studio:

To do live debugging, set the same registry key as WinDBG use case.
17 files changed:
eglib/winconfig.h
mono/mini/Makefile.am.in
mono/mini/aot-compiler.c
mono/mini/exceptions-amd64.c
mono/mini/mini-amd64.c
mono/mini/mini-amd64.h
mono/mini/mini-runtime.c
mono/mini/mini-unwind.h
mono/mini/mini-windows-dlldac.c [new file with mode: 0644]
mono/mini/mini.c
mono/mini/tramp-amd64-gsharedvt.c
mono/mini/tramp-amd64.c
mono/mini/unwind.c
msvc/libmonodac.vcxproj [new file with mode: 0644]
msvc/libmonodac.vcxproj.filters [new file with mode: 0644]
msvc/mono.sln
winconfig.h