Update patches for coreclr
authorDmitry Kovalenko <d.kovalenko@samsung.com>
Mon, 5 Feb 2018 09:00:39 +0000 (12:00 +0300)
committerDmitry Kovalenko <d.kovalenko@samsung.com>
Mon, 5 Feb 2018 09:10:16 +0000 (12:10 +0300)
patches for review.tizen.org:29418/platform/upstream/coreclr:58c98ea

Signed-off-by: Dmitry Kovalenko <d.kovalenko@samsung.com>
patches/coreclr/0001-Add-more-stuff-to-devel-package-for-debugger.patch [deleted file]
patches/coreclr/0001-Add-patch-for-breakpoints-on-ARM.patch [new file with mode: 0644]
patches/coreclr/0002-Add-patch-for-breakpoints-on-ARM.patch [deleted file]
patches/coreclr/0002-Enable-Debug-IPC.patch [new file with mode: 0644]
patches/coreclr/0003-Add-patch-for-undefined-references-in-SOS.patch [new file with mode: 0644]
patches/coreclr/0003-Enable-Debug-IPC.patch [deleted file]
patches/coreclr/0004-Add-patch-for-undefined-references-in-SOS.patch [deleted file]
patches/coreclr/0004-Fix-SetDebuggerREGDISPLAYFromREGDISPLAY-function-on-.patch [new file with mode: 0644]
patches/coreclr/0005-Fix-SetDebuggerREGDISPLAYFromREGDISPLAY-function-on-.patch [deleted file]

diff --git a/patches/coreclr/0001-Add-more-stuff-to-devel-package-for-debugger.patch b/patches/coreclr/0001-Add-more-stuff-to-devel-package-for-debugger.patch
deleted file mode 100644 (file)
index ed09300..0000000
+++ /dev/null
@@ -1,53 +0,0 @@
-From 73063a5586b8dadf5b8f651fc792cfbbeace2392 Mon Sep 17 00:00:00 2001
-From: Igor Kulaychuk <i.kulaychuk@samsung.com>
-Date: Thu, 24 Aug 2017 23:31:36 +0300
-Subject: [PATCH 1/5] Add more stuff to devel package for debugger
-
----
- packaging/coreclr.spec | 21 ++++++++++++++-------
- 1 file changed, 14 insertions(+), 7 deletions(-)
-
-diff --git a/packaging/coreclr.spec b/packaging/coreclr.spec
-index 46211a0..226c6d7 100644
---- a/packaging/coreclr.spec
-+++ b/packaging/coreclr.spec
-@@ -302,11 +302,20 @@ ln -sf ../%{netcoreappdir}/corerun    %{buildroot}%{_datadir}/%{dotnetdir}/corer
- # .NET Core Headers and static libraries
- mkdir -p %{buildroot}%{_datadir}/%{netcoreappdir}/src/pal/src/
--cp -rf %{_reldir}/inc %{buildroot}%{_datadir}/%{netcoreappdir}/
--cp -rf src/inc %{buildroot}%{_datadir}/%{netcoreappdir}/src/
--cp -rf src/pal/inc %{buildroot}%{_datadir}/%{netcoreappdir}/src/pal/
--cp -rf %{_reldir}/lib %{buildroot}%{_datadir}/%{netcoreappdir}
--cp -rf src/pal/src/include %{buildroot}%{_datadir}/%{netcoreappdir}/src/pal/src
-+mkdir -p %{buildroot}%{_datadir}/%{netcoreappdir}/src/debug/
-+mkdir -p %{buildroot}%{_datadir}/%{netcoreappdir}/src/dlls/
-+mkdir -p %{buildroot}%{_datadir}/%{netcoreappdir}/src/coreclr/hosts/
-+mkdir -p %{buildroot}%{_datadir}/%{netcoreappdir}/src/ToolBox/SOS/
-+cp -rf src/inc                %{buildroot}%{_datadir}/%{netcoreappdir}/src/
-+cp -rf src/pal/inc            %{buildroot}%{_datadir}/%{netcoreappdir}/src/pal/
-+cp -rf src/pal/prebuilt       %{buildroot}%{_datadir}/%{netcoreappdir}/src/pal/
-+cp -rf src/debug/inc          %{buildroot}%{_datadir}/%{netcoreappdir}/src/debug/
-+cp -rf src/debug/shim         %{buildroot}%{_datadir}/%{netcoreappdir}/src/debug/
-+cp -rf src/dlls/dbgshim       %{buildroot}%{_datadir}/%{netcoreappdir}/src/dlls/
-+cp -rf src/coreclr/hosts/inc  %{buildroot}%{_datadir}/%{netcoreappdir}/src/coreclr/hosts/
-+cp -rf src/ToolBox/SOS/Strike %{buildroot}%{_datadir}/%{netcoreappdir}/src/ToolBox/SOS
-+cp -rf src/pal/src/include    %{buildroot}%{_datadir}/%{netcoreappdir}/src/pal/src
-+cp -rf %{_reldir}/lib         %{buildroot}%{_datadir}/%{netcoreappdir}
- # make link for .NET CoreOverlay
- ln -sf ../%{netcoreappdir}/corerun          %{buildroot}%{_datadir}/%{tizennetdir}
-@@ -368,10 +377,8 @@ ln -sf ../%{netcoreappdir}/SOS.NETCore.dll     %{buildroot}%{_datadir}/%{tizenne
- %files devel
- %manifest %{name}.manifest
--%dir %{_datadir}/%{netcoreappdir}/inc
- %dir %{_datadir}/%{netcoreappdir}/lib
- %dir %{_datadir}/%{netcoreappdir}/src
--%{_datadir}/%{netcoreappdir}/inc/*
- %{_datadir}/%{netcoreappdir}/lib/*
- %{_datadir}/%{netcoreappdir}/src/*
- %endif
--- 
-2.7.4
-
diff --git a/patches/coreclr/0001-Add-patch-for-breakpoints-on-ARM.patch b/patches/coreclr/0001-Add-patch-for-breakpoints-on-ARM.patch
new file mode 100644 (file)
index 0000000..e4fd36a
--- /dev/null
@@ -0,0 +1,184 @@
+From c62d48577e6562996b1c1ab74d3f125b3262672a Mon Sep 17 00:00:00 2001
+From: Igor Kulaychuk <i.kulaychuk@samsung.com>
+Date: Mon, 5 Feb 2018 11:08:09 +0300
+Subject: [PATCH 1/4] Add patch for breakpoints on ARM
+
+Signed-off-by: Igor Kulaychuk <i.kulaychuk@samsung.com>
+Signed-off-by: Dmitry Kovalenko <d.kovalenko@samsung.com>
+---
+ packaging/coreclr.spec              |   4 +-
+ packaging/fix-arm-breakpoints.patch | 133 ++++++++++++++++++++++++++++++++++++
+ 2 files changed, 136 insertions(+), 1 deletion(-)
+ create mode 100644 packaging/fix-arm-breakpoints.patch
+
+diff --git a/packaging/coreclr.spec b/packaging/coreclr.spec
+index 89fd3047..013a4c2a 100644
+--- a/packaging/coreclr.spec
++++ b/packaging/coreclr.spec
+@@ -23,7 +23,7 @@ Source1000: downloaded_files.tar.gz
+ Source1001: %{name}.manifest
+ Source1002: libicu.tar.gz
+ Source1003: dep_libs.tar.gz
+-# Gbp-Ignore-Patches: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
++# Gbp-Ignore-Patches: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
+ Patch0:     0001-Add-project.assets.json-files.patch
+ Patch1:     0001-ARM-Linux-Support-unaligned-struct-read-write-11290.patch
+ Patch2:     0002-x86-Linux-Thread-safe-UMThunkMarshInfo-RunTimeInit-1.patch
+@@ -62,6 +62,7 @@ Patch34:     0001-Fix-assert-in-HelperMethodFrame-UpdateRegDisplay-142.patch
+ Patch35:     0001-Fix-clrstack-command-of-lldb-sosplugin-on-x86-13973.patch
+ Patch36:     0001-Fix-typo-in-SetDebuggerREGDISPLAYFromREGDISPLAY-1422.patch
+ Patch37:     0001-Use-addresses-without-sign-extension-in-lldb-plugin-.patch
++Patch38:     fix-arm-breakpoints.patch
+ ExcludeArch: aarch64
+@@ -204,6 +205,7 @@ cp %{SOURCE1001} .
+ %patch35 -p1
+ %patch36 -p1
+ %patch37 -p1
++%patch38 -p1
+ %if 0%{skipmscorlib}
+ %else
+diff --git a/packaging/fix-arm-breakpoints.patch b/packaging/fix-arm-breakpoints.patch
+new file mode 100644
+index 00000000..092a4e39
+--- /dev/null
++++ b/packaging/fix-arm-breakpoints.patch
+@@ -0,0 +1,133 @@
++diff --git a/src/debug/inc/arm/primitives.h b/src/debug/inc/arm/primitives.h
++index 0bac542..1cceeff 100644
++--- a/src/debug/inc/arm/primitives.h
+++++ b/src/debug/inc/arm/primitives.h
++@@ -30,7 +30,11 @@ typedef DPTR(CORDB_ADDRESS_TYPE)    PTR_CORDB_ADDRESS_TYPE;
++ #define STACKWALK_CONTROLPC_ADJUST_OFFSET 2
++ 
++ #define CORDbg_BREAK_INSTRUCTION_SIZE 2
+++#ifdef __linux__
+++#define CORDbg_BREAK_INSTRUCTION (USHORT)0xde01
+++#else
++ #define CORDbg_BREAK_INSTRUCTION (USHORT)0xdefe
+++#endif
++ 
++ inline CORDB_ADDRESS GetPatchEndAddr(CORDB_ADDRESS patchAddr)
++ {
++diff --git a/src/vm/arm/armsinglestepper.cpp b/src/vm/arm/armsinglestepper.cpp
++index e000959..bfe8824 100644
++--- a/src/vm/arm/armsinglestepper.cpp
+++++ b/src/vm/arm/armsinglestepper.cpp
++@@ -97,17 +97,25 @@ ArmSingleStepper::ArmSingleStepper()
++ 
++ ArmSingleStepper::~ArmSingleStepper()
++ {
++-#if !defined(DACCESS_COMPILE) && !defined(FEATURE_PAL)
+++#if !defined(DACCESS_COMPILE)
+++#ifdef FEATURE_PAL
+++    SystemDomain::GetGlobalLoaderAllocator()->GetExecutableHeap()->BackoutMem(m_rgCode, kMaxCodeBuffer * sizeof(WORD));
+++#else
++     DeleteExecutable(m_rgCode);
++ #endif
+++#endif
++ }
++ 
++ void ArmSingleStepper::Init()
++ {
++-#if !defined(DACCESS_COMPILE) && !defined(FEATURE_PAL)
+++#if !defined(DACCESS_COMPILE)
++     if (m_rgCode == NULL)
++     {
+++#ifdef FEATURE_PAL
+++        m_rgCode = (WORD *)(void *)SystemDomain::GetGlobalLoaderAllocator()->GetExecutableHeap()->AllocMem(S_SIZE_T(kMaxCodeBuffer * sizeof(WORD)));
+++#else
++         m_rgCode = new (executable) WORD[kMaxCodeBuffer];
+++#endif
++     }
++ #endif
++ }
++diff --git a/src/vm/arm/cgencpu.h b/src/vm/arm/cgencpu.h
++index 6f128f6..2a369d8 100644
++--- a/src/vm/arm/cgencpu.h
+++++ b/src/vm/arm/cgencpu.h
++@@ -566,7 +566,11 @@ public:
++         // a reasonable breakpoint substitute (it's what DebugBreak uses). Bkpt #0, on the other hand, always
++         // seems to flow directly to the kernel debugger (even if we ignore it there it doesn't seem to be
++         // picked up by the user mode debugger).
+++#ifdef __linux__
+++        Emit16(0xde01);
+++#else
++         Emit16(0xdefe);
+++#endif
++     }
++ 
++     void ThumbEmitMovConstant(ThumbReg dest, int constant)
++diff --git a/src/vm/armsinglestepper.h b/src/vm/armsinglestepper.h
++index 53a1019..8893525 100644
++--- a/src/vm/armsinglestepper.h
+++++ b/src/vm/armsinglestepper.h
++@@ -88,7 +88,11 @@ private:
++         kMaxCodeBuffer = 2 + 3 + 1, // WORD slots in our redirect buffer (2 for current instruction, 3 for
++                                     // breakpoint instructions used to pad out slots in an IT block and one
++                                     // for the final breakpoint)
+++#ifdef __linux__
+++        kBreakpointOp = 0xde01,     // Opcode for the breakpoint instruction used on ARM Linux
+++#else
++         kBreakpointOp = 0xdefe,     // Opcode for the breakpoint instruction used on CoreARM
+++#endif
++     };
++ 
++     // Bit numbers of the condition flags in the CPSR.
++diff --git a/src/vm/exceptionhandling.cpp b/src/vm/exceptionhandling.cpp
++index c6d42ed..a52ccd7 100644
++--- a/src/vm/exceptionhandling.cpp
+++++ b/src/vm/exceptionhandling.cpp
++@@ -5186,6 +5186,38 @@ BOOL IsSafeToHandleHardwareException(PCONTEXT contextRecord, PEXCEPTION_RECORD e
++         IsIPInMarkedJitHelper(controlPc));
++ }
++ 
+++#ifdef _TARGET_ARM_
+++static inline BOOL HandleArmSingleStep(PCONTEXT pContext, PEXCEPTION_RECORD pExceptionRecord, Thread *pThread)
+++{
+++#ifdef __linux__
+++    // On ARM Linux exception point to the break instruction,
+++    // but the rest of the code expects that it points to an instruction after the break
+++    if (pExceptionRecord->ExceptionCode == EXCEPTION_BREAKPOINT)
+++    {
+++        SetIP(pContext, GetIP(pContext) + CORDbg_BREAK_INSTRUCTION_SIZE);
+++        pExceptionRecord->ExceptionAddress = (void *)GetIP(pContext);
+++    }
+++#endif
+++    // On ARM we don't have any reliable hardware support for single stepping so it is emulated in software.
+++    // The implementation will end up throwing an EXCEPTION_BREAKPOINT rather than an EXCEPTION_SINGLE_STEP
+++    // and leaves other aspects of the thread context in an invalid state. Therefore we use this opportunity
+++    // to fixup the state before any other part of the system uses it (we do it here since only the debugger
+++    // uses single step functionality).
+++
+++    // First ask the emulation itself whether this exception occurred while single stepping was enabled. If so
+++    // it will fix up the context to be consistent again and return true. If so and the exception was
+++    // EXCEPTION_BREAKPOINT then we translate it to EXCEPTION_SINGLE_STEP (otherwise we leave it be, e.g. the
+++    // instruction stepped caused an access violation).
+++    if (pThread->HandleSingleStep(pContext, pExceptionRecord->ExceptionCode) && (pExceptionRecord->ExceptionCode == EXCEPTION_BREAKPOINT))
+++    {
+++        pExceptionRecord->ExceptionCode = EXCEPTION_SINGLE_STEP;
+++        pExceptionRecord->ExceptionAddress = (void *)GetIP(pContext);
+++        return TRUE;
+++    }
+++    return FALSE;
+++}
+++#endif // _TARGET_ARM_
+++
++ BOOL HandleHardwareException(PAL_SEHException* ex)
++ {
++     _ASSERTE(IsSafeToHandleHardwareException(ex->GetContextRecord(), ex->GetExceptionRecord()));
++@@ -5249,6 +5281,9 @@ BOOL HandleHardwareException(PAL_SEHException* ex)
++         Thread *pThread = GetThread();
++         if (pThread != NULL && g_pDebugInterface != NULL)
++         {
+++#ifdef _TARGET_ARM_
+++            HandleArmSingleStep(ex->GetContextRecord(), ex->GetExceptionRecord(), pThread);
+++#endif
++             if (ex->GetExceptionRecord()->ExceptionCode == STATUS_BREAKPOINT)
++             {
++                 // If this is breakpoint context, it is set up to point to an instruction after the break instruction.
+-- 
+2.13.6
+
diff --git a/patches/coreclr/0002-Add-patch-for-breakpoints-on-ARM.patch b/patches/coreclr/0002-Add-patch-for-breakpoints-on-ARM.patch
deleted file mode 100644 (file)
index 3bd3dd2..0000000
+++ /dev/null
@@ -1,182 +0,0 @@
-From cf1d582145e4ae064593b4d351b60477e0673299 Mon Sep 17 00:00:00 2001
-From: Igor Kulaychuk <i.kulaychuk@samsung.com>
-Date: Thu, 24 Aug 2017 23:39:57 +0300
-Subject: [PATCH 2/5] Add patch for breakpoints on ARM
-
----
- packaging/coreclr.spec              |   4 +-
- packaging/fix-arm-breakpoints.patch | 133 ++++++++++++++++++++++++++++++++++++
- 2 files changed, 136 insertions(+), 1 deletion(-)
- create mode 100644 packaging/fix-arm-breakpoints.patch
-
-diff --git a/packaging/coreclr.spec b/packaging/coreclr.spec
-index 226c6d7..81311b1 100644
---- a/packaging/coreclr.spec
-+++ b/packaging/coreclr.spec
-@@ -23,7 +23,7 @@ Source1000: downloaded_files.tar.gz
- Source1001: %{name}.manifest
- Source1002: libicu.tar.gz
- Source1003: dep_libs.tar.gz
--# Gbp-Ignore-Patches: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
-+# Gbp-Ignore-Patches: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
- Patch0:     Add-project.assets.json-files.patch
- Patch1:     Add-Tizen-RuntimeID-case.patch
- Patch2:     Change-O3-build-in-clang3.8.patch
-@@ -43,6 +43,7 @@ Patch15:    0001-Fix-CreateDump-related-undefined-reference-on-non-AM.patch
- Patch16:    0001-ARM-Linux-Enable-DacStackWalk.patch
- Patch17:    profiling.patch
- Patch18:    clear_cache.patch
-+Patch19:    fix-arm-breakpoints.patch
- ExcludeArch: aarch64
-@@ -160,6 +161,7 @@ cp %{SOURCE1001} .
- %patch16 -p1
- %patch17 -p1
- %patch18 -p1
-+%patch19 -p1
- %if 0%{skipmscorlib}
- %else
-diff --git a/packaging/fix-arm-breakpoints.patch b/packaging/fix-arm-breakpoints.patch
-new file mode 100644
-index 0000000..092a4e3
---- /dev/null
-+++ b/packaging/fix-arm-breakpoints.patch
-@@ -0,0 +1,133 @@
-+diff --git a/src/debug/inc/arm/primitives.h b/src/debug/inc/arm/primitives.h
-+index 0bac542..1cceeff 100644
-+--- a/src/debug/inc/arm/primitives.h
-++++ b/src/debug/inc/arm/primitives.h
-+@@ -30,7 +30,11 @@ typedef DPTR(CORDB_ADDRESS_TYPE)    PTR_CORDB_ADDRESS_TYPE;
-+ #define STACKWALK_CONTROLPC_ADJUST_OFFSET 2
-+ 
-+ #define CORDbg_BREAK_INSTRUCTION_SIZE 2
-++#ifdef __linux__
-++#define CORDbg_BREAK_INSTRUCTION (USHORT)0xde01
-++#else
-+ #define CORDbg_BREAK_INSTRUCTION (USHORT)0xdefe
-++#endif
-+ 
-+ inline CORDB_ADDRESS GetPatchEndAddr(CORDB_ADDRESS patchAddr)
-+ {
-+diff --git a/src/vm/arm/armsinglestepper.cpp b/src/vm/arm/armsinglestepper.cpp
-+index e000959..bfe8824 100644
-+--- a/src/vm/arm/armsinglestepper.cpp
-++++ b/src/vm/arm/armsinglestepper.cpp
-+@@ -97,17 +97,25 @@ ArmSingleStepper::ArmSingleStepper()
-+ 
-+ ArmSingleStepper::~ArmSingleStepper()
-+ {
-+-#if !defined(DACCESS_COMPILE) && !defined(FEATURE_PAL)
-++#if !defined(DACCESS_COMPILE)
-++#ifdef FEATURE_PAL
-++    SystemDomain::GetGlobalLoaderAllocator()->GetExecutableHeap()->BackoutMem(m_rgCode, kMaxCodeBuffer * sizeof(WORD));
-++#else
-+     DeleteExecutable(m_rgCode);
-+ #endif
-++#endif
-+ }
-+ 
-+ void ArmSingleStepper::Init()
-+ {
-+-#if !defined(DACCESS_COMPILE) && !defined(FEATURE_PAL)
-++#if !defined(DACCESS_COMPILE)
-+     if (m_rgCode == NULL)
-+     {
-++#ifdef FEATURE_PAL
-++        m_rgCode = (WORD *)(void *)SystemDomain::GetGlobalLoaderAllocator()->GetExecutableHeap()->AllocMem(S_SIZE_T(kMaxCodeBuffer * sizeof(WORD)));
-++#else
-+         m_rgCode = new (executable) WORD[kMaxCodeBuffer];
-++#endif
-+     }
-+ #endif
-+ }
-+diff --git a/src/vm/arm/cgencpu.h b/src/vm/arm/cgencpu.h
-+index 6f128f6..2a369d8 100644
-+--- a/src/vm/arm/cgencpu.h
-++++ b/src/vm/arm/cgencpu.h
-+@@ -566,7 +566,11 @@ public:
-+         // a reasonable breakpoint substitute (it's what DebugBreak uses). Bkpt #0, on the other hand, always
-+         // seems to flow directly to the kernel debugger (even if we ignore it there it doesn't seem to be
-+         // picked up by the user mode debugger).
-++#ifdef __linux__
-++        Emit16(0xde01);
-++#else
-+         Emit16(0xdefe);
-++#endif
-+     }
-+ 
-+     void ThumbEmitMovConstant(ThumbReg dest, int constant)
-+diff --git a/src/vm/armsinglestepper.h b/src/vm/armsinglestepper.h
-+index 53a1019..8893525 100644
-+--- a/src/vm/armsinglestepper.h
-++++ b/src/vm/armsinglestepper.h
-+@@ -88,7 +88,11 @@ private:
-+         kMaxCodeBuffer = 2 + 3 + 1, // WORD slots in our redirect buffer (2 for current instruction, 3 for
-+                                     // breakpoint instructions used to pad out slots in an IT block and one
-+                                     // for the final breakpoint)
-++#ifdef __linux__
-++        kBreakpointOp = 0xde01,     // Opcode for the breakpoint instruction used on ARM Linux
-++#else
-+         kBreakpointOp = 0xdefe,     // Opcode for the breakpoint instruction used on CoreARM
-++#endif
-+     };
-+ 
-+     // Bit numbers of the condition flags in the CPSR.
-+diff --git a/src/vm/exceptionhandling.cpp b/src/vm/exceptionhandling.cpp
-+index c6d42ed..a52ccd7 100644
-+--- a/src/vm/exceptionhandling.cpp
-++++ b/src/vm/exceptionhandling.cpp
-+@@ -5186,6 +5186,38 @@ BOOL IsSafeToHandleHardwareException(PCONTEXT contextRecord, PEXCEPTION_RECORD e
-+         IsIPInMarkedJitHelper(controlPc));
-+ }
-+ 
-++#ifdef _TARGET_ARM_
-++static inline BOOL HandleArmSingleStep(PCONTEXT pContext, PEXCEPTION_RECORD pExceptionRecord, Thread *pThread)
-++{
-++#ifdef __linux__
-++    // On ARM Linux exception point to the break instruction,
-++    // but the rest of the code expects that it points to an instruction after the break
-++    if (pExceptionRecord->ExceptionCode == EXCEPTION_BREAKPOINT)
-++    {
-++        SetIP(pContext, GetIP(pContext) + CORDbg_BREAK_INSTRUCTION_SIZE);
-++        pExceptionRecord->ExceptionAddress = (void *)GetIP(pContext);
-++    }
-++#endif
-++    // On ARM we don't have any reliable hardware support for single stepping so it is emulated in software.
-++    // The implementation will end up throwing an EXCEPTION_BREAKPOINT rather than an EXCEPTION_SINGLE_STEP
-++    // and leaves other aspects of the thread context in an invalid state. Therefore we use this opportunity
-++    // to fixup the state before any other part of the system uses it (we do it here since only the debugger
-++    // uses single step functionality).
-++
-++    // First ask the emulation itself whether this exception occurred while single stepping was enabled. If so
-++    // it will fix up the context to be consistent again and return true. If so and the exception was
-++    // EXCEPTION_BREAKPOINT then we translate it to EXCEPTION_SINGLE_STEP (otherwise we leave it be, e.g. the
-++    // instruction stepped caused an access violation).
-++    if (pThread->HandleSingleStep(pContext, pExceptionRecord->ExceptionCode) && (pExceptionRecord->ExceptionCode == EXCEPTION_BREAKPOINT))
-++    {
-++        pExceptionRecord->ExceptionCode = EXCEPTION_SINGLE_STEP;
-++        pExceptionRecord->ExceptionAddress = (void *)GetIP(pContext);
-++        return TRUE;
-++    }
-++    return FALSE;
-++}
-++#endif // _TARGET_ARM_
-++
-+ BOOL HandleHardwareException(PAL_SEHException* ex)
-+ {
-+     _ASSERTE(IsSafeToHandleHardwareException(ex->GetContextRecord(), ex->GetExceptionRecord()));
-+@@ -5249,6 +5281,9 @@ BOOL HandleHardwareException(PAL_SEHException* ex)
-+         Thread *pThread = GetThread();
-+         if (pThread != NULL && g_pDebugInterface != NULL)
-+         {
-++#ifdef _TARGET_ARM_
-++            HandleArmSingleStep(ex->GetContextRecord(), ex->GetExceptionRecord(), pThread);
-++#endif
-+             if (ex->GetExceptionRecord()->ExceptionCode == STATUS_BREAKPOINT)
-+             {
-+                 // If this is breakpoint context, it is set up to point to an instruction after the break instruction.
--- 
-2.7.4
-
diff --git a/patches/coreclr/0002-Enable-Debug-IPC.patch b/patches/coreclr/0002-Enable-Debug-IPC.patch
new file mode 100644 (file)
index 0000000..fa8fa38
--- /dev/null
@@ -0,0 +1,34 @@
+From e572cf64fed4ac7bdf574a504f68424a8cc14baf Mon Sep 17 00:00:00 2001
+From: Igor Kulaychuk <i.kulaychuk@samsung.com>
+Date: Thu, 24 Aug 2017 23:44:38 +0300
+Subject: [PATCH 2/4] Enable Debug IPC
+
+---
+ packaging/coreclr.spec | 4 ++--
+ 1 file changed, 2 insertions(+), 2 deletions(-)
+
+diff --git a/packaging/coreclr.spec b/packaging/coreclr.spec
+index 013a4c2a..71cc6083 100644
+--- a/packaging/coreclr.spec
++++ b/packaging/coreclr.spec
+@@ -304,7 +304,7 @@ export PAL_DBG_CHANNELS=""
+ # No build native and mscorlib.
+ %else
+ # Build native only.
+-./build.sh %{_barch} %{_buildtype} clang3.8 skipmscorlib skipgenerateversion skipnuget %{testopt} cmakeargs "-DFEATURE_GDBJIT=TRUE -DFEATURE_DBGIPC=0 -DFEATURE_NI_BIND_FALLBACK=false -DCMAKE_C_COMPILER=/usr/bin/clang -DCMAKE_CXX_COMPILER=/usr/bin/clang++"
++./build.sh %{_barch} %{_buildtype} clang3.8 skipmscorlib skipgenerateversion skipnuget %{testopt} cmakeargs "-DFEATURE_GDBJIT=TRUE -DFEATURE_DBGIPC=1 -DFEATURE_NI_BIND_FALLBACK=false -DCMAKE_C_COMPILER=/usr/bin/clang -DCMAKE_CXX_COMPILER=/usr/bin/clang++"
+ %endif
+ %else
+ %if 0%{skipnative}
+@@ -312,7 +312,7 @@ export PAL_DBG_CHANNELS=""
+ ./build.sh %{_barch} %{_buildtype} -skiprestore skipnative skipnuget %{testopt}
+ %else
+ # Build native and mscorlib.
+-./build.sh %{_barch} %{_buildtype} clang3.8 skipgenerateversion -skiprestore skipnuget %{testopt} cmakeargs "-DFEATURE_GDBJIT=TRUE -DFEATURE_DBGIPC=0 -DFEATURE_NI_BIND_FALLBACK=false -DCMAKE_C_COMPILER=/usr/bin/clang -DCMAKE_CXX_COMPILER=/usr/bin/clang++"
++./build.sh %{_barch} %{_buildtype} clang3.8 skipgenerateversion -skiprestore skipnuget %{testopt} cmakeargs "-DFEATURE_GDBJIT=TRUE -DFEATURE_DBGIPC=1 -DFEATURE_NI_BIND_FALLBACK=false -DCMAKE_C_COMPILER=/usr/bin/clang -DCMAKE_CXX_COMPILER=/usr/bin/clang++"
+ %endif
+ %endif
+-- 
+2.13.6
+
diff --git a/patches/coreclr/0003-Add-patch-for-undefined-references-in-SOS.patch b/patches/coreclr/0003-Add-patch-for-undefined-references-in-SOS.patch
new file mode 100644 (file)
index 0000000..2ec7167
--- /dev/null
@@ -0,0 +1,318 @@
+From 7ee849fb6359f0f00223e9750a4e4d4550bc5bd6 Mon Sep 17 00:00:00 2001
+From: Igor Kulaychuk <i.kulaychuk@samsung.com>
+Date: Thu, 31 Aug 2017 20:22:56 +0300
+Subject: [PATCH 3/4] Add patch for undefined references in SOS
+
+Signed-off-by: Igor Kulaychuk <i.kulaychuk@samsung.com>
+Signed-off-by: Dmitry Kovalenko <d.kovalenko@samsung.com>
+---
+ packaging/coreclr.spec                          |   2 +
+ packaging/fix-undefined-references-in-sos.patch | 276 ++++++++++++++++++++++++
+ 2 files changed, 278 insertions(+)
+ create mode 100644 packaging/fix-undefined-references-in-sos.patch
+
+diff --git a/packaging/coreclr.spec b/packaging/coreclr.spec
+index 71cc6083..20eda688 100644
+--- a/packaging/coreclr.spec
++++ b/packaging/coreclr.spec
+@@ -63,6 +63,7 @@ Patch35:     0001-Fix-clrstack-command-of-lldb-sosplugin-on-x86-13973.patch
+ Patch36:     0001-Fix-typo-in-SetDebuggerREGDISPLAYFromREGDISPLAY-1422.patch
+ Patch37:     0001-Use-addresses-without-sign-extension-in-lldb-plugin-.patch
+ Patch38:     fix-arm-breakpoints.patch
++Patch39:     fix-undefined-references-in-sos.patch
+ ExcludeArch: aarch64
+@@ -206,6 +207,7 @@ cp %{SOURCE1001} .
+ %patch36 -p1
+ %patch37 -p1
+ %patch38 -p1
++%patch39 -p1
+ %if 0%{skipmscorlib}
+ %else
+diff --git a/packaging/fix-undefined-references-in-sos.patch b/packaging/fix-undefined-references-in-sos.patch
+new file mode 100644
+index 00000000..96d7bcf5
+--- /dev/null
++++ b/packaging/fix-undefined-references-in-sos.patch
+@@ -0,0 +1,276 @@
++diff --git a/src/inc/regdisp.h b/src/inc/regdisp.h
++index a361dca..eb84fdf 100644
++--- a/src/inc/regdisp.h
+++++ b/src/inc/regdisp.h
++@@ -323,6 +323,35 @@ inline void SyncRegDisplayToCurrentContext(REGDISPLAY* pRD)
++ 
++ typedef REGDISPLAY *PREGDISPLAY;
++ 
+++#ifdef WIN64EXCEPTIONS
+++inline void FillContextPointers(PT_KNONVOLATILE_CONTEXT_POINTERS pCtxPtrs, PT_CONTEXT pCtx)
+++{
+++#ifdef _TARGET_AMD64_
+++    for (int i = 0; i < 16; i++)
+++    {
+++        *(&pCtxPtrs->Rax + i) = (&pCtx->Rax + i);
+++    }
+++#elif defined(_TARGET_ARM64_) // _TARGET_AMD64_
+++    for (int i = 0; i < 12; i++)
+++    {
+++        *(&pCtxPtrs->X19 + i) = (&pCtx->X19 + i);
+++    }
+++#elif defined(_TARGET_ARM_) // _TARGET_ARM64_
+++    // Copy over the nonvolatile integer registers (R4-R11)
+++    for (int i = 0; i < 8; i++)
+++    {
+++        *(&pCtxPtrs->R4 + i) = (&pCtx->R4 + i);
+++    }
+++#elif defined(_TARGET_X86_) // _TARGET_ARM_
+++    for (int i = 0; i < 7; i++)
+++    {
+++        *(&pCtxPtrs->Edi + i) = (&pCtx->Edi + i);
+++    }
+++#else // _TARGET_X86_
+++    PORTABILITY_ASSERT("FillContextPointers");
+++#endif // _TARGET_???_ (ELSE)
+++}
+++#endif // WIN64EXCEPTIONS
++ 
++ inline void FillRegDisplay(const PREGDISPLAY pRD, PT_CONTEXT pctx, PT_CONTEXT pCallerCtx = NULL)
++ {
++@@ -374,33 +403,12 @@ inline void FillRegDisplay(const PREGDISPLAY pRD, PT_CONTEXT pctx, PT_CONTEXT pC
++         pRD->IsCallerSPValid      = TRUE;        // Don't add usage of this field.  This is only temporary.
++     }
++ 
++-#ifdef _TARGET_AMD64_
++-    for (int i = 0; i < 16; i++)
++-    {
++-        *(&pRD->ctxPtrsOne.Rax + i) = (&pctx->Rax + i);
++-    }
++-#elif defined(_TARGET_ARM64_) // _TARGET_AMD64_
++-    for (int i = 0; i < 12; i++)
++-    {
++-        *(&pRD->ctxPtrsOne.X19 + i) = (&pctx->X19 + i);
++-    }
++-#elif defined(_TARGET_ARM_) // _TARGET_ARM64_
++-    // Copy over the nonvolatile integer registers (R4-R11)
++-    for (int i = 0; i < 8; i++)
++-    {
++-        *(&pRD->ctxPtrsOne.R4 + i) = (&pctx->R4 + i);
++-    }
+++    FillContextPointers(&pRD->ctxPtrsOne, pctx);
++ 
+++#if defined(_TARGET_ARM_)
++     pRD->ctxPtrsOne.Lr = &pctx->Lr;
++     pRD->pPC = &pRD->pCurrentContext->Pc;
++-#elif defined(_TARGET_X86_) // _TARGET_ARM_
++-    for (int i = 0; i < 7; i++)
++-    {
++-        *(&pRD->ctxPtrsOne.Edi + i) = (&pctx->Edi + i);
++-    }
++-#else // _TARGET_X86_
++-    PORTABILITY_ASSERT("FillRegDisplay");
++-#endif // _TARGET_???_ (ELSE)
+++#endif // _TARGET_ARM_
++ 
++ #ifdef DEBUG_REGDISPLAY
++     pRD->_pThread = NULL;
++diff --git a/src/unwinder/i386/unwinder_i386.cpp b/src/unwinder/i386/unwinder_i386.cpp
++index f221020..42c19cb 100644
++--- a/src/unwinder/i386/unwinder_i386.cpp
+++++ b/src/unwinder/i386/unwinder_i386.cpp
++@@ -8,6 +8,49 @@
++ #include "unwinder_i386.h"
++ 
++ #ifdef WIN64EXCEPTIONS
+++BOOL OOPStackUnwinderX86::Unwind(T_CONTEXT* pContextRecord, T_KNONVOLATILE_CONTEXT_POINTERS* pContextPointers)
+++{
+++    REGDISPLAY rd;
+++
+++    FillRegDisplay(&rd, pContextRecord);
+++
+++    rd.SP = pContextRecord->Esp;
+++    rd.PCTAddr = (UINT_PTR)&(pContextRecord->Eip);
+++
+++    if (pContextPointers)
+++    {
+++        rd.pCurrentContextPointers = pContextPointers;
+++    }
+++
+++    CodeManState codeManState;
+++    codeManState.dwIsSet = 0;
+++
+++    DWORD ControlPc = pContextRecord->Eip;
+++
+++    EECodeInfo codeInfo;
+++    codeInfo.Init((PCODE) ControlPc);
+++
+++    if (!UnwindStackFrame(&rd, &codeInfo, UpdateAllRegs, &codeManState, NULL))
+++    {
+++        return FALSE;
+++    }
+++
+++    pContextRecord->ContextFlags |= CONTEXT_UNWOUND_TO_CALL;
+++
+++#define ARGUMENT_AND_SCRATCH_REGISTER(reg) if (rd.pCurrentContextPointers->reg) pContextRecord->reg = *rd.pCurrentContextPointers->reg;
+++    ENUM_ARGUMENT_AND_SCRATCH_REGISTERS();
+++#undef ARGUMENT_AND_SCRATCH_REGISTER
+++
+++#define CALLEE_SAVED_REGISTER(reg) if (rd.pCurrentContextPointers->reg) pContextRecord->reg = *rd.pCurrentContextPointers->reg;
+++    ENUM_CALLEE_SAVED_REGISTERS();
+++#undef CALLEE_SAVED_REGISTER
+++
+++    pContextRecord->Esp = rd.SP - codeInfo.GetCodeManager()->GetStackParameterSize(&codeInfo);
+++    pContextRecord->Eip = rd.ControlPC;
+++
+++    return TRUE;
+++}
+++
++ /*++
++ 
++ Routine Description:
++@@ -72,42 +115,13 @@ OOPStackUnwinderX86::VirtualUnwind(
++         *HandlerRoutine = NULL;
++     }
++ 
++-    REGDISPLAY rd;
++-
++-    FillRegDisplay(&rd, ContextRecord);
++-
++-    rd.SP = ContextRecord->Esp;
++-    rd.PCTAddr = (UINT_PTR)&(ContextRecord->Eip);
++-
++-    if (ContextPointers)
++-    {
++-        rd.pCurrentContextPointers = ContextPointers;
++-    }
++-
++-    CodeManState codeManState;
++-    codeManState.dwIsSet = 0;
+++    _ASSERTE(ContextRecord->Eip == ControlPc);
++ 
++-    EECodeInfo codeInfo;
++-    codeInfo.Init((PCODE) ControlPc);
++-
++-    if (!UnwindStackFrame(&rd, &codeInfo, UpdateAllRegs, &codeManState, NULL))
+++    if (!OOPStackUnwinderX86::Unwind(ContextRecord, ContextPointers))
++     {
++         return HRESULT_FROM_WIN32(ERROR_READ_FAULT);
++     }
++ 
++-    ContextRecord->ContextFlags |= CONTEXT_UNWOUND_TO_CALL;
++-
++-#define ARGUMENT_AND_SCRATCH_REGISTER(reg) if (rd.pCurrentContextPointers->reg) ContextRecord->reg = *rd.pCurrentContextPointers->reg;
++-    ENUM_ARGUMENT_AND_SCRATCH_REGISTERS();
++-#undef ARGUMENT_AND_SCRATCH_REGISTER
++-
++-#define CALLEE_SAVED_REGISTER(reg) if (rd.pCurrentContextPointers->reg) ContextRecord->reg = *rd.pCurrentContextPointers->reg;
++-    ENUM_CALLEE_SAVED_REGISTERS();
++-#undef CALLEE_SAVED_REGISTER
++-
++-    ContextRecord->Esp = rd.SP - codeInfo.GetCodeManager()->GetStackParameterSize(&codeInfo);
++-    ContextRecord->Eip = rd.ControlPC;
++-
++     // For x86, the value of Establisher Frame Pointer is Caller SP
++     //
++     // (Please refers to CLR ABI for details)
++@@ -115,6 +129,18 @@ OOPStackUnwinderX86::VirtualUnwind(
++     return S_OK;
++ }
++ 
+++BOOL DacUnwindStackFrame(T_CONTEXT* pContextRecord, T_KNONVOLATILE_CONTEXT_POINTERS* pContextPointers)
+++{
+++    BOOL res = OOPStackUnwinderX86::Unwind(pContextRecord, NULL);
+++
+++    if (res && pContextPointers)
+++    {
+++        FillContextPointers(pContextPointers, pContextRecord);
+++    }
+++
+++    return res;
+++}
+++
++ //---------------------------------------------------------------------------------------
++ //
++ // This function behaves like the RtlVirtualUnwind in Windows.
++diff --git a/src/unwinder/i386/unwinder_i386.h b/src/unwinder/i386/unwinder_i386.h
++index bed30bf..f29248f 100644
++--- a/src/unwinder/i386/unwinder_i386.h
+++++ b/src/unwinder/i386/unwinder_i386.h
++@@ -18,6 +18,8 @@
++ class OOPStackUnwinderX86 : public OOPStackUnwinder
++ {
++ public:
+++    static BOOL Unwind(T_CONTEXT* pContextRecord, T_KNONVOLATILE_CONTEXT_POINTERS* pContextPointers);
+++
++     static HRESULT VirtualUnwind(__in DWORD HandlerType,
++         __in DWORD ImageBase,
++         __in DWORD ControlPc,
++diff --git a/src/vm/i386/excepx86.cpp b/src/vm/i386/excepx86.cpp
++index cf01147..9f19d47 100644
++--- a/src/vm/i386/excepx86.cpp
+++++ b/src/vm/i386/excepx86.cpp
++@@ -1953,18 +1953,6 @@ LPVOID STDCALL COMPlusEndCatch(LPVOID ebp, DWORD ebx, DWORD edi, DWORD esi, LPVO
++     return esp;
++ }
++ 
++-#endif // !DACCESS_COMPILE
++-
++-PTR_CONTEXT GetCONTEXTFromRedirectedStubStackFrame(CONTEXT * pContext)
++-{
++-    LIMITED_METHOD_DAC_CONTRACT;
++-    
++-    UINT_PTR stackSlot = pContext->Ebp + REDIRECTSTUB_EBP_OFFSET_CONTEXT;
++-    PTR_PTR_CONTEXT ppContext = dac_cast<PTR_PTR_CONTEXT>((TADDR)stackSlot);
++-    return *ppContext;
++-}
++-
++-#if !defined(DACCESS_COMPILE)
++ PEXCEPTION_REGISTRATION_RECORD GetCurrentSEHRecord()
++ {
++     WRAPPER_NO_CONTRACT;
++@@ -3618,6 +3606,15 @@ EXCEPTION_HANDLER_IMPL(COMPlusFrameHandlerRevCom)
++ #endif // !DACCESS_COMPILE
++ #endif // !WIN64EXCEPTIONS
++ 
+++PTR_CONTEXT GetCONTEXTFromRedirectedStubStackFrame(CONTEXT * pContext)
+++{
+++    LIMITED_METHOD_DAC_CONTRACT;
+++
+++    UINT_PTR stackSlot = pContext->Ebp + REDIRECTSTUB_EBP_OFFSET_CONTEXT;
+++    PTR_PTR_CONTEXT ppContext = dac_cast<PTR_PTR_CONTEXT>((TADDR)stackSlot);
+++    return *ppContext;
+++}
+++
++ #ifndef DACCESS_COMPILE
++ LONG CLRNoCatchHandler(EXCEPTION_POINTERS* pExceptionInfo, PVOID pv)
++ {
++diff --git a/src/vm/virtualcallstub.cpp b/src/vm/virtualcallstub.cpp
++index 01b15c6..e753860 100644
++--- a/src/vm/virtualcallstub.cpp
+++++ b/src/vm/virtualcallstub.cpp
++@@ -1640,6 +1640,13 @@ void VirtualCallStubManager::BackPatchWorkerStatic(PCODE returnAddress, TADDR si
++     END_ENTRYPOINT_VOIDRET;
++ }
++ 
+++#if defined(_TARGET_X86_) && defined(FEATURE_PAL)
+++void BackPatchWorkerStaticStub(PCODE returnAddr, TADDR siteAddrForRegisterIndirect)
+++{
+++    VirtualCallStubManager::BackPatchWorkerStatic(returnAddr, siteAddrForRegisterIndirect);
+++}
+++#endif
+++
++ PCODE VirtualCallStubManager::ResolveWorker(StubCallSite* pCallSite,
++                                             OBJECTREF *protectedObj,
++                                             DispatchToken token,
++@@ -4047,10 +4054,3 @@ BOOL VirtualCallStubManagerManager::TraceManager(
++     // Forward the call to the appropriate manager.
++     return pMgr->TraceManager(thread, trace, pContext, pRetAddr);
++ }
++-
++-#if defined(_TARGET_X86_) && defined(FEATURE_PAL)
++-void BackPatchWorkerStaticStub(PCODE returnAddr, TADDR siteAddrForRegisterIndirect)
++-{
++-    VirtualCallStubManager::BackPatchWorkerStatic(returnAddr, siteAddrForRegisterIndirect);
++-}
++-#endif
+-- 
+2.13.6
+
diff --git a/patches/coreclr/0003-Enable-Debug-IPC.patch b/patches/coreclr/0003-Enable-Debug-IPC.patch
deleted file mode 100644 (file)
index 237abe4..0000000
+++ /dev/null
@@ -1,34 +0,0 @@
-From 7b7b73c5ee5a152597f8547c5dc7d6786dd2938e Mon Sep 17 00:00:00 2001
-From: Igor Kulaychuk <i.kulaychuk@samsung.com>
-Date: Thu, 24 Aug 2017 23:44:38 +0300
-Subject: [PATCH 3/5] Enable Debug IPC
-
----
- packaging/coreclr.spec | 4 ++--
- 1 file changed, 2 insertions(+), 2 deletions(-)
-
-diff --git a/packaging/coreclr.spec b/packaging/coreclr.spec
-index 81311b1..57aedb5 100644
---- a/packaging/coreclr.spec
-+++ b/packaging/coreclr.spec
-@@ -255,7 +255,7 @@ export PAL_DBG_CHANNELS=""
- # No build native and mscorlib.
- %else
- # Build native only.
--./build.sh %{_barch} %{_buildtype} clang3.8 skipmscorlib skipgenerateversion skipnuget %{testopt} cmakeargs "-DFEATURE_GDBJIT=TRUE -DFEATURE_DBGIPC=0 -DFEATURE_NI_BIND_FALLBACK=false -DCMAKE_C_COMPILER=/usr/bin/clang -DCMAKE_CXX_COMPILER=/usr/bin/clang++"
-+./build.sh %{_barch} %{_buildtype} clang3.8 skipmscorlib skipgenerateversion skipnuget %{testopt} cmakeargs "-DFEATURE_GDBJIT=TRUE -DFEATURE_DBGIPC=1 -DFEATURE_NI_BIND_FALLBACK=false -DCMAKE_C_COMPILER=/usr/bin/clang -DCMAKE_CXX_COMPILER=/usr/bin/clang++"
- %endif
- %else
- %if 0%{skipnative}
-@@ -263,7 +263,7 @@ export PAL_DBG_CHANNELS=""
- ./build.sh %{_barch} %{_buildtype} -skiprestore skipnative skipnuget %{testopt}
- %else
- # Build native and mscorlib.
--./build.sh %{_barch} %{_buildtype} clang3.8 skipgenerateversion -skiprestore skipnuget %{testopt} cmakeargs "-DFEATURE_GDBJIT=TRUE -DFEATURE_DBGIPC=0 -DFEATURE_NI_BIND_FALLBACK=false -DCMAKE_C_COMPILER=/usr/bin/clang -DCMAKE_CXX_COMPILER=/usr/bin/clang++"
-+./build.sh %{_barch} %{_buildtype} clang3.8 skipgenerateversion -skiprestore skipnuget %{testopt} cmakeargs "-DFEATURE_GDBJIT=TRUE -DFEATURE_DBGIPC=1 -DFEATURE_NI_BIND_FALLBACK=false -DCMAKE_C_COMPILER=/usr/bin/clang -DCMAKE_CXX_COMPILER=/usr/bin/clang++"
- %endif
- %endif
--- 
-2.7.4
-
diff --git a/patches/coreclr/0004-Add-patch-for-undefined-references-in-SOS.patch b/patches/coreclr/0004-Add-patch-for-undefined-references-in-SOS.patch
deleted file mode 100644 (file)
index 1739f1a..0000000
+++ /dev/null
@@ -1,316 +0,0 @@
-From 84eb6d8886363b7495881717e0d48fbe95ac6ec1 Mon Sep 17 00:00:00 2001
-From: Igor Kulaychuk <i.kulaychuk@samsung.com>
-Date: Thu, 31 Aug 2017 20:22:56 +0300
-Subject: [PATCH 4/5] Add patch for undefined references in SOS
-
----
- packaging/coreclr.spec                          |   2 +
- packaging/fix-undefined-references-in-sos.patch | 276 ++++++++++++++++++++++++
- 2 files changed, 278 insertions(+)
- create mode 100644 packaging/fix-undefined-references-in-sos.patch
-
-diff --git a/packaging/coreclr.spec b/packaging/coreclr.spec
-index 57aedb5..917fbc2 100644
---- a/packaging/coreclr.spec
-+++ b/packaging/coreclr.spec
-@@ -44,6 +44,7 @@ Patch16:    0001-ARM-Linux-Enable-DacStackWalk.patch
- Patch17:    profiling.patch
- Patch18:    clear_cache.patch
- Patch19:    fix-arm-breakpoints.patch
-+Patch20:    fix-undefined-references-in-sos.patch
- ExcludeArch: aarch64
-@@ -162,6 +163,7 @@ cp %{SOURCE1001} .
- %patch17 -p1
- %patch18 -p1
- %patch19 -p1
-+%patch20 -p1
- %if 0%{skipmscorlib}
- %else
-diff --git a/packaging/fix-undefined-references-in-sos.patch b/packaging/fix-undefined-references-in-sos.patch
-new file mode 100644
-index 0000000..96d7bcf
---- /dev/null
-+++ b/packaging/fix-undefined-references-in-sos.patch
-@@ -0,0 +1,276 @@
-+diff --git a/src/inc/regdisp.h b/src/inc/regdisp.h
-+index a361dca..eb84fdf 100644
-+--- a/src/inc/regdisp.h
-++++ b/src/inc/regdisp.h
-+@@ -323,6 +323,35 @@ inline void SyncRegDisplayToCurrentContext(REGDISPLAY* pRD)
-+ 
-+ typedef REGDISPLAY *PREGDISPLAY;
-+ 
-++#ifdef WIN64EXCEPTIONS
-++inline void FillContextPointers(PT_KNONVOLATILE_CONTEXT_POINTERS pCtxPtrs, PT_CONTEXT pCtx)
-++{
-++#ifdef _TARGET_AMD64_
-++    for (int i = 0; i < 16; i++)
-++    {
-++        *(&pCtxPtrs->Rax + i) = (&pCtx->Rax + i);
-++    }
-++#elif defined(_TARGET_ARM64_) // _TARGET_AMD64_
-++    for (int i = 0; i < 12; i++)
-++    {
-++        *(&pCtxPtrs->X19 + i) = (&pCtx->X19 + i);
-++    }
-++#elif defined(_TARGET_ARM_) // _TARGET_ARM64_
-++    // Copy over the nonvolatile integer registers (R4-R11)
-++    for (int i = 0; i < 8; i++)
-++    {
-++        *(&pCtxPtrs->R4 + i) = (&pCtx->R4 + i);
-++    }
-++#elif defined(_TARGET_X86_) // _TARGET_ARM_
-++    for (int i = 0; i < 7; i++)
-++    {
-++        *(&pCtxPtrs->Edi + i) = (&pCtx->Edi + i);
-++    }
-++#else // _TARGET_X86_
-++    PORTABILITY_ASSERT("FillContextPointers");
-++#endif // _TARGET_???_ (ELSE)
-++}
-++#endif // WIN64EXCEPTIONS
-+ 
-+ inline void FillRegDisplay(const PREGDISPLAY pRD, PT_CONTEXT pctx, PT_CONTEXT pCallerCtx = NULL)
-+ {
-+@@ -374,33 +403,12 @@ inline void FillRegDisplay(const PREGDISPLAY pRD, PT_CONTEXT pctx, PT_CONTEXT pC
-+         pRD->IsCallerSPValid      = TRUE;        // Don't add usage of this field.  This is only temporary.
-+     }
-+ 
-+-#ifdef _TARGET_AMD64_
-+-    for (int i = 0; i < 16; i++)
-+-    {
-+-        *(&pRD->ctxPtrsOne.Rax + i) = (&pctx->Rax + i);
-+-    }
-+-#elif defined(_TARGET_ARM64_) // _TARGET_AMD64_
-+-    for (int i = 0; i < 12; i++)
-+-    {
-+-        *(&pRD->ctxPtrsOne.X19 + i) = (&pctx->X19 + i);
-+-    }
-+-#elif defined(_TARGET_ARM_) // _TARGET_ARM64_
-+-    // Copy over the nonvolatile integer registers (R4-R11)
-+-    for (int i = 0; i < 8; i++)
-+-    {
-+-        *(&pRD->ctxPtrsOne.R4 + i) = (&pctx->R4 + i);
-+-    }
-++    FillContextPointers(&pRD->ctxPtrsOne, pctx);
-+ 
-++#if defined(_TARGET_ARM_)
-+     pRD->ctxPtrsOne.Lr = &pctx->Lr;
-+     pRD->pPC = &pRD->pCurrentContext->Pc;
-+-#elif defined(_TARGET_X86_) // _TARGET_ARM_
-+-    for (int i = 0; i < 7; i++)
-+-    {
-+-        *(&pRD->ctxPtrsOne.Edi + i) = (&pctx->Edi + i);
-+-    }
-+-#else // _TARGET_X86_
-+-    PORTABILITY_ASSERT("FillRegDisplay");
-+-#endif // _TARGET_???_ (ELSE)
-++#endif // _TARGET_ARM_
-+ 
-+ #ifdef DEBUG_REGDISPLAY
-+     pRD->_pThread = NULL;
-+diff --git a/src/unwinder/i386/unwinder_i386.cpp b/src/unwinder/i386/unwinder_i386.cpp
-+index f221020..42c19cb 100644
-+--- a/src/unwinder/i386/unwinder_i386.cpp
-++++ b/src/unwinder/i386/unwinder_i386.cpp
-+@@ -8,6 +8,49 @@
-+ #include "unwinder_i386.h"
-+ 
-+ #ifdef WIN64EXCEPTIONS
-++BOOL OOPStackUnwinderX86::Unwind(T_CONTEXT* pContextRecord, T_KNONVOLATILE_CONTEXT_POINTERS* pContextPointers)
-++{
-++    REGDISPLAY rd;
-++
-++    FillRegDisplay(&rd, pContextRecord);
-++
-++    rd.SP = pContextRecord->Esp;
-++    rd.PCTAddr = (UINT_PTR)&(pContextRecord->Eip);
-++
-++    if (pContextPointers)
-++    {
-++        rd.pCurrentContextPointers = pContextPointers;
-++    }
-++
-++    CodeManState codeManState;
-++    codeManState.dwIsSet = 0;
-++
-++    DWORD ControlPc = pContextRecord->Eip;
-++
-++    EECodeInfo codeInfo;
-++    codeInfo.Init((PCODE) ControlPc);
-++
-++    if (!UnwindStackFrame(&rd, &codeInfo, UpdateAllRegs, &codeManState, NULL))
-++    {
-++        return FALSE;
-++    }
-++
-++    pContextRecord->ContextFlags |= CONTEXT_UNWOUND_TO_CALL;
-++
-++#define ARGUMENT_AND_SCRATCH_REGISTER(reg) if (rd.pCurrentContextPointers->reg) pContextRecord->reg = *rd.pCurrentContextPointers->reg;
-++    ENUM_ARGUMENT_AND_SCRATCH_REGISTERS();
-++#undef ARGUMENT_AND_SCRATCH_REGISTER
-++
-++#define CALLEE_SAVED_REGISTER(reg) if (rd.pCurrentContextPointers->reg) pContextRecord->reg = *rd.pCurrentContextPointers->reg;
-++    ENUM_CALLEE_SAVED_REGISTERS();
-++#undef CALLEE_SAVED_REGISTER
-++
-++    pContextRecord->Esp = rd.SP - codeInfo.GetCodeManager()->GetStackParameterSize(&codeInfo);
-++    pContextRecord->Eip = rd.ControlPC;
-++
-++    return TRUE;
-++}
-++
-+ /*++
-+ 
-+ Routine Description:
-+@@ -72,42 +115,13 @@ OOPStackUnwinderX86::VirtualUnwind(
-+         *HandlerRoutine = NULL;
-+     }
-+ 
-+-    REGDISPLAY rd;
-+-
-+-    FillRegDisplay(&rd, ContextRecord);
-+-
-+-    rd.SP = ContextRecord->Esp;
-+-    rd.PCTAddr = (UINT_PTR)&(ContextRecord->Eip);
-+-
-+-    if (ContextPointers)
-+-    {
-+-        rd.pCurrentContextPointers = ContextPointers;
-+-    }
-+-
-+-    CodeManState codeManState;
-+-    codeManState.dwIsSet = 0;
-++    _ASSERTE(ContextRecord->Eip == ControlPc);
-+ 
-+-    EECodeInfo codeInfo;
-+-    codeInfo.Init((PCODE) ControlPc);
-+-
-+-    if (!UnwindStackFrame(&rd, &codeInfo, UpdateAllRegs, &codeManState, NULL))
-++    if (!OOPStackUnwinderX86::Unwind(ContextRecord, ContextPointers))
-+     {
-+         return HRESULT_FROM_WIN32(ERROR_READ_FAULT);
-+     }
-+ 
-+-    ContextRecord->ContextFlags |= CONTEXT_UNWOUND_TO_CALL;
-+-
-+-#define ARGUMENT_AND_SCRATCH_REGISTER(reg) if (rd.pCurrentContextPointers->reg) ContextRecord->reg = *rd.pCurrentContextPointers->reg;
-+-    ENUM_ARGUMENT_AND_SCRATCH_REGISTERS();
-+-#undef ARGUMENT_AND_SCRATCH_REGISTER
-+-
-+-#define CALLEE_SAVED_REGISTER(reg) if (rd.pCurrentContextPointers->reg) ContextRecord->reg = *rd.pCurrentContextPointers->reg;
-+-    ENUM_CALLEE_SAVED_REGISTERS();
-+-#undef CALLEE_SAVED_REGISTER
-+-
-+-    ContextRecord->Esp = rd.SP - codeInfo.GetCodeManager()->GetStackParameterSize(&codeInfo);
-+-    ContextRecord->Eip = rd.ControlPC;
-+-
-+     // For x86, the value of Establisher Frame Pointer is Caller SP
-+     //
-+     // (Please refers to CLR ABI for details)
-+@@ -115,6 +129,18 @@ OOPStackUnwinderX86::VirtualUnwind(
-+     return S_OK;
-+ }
-+ 
-++BOOL DacUnwindStackFrame(T_CONTEXT* pContextRecord, T_KNONVOLATILE_CONTEXT_POINTERS* pContextPointers)
-++{
-++    BOOL res = OOPStackUnwinderX86::Unwind(pContextRecord, NULL);
-++
-++    if (res && pContextPointers)
-++    {
-++        FillContextPointers(pContextPointers, pContextRecord);
-++    }
-++
-++    return res;
-++}
-++
-+ //---------------------------------------------------------------------------------------
-+ //
-+ // This function behaves like the RtlVirtualUnwind in Windows.
-+diff --git a/src/unwinder/i386/unwinder_i386.h b/src/unwinder/i386/unwinder_i386.h
-+index bed30bf..f29248f 100644
-+--- a/src/unwinder/i386/unwinder_i386.h
-++++ b/src/unwinder/i386/unwinder_i386.h
-+@@ -18,6 +18,8 @@
-+ class OOPStackUnwinderX86 : public OOPStackUnwinder
-+ {
-+ public:
-++    static BOOL Unwind(T_CONTEXT* pContextRecord, T_KNONVOLATILE_CONTEXT_POINTERS* pContextPointers);
-++
-+     static HRESULT VirtualUnwind(__in DWORD HandlerType,
-+         __in DWORD ImageBase,
-+         __in DWORD ControlPc,
-+diff --git a/src/vm/i386/excepx86.cpp b/src/vm/i386/excepx86.cpp
-+index cf01147..9f19d47 100644
-+--- a/src/vm/i386/excepx86.cpp
-++++ b/src/vm/i386/excepx86.cpp
-+@@ -1953,18 +1953,6 @@ LPVOID STDCALL COMPlusEndCatch(LPVOID ebp, DWORD ebx, DWORD edi, DWORD esi, LPVO
-+     return esp;
-+ }
-+ 
-+-#endif // !DACCESS_COMPILE
-+-
-+-PTR_CONTEXT GetCONTEXTFromRedirectedStubStackFrame(CONTEXT * pContext)
-+-{
-+-    LIMITED_METHOD_DAC_CONTRACT;
-+-    
-+-    UINT_PTR stackSlot = pContext->Ebp + REDIRECTSTUB_EBP_OFFSET_CONTEXT;
-+-    PTR_PTR_CONTEXT ppContext = dac_cast<PTR_PTR_CONTEXT>((TADDR)stackSlot);
-+-    return *ppContext;
-+-}
-+-
-+-#if !defined(DACCESS_COMPILE)
-+ PEXCEPTION_REGISTRATION_RECORD GetCurrentSEHRecord()
-+ {
-+     WRAPPER_NO_CONTRACT;
-+@@ -3618,6 +3606,15 @@ EXCEPTION_HANDLER_IMPL(COMPlusFrameHandlerRevCom)
-+ #endif // !DACCESS_COMPILE
-+ #endif // !WIN64EXCEPTIONS
-+ 
-++PTR_CONTEXT GetCONTEXTFromRedirectedStubStackFrame(CONTEXT * pContext)
-++{
-++    LIMITED_METHOD_DAC_CONTRACT;
-++
-++    UINT_PTR stackSlot = pContext->Ebp + REDIRECTSTUB_EBP_OFFSET_CONTEXT;
-++    PTR_PTR_CONTEXT ppContext = dac_cast<PTR_PTR_CONTEXT>((TADDR)stackSlot);
-++    return *ppContext;
-++}
-++
-+ #ifndef DACCESS_COMPILE
-+ LONG CLRNoCatchHandler(EXCEPTION_POINTERS* pExceptionInfo, PVOID pv)
-+ {
-+diff --git a/src/vm/virtualcallstub.cpp b/src/vm/virtualcallstub.cpp
-+index 01b15c6..e753860 100644
-+--- a/src/vm/virtualcallstub.cpp
-++++ b/src/vm/virtualcallstub.cpp
-+@@ -1640,6 +1640,13 @@ void VirtualCallStubManager::BackPatchWorkerStatic(PCODE returnAddress, TADDR si
-+     END_ENTRYPOINT_VOIDRET;
-+ }
-+ 
-++#if defined(_TARGET_X86_) && defined(FEATURE_PAL)
-++void BackPatchWorkerStaticStub(PCODE returnAddr, TADDR siteAddrForRegisterIndirect)
-++{
-++    VirtualCallStubManager::BackPatchWorkerStatic(returnAddr, siteAddrForRegisterIndirect);
-++}
-++#endif
-++
-+ PCODE VirtualCallStubManager::ResolveWorker(StubCallSite* pCallSite,
-+                                             OBJECTREF *protectedObj,
-+                                             DispatchToken token,
-+@@ -4047,10 +4054,3 @@ BOOL VirtualCallStubManagerManager::TraceManager(
-+     // Forward the call to the appropriate manager.
-+     return pMgr->TraceManager(thread, trace, pContext, pRetAddr);
-+ }
-+-
-+-#if defined(_TARGET_X86_) && defined(FEATURE_PAL)
-+-void BackPatchWorkerStaticStub(PCODE returnAddr, TADDR siteAddrForRegisterIndirect)
-+-{
-+-    VirtualCallStubManager::BackPatchWorkerStatic(returnAddr, siteAddrForRegisterIndirect);
-+-}
-+-#endif
--- 
-2.7.4
-
diff --git a/patches/coreclr/0004-Fix-SetDebuggerREGDISPLAYFromREGDISPLAY-function-on-.patch b/patches/coreclr/0004-Fix-SetDebuggerREGDISPLAYFromREGDISPLAY-function-on-.patch
new file mode 100644 (file)
index 0000000..8418410
--- /dev/null
@@ -0,0 +1,73 @@
+From 96fed12d0cc3b847be9f02e54f247288c539fc9d Mon Sep 17 00:00:00 2001
+From: Igor Kulaychuk <i.kulaychuk@samsung.com>
+Date: Thu, 14 Sep 2017 15:40:49 +0300
+Subject: [PATCH 4/4] Fix SetDebuggerREGDISPLAYFromREGDISPLAY() function on ARM
+
+Signed-off-by: Igor Kulaychuk <i.kulaychuk@samsung.com>
+Signed-off-by: Dmitry Kovalenko <d.kovalenko@samsung.com>
+---
+ packaging/coreclr.spec                             |  2 ++
+ ...x-arm-set-debuggerregdisplay-from-context.patch | 31 ++++++++++++++++++++++
+ 2 files changed, 33 insertions(+)
+ create mode 100644 packaging/fix-arm-set-debuggerregdisplay-from-context.patch
+
+diff --git a/packaging/coreclr.spec b/packaging/coreclr.spec
+index 20eda688..fb33455c 100644
+--- a/packaging/coreclr.spec
++++ b/packaging/coreclr.spec
+@@ -64,6 +64,7 @@ Patch36:     0001-Fix-typo-in-SetDebuggerREGDISPLAYFromREGDISPLAY-1422.patch
+ Patch37:     0001-Use-addresses-without-sign-extension-in-lldb-plugin-.patch
+ Patch38:     fix-arm-breakpoints.patch
+ Patch39:     fix-undefined-references-in-sos.patch
++Patch40:     fix-arm-set-debuggerregdisplay-from-context.patch
+ ExcludeArch: aarch64
+@@ -208,6 +209,7 @@ cp %{SOURCE1001} .
+ %patch37 -p1
+ %patch38 -p1
+ %patch39 -p1
++%patch40 -p1
+ %if 0%{skipmscorlib}
+ %else
+diff --git a/packaging/fix-arm-set-debuggerregdisplay-from-context.patch b/packaging/fix-arm-set-debuggerregdisplay-from-context.patch
+new file mode 100644
+index 00000000..7ddfc736
+--- /dev/null
++++ b/packaging/fix-arm-set-debuggerregdisplay-from-context.patch
+@@ -0,0 +1,31 @@
++commit ed63a9873f5228fcc2b9b0280a9a237a3401aa05
++Author: Igor Kulaychuk <i.kulaychuk@samsung.com>
++Date:   Wed Sep 13 20:39:44 2017 +0300
++
++    [ARM] Fix SetDebuggerREGDISPLAYFromREGDISPLAY() function
++    
++    Use the same logic as in AMD64 code: when setting DebuggerREGDISPLAY from the context,
++    the context flags might not be initialized. Since it is only called from stackwalker,
++    we can copy valid integer, control, and floating point sections from the context.
++
++diff --git a/src/debug/shared/arm/primitives.cpp b/src/debug/shared/arm/primitives.cpp
++index e9d0bbd..8771dd9 100644
++--- a/src/debug/shared/arm/primitives.cpp
+++++ b/src/debug/shared/arm/primitives.cpp
++@@ -80,8 +80,15 @@ void CORDbgSetDebuggerREGDISPLAYFromContext(DebuggerREGDISPLAY *pDRD,
++ void SetDebuggerREGDISPLAYFromREGDISPLAY(DebuggerREGDISPLAY* pDRD, REGDISPLAY* pRD)
++ {
++     SUPPORTS_DAC_HOST_ONLY;
++-    
+++    // CORDbgSetDebuggerREGDISPLAYFromContext() checks the context flags.  In cases where we don't have a filter
+++    // context from the thread, we initialize a CONTEXT on the stack and use that to do our stack walking.  We never
+++    // initialize the context flags in such cases.  Since this function is called from the stackwalker, we can
+++    // guarantee that the integer, control, and floating point sections are valid.  So we set the flags here and
+++    // restore them afterwards.
+++    DWORD contextFlags = pRD->pCurrentContext->ContextFlags;
+++    pRD->pCurrentContext->ContextFlags = CONTEXT_FULL;
++     CORDbgSetDebuggerREGDISPLAYFromContext(pDRD, reinterpret_cast<DT_CONTEXT*>(pRD->pCurrentContext));
+++    pRD->pCurrentContext->ContextFlags = contextFlags;
++ 
++     pDRD->SP   = pRD->SP;
++     pDRD->PC   = (SIZE_T)*(pRD->pPC);
+-- 
+2.13.6
+
diff --git a/patches/coreclr/0005-Fix-SetDebuggerREGDISPLAYFromREGDISPLAY-function-on-.patch b/patches/coreclr/0005-Fix-SetDebuggerREGDISPLAYFromREGDISPLAY-function-on-.patch
deleted file mode 100644 (file)
index 8419406..0000000
+++ /dev/null
@@ -1,71 +0,0 @@
-From 765fdc841203909fcdbc13dfcc2ae91b0b1ebc85 Mon Sep 17 00:00:00 2001
-From: Igor Kulaychuk <i.kulaychuk@samsung.com>
-Date: Thu, 14 Sep 2017 15:40:49 +0300
-Subject: [PATCH 5/5] Fix SetDebuggerREGDISPLAYFromREGDISPLAY() function on ARM
-
----
- packaging/coreclr.spec                             |  2 ++
- ...x-arm-set-debuggerregdisplay-from-context.patch | 31 ++++++++++++++++++++++
- 2 files changed, 33 insertions(+)
- create mode 100644 packaging/fix-arm-set-debuggerregdisplay-from-context.patch
-
-diff --git a/packaging/coreclr.spec b/packaging/coreclr.spec
-index 917fbc2..a0d03ff 100644
---- a/packaging/coreclr.spec
-+++ b/packaging/coreclr.spec
-@@ -45,6 +45,7 @@ Patch17:    profiling.patch
- Patch18:    clear_cache.patch
- Patch19:    fix-arm-breakpoints.patch
- Patch20:    fix-undefined-references-in-sos.patch
-+Patch21:    fix-arm-set-debuggerregdisplay-from-context.patch
- ExcludeArch: aarch64
-@@ -164,6 +165,7 @@ cp %{SOURCE1001} .
- %patch18 -p1
- %patch19 -p1
- %patch20 -p1
-+%patch21 -p1
- %if 0%{skipmscorlib}
- %else
-diff --git a/packaging/fix-arm-set-debuggerregdisplay-from-context.patch b/packaging/fix-arm-set-debuggerregdisplay-from-context.patch
-new file mode 100644
-index 0000000..7ddfc73
---- /dev/null
-+++ b/packaging/fix-arm-set-debuggerregdisplay-from-context.patch
-@@ -0,0 +1,31 @@
-+commit ed63a9873f5228fcc2b9b0280a9a237a3401aa05
-+Author: Igor Kulaychuk <i.kulaychuk@samsung.com>
-+Date:   Wed Sep 13 20:39:44 2017 +0300
-+
-+    [ARM] Fix SetDebuggerREGDISPLAYFromREGDISPLAY() function
-+    
-+    Use the same logic as in AMD64 code: when setting DebuggerREGDISPLAY from the context,
-+    the context flags might not be initialized. Since it is only called from stackwalker,
-+    we can copy valid integer, control, and floating point sections from the context.
-+
-+diff --git a/src/debug/shared/arm/primitives.cpp b/src/debug/shared/arm/primitives.cpp
-+index e9d0bbd..8771dd9 100644
-+--- a/src/debug/shared/arm/primitives.cpp
-++++ b/src/debug/shared/arm/primitives.cpp
-+@@ -80,8 +80,15 @@ void CORDbgSetDebuggerREGDISPLAYFromContext(DebuggerREGDISPLAY *pDRD,
-+ void SetDebuggerREGDISPLAYFromREGDISPLAY(DebuggerREGDISPLAY* pDRD, REGDISPLAY* pRD)
-+ {
-+     SUPPORTS_DAC_HOST_ONLY;
-+-    
-++    // CORDbgSetDebuggerREGDISPLAYFromContext() checks the context flags.  In cases where we don't have a filter
-++    // context from the thread, we initialize a CONTEXT on the stack and use that to do our stack walking.  We never
-++    // initialize the context flags in such cases.  Since this function is called from the stackwalker, we can
-++    // guarantee that the integer, control, and floating point sections are valid.  So we set the flags here and
-++    // restore them afterwards.
-++    DWORD contextFlags = pRD->pCurrentContext->ContextFlags;
-++    pRD->pCurrentContext->ContextFlags = CONTEXT_FULL;
-+     CORDbgSetDebuggerREGDISPLAYFromContext(pDRD, reinterpret_cast<DT_CONTEXT*>(pRD->pCurrentContext));
-++    pRD->pCurrentContext->ContextFlags = contextFlags;
-+ 
-+     pDRD->SP   = pRD->SP;
-+     pDRD->PC   = (SIZE_T)*(pRD->pPC);
--- 
-2.7.4
-