Fix Thread.Start while debugging bug on OSX.
authorMike McLaughlin <mikem@microsoft.com>
Tue, 10 Nov 2015 22:28:10 +0000 (14:28 -0800)
committerMike McLaughlin <mikem@microsoft.com>
Thu, 12 Nov 2015 23:00:10 +0000 (15:00 -0800)
commit9ef5ee736212e95d456cc13f3e1f7ff96db51bef
treeb139014f574836adb77f9c215eb0c8f872cdd4ac
parentb13c844a60d553a6f78eb4b2a2c912a8bc07540f
Fix Thread.Start while debugging bug on OSX.

The OSX exception logic is running on a separate thread from the one that the exception happened. The CatchHardwareExceptionHolder::IsEnabled used to check for h/w exception holders assumed it was running on the thread the exception/holders happened not the exception notification thread. Moved the h/w exception holder count to the CPalThread object instead of a TLS thread variable so the OSX exception code can check it given a CPalThread instance.

The main problem was that the stubmgr when creating a thread (for the start notification) put a breakpoint in ThePreStubPatch which is in the coreclr text section and because the h/w exception holder check was broken, it thought the breakpoint wasn't the debugger's and aborted the coreclr process.  The other part of this fix is to put a h/w exception holder around the called to ThePreStubPatch in prestub.cpp.

The stubmgr's delegate invoke subclass used the wrong registers for Linux/OSX to read the "this" and parameter registers. Added the proper ifdefs and registers (ecx -> rdi, rdx -> rsi) for the Unix platforms.

On both Linux and OSX, the h/w exception holder check in the exception routing logic needed to check if the int3/trap is in DBG_DebugBreak so asserts always abort/core dump. Move DBG_DebugBreak to an assembly worker so the start/end address can be used for this check.
13 files changed:
src/inc/palclr.h
src/pal/src/CMakeLists.txt
src/pal/src/arch/arm/debugbreak.S [new file with mode: 0644]
src/pal/src/arch/arm64/debugbreak.S [new file with mode: 0644]
src/pal/src/arch/i386/debugbreak.S [new file with mode: 0644]
src/pal/src/debug/debug.cpp
src/pal/src/exception/machexception.cpp
src/pal/src/exception/seh.cpp
src/pal/src/include/pal/debug.h
src/pal/src/include/pal/thread.hpp
src/pal/src/thread/context.cpp
src/vm/prestub.cpp
src/vm/stubmgr.cpp