Add patches for Tizen repositories in Gerrit
authorIgor Kulaychuk <i.kulaychuk@samsung.com>
Fri, 25 Aug 2017 15:40:36 +0000 (18:40 +0300)
committerIgor Kulaychuk <i.kulaychuk@samsung.com>
Fri, 25 Aug 2017 15:53:48 +0000 (18:53 +0300)
patches/coreclr/0001-Add-more-stuff-to-devel-package-for-debugger.patch [new file with mode: 0644]
patches/coreclr/0002-Add-patch-for-breakpoints-on-ARM.patch [new file with mode: 0644]
patches/coreclr/0003-Enable-Debug-IPC.patch [new file with mode: 0644]
patches/dotnet-launcher/0001-Enable-waiting-for-managed-debugger-attach.patch [new file with mode: 0644]

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
new file mode 100644 (file)
index 0000000..55ba221
--- /dev/null
@@ -0,0 +1,53 @@
+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/3] 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/0002-Add-patch-for-breakpoints-on-ARM.patch b/patches/coreclr/0002-Add-patch-for-breakpoints-on-ARM.patch
new file mode 100644 (file)
index 0000000..602beda
--- /dev/null
@@ -0,0 +1,182 @@
+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/3] 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/0003-Enable-Debug-IPC.patch b/patches/coreclr/0003-Enable-Debug-IPC.patch
new file mode 100644 (file)
index 0000000..dc813fc
--- /dev/null
@@ -0,0 +1,34 @@
+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/3] 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/dotnet-launcher/0001-Enable-waiting-for-managed-debugger-attach.patch b/patches/dotnet-launcher/0001-Enable-waiting-for-managed-debugger-attach.patch
new file mode 100644 (file)
index 0000000..8758873
--- /dev/null
@@ -0,0 +1,82 @@
+From 36807ef3792cf299a02e96a92cb0a4618b3d584e Mon Sep 17 00:00:00 2001
+From: Igor Kulaychuk <i.kulaychuk@samsung.com>
+Date: Thu, 24 Aug 2017 23:56:27 +0300
+Subject: [PATCH] Enable waiting for managed debugger attach
+
+---
+ NativeLauncher/dotnet.debugger                    |  9 ++++-----
+ NativeLauncher/launcher/dotnet/dotnet_launcher.cc | 23 +++++++++++++++++++++++
+ NativeLauncher/launcher/dotnet/dotnet_launcher.h  |  1 +
+ 3 files changed, 28 insertions(+), 5 deletions(-)
+
+diff --git a/NativeLauncher/dotnet.debugger b/NativeLauncher/dotnet.debugger
+index 6f57cde..c3c4ad2 100644
+--- a/NativeLauncher/dotnet.debugger
++++ b/NativeLauncher/dotnet.debugger
+@@ -1,6 +1,5 @@
+ [DEBUGGER]
+-NAME LLDB-SERVER
+-EXE /home/owner/share/tmp/sdk_tools/lldb/bin/lldb-server
+-APP_TYPE dotnet
+-EXTRA_KEY __DLP_DEBUG_ARG__
+-EXTRA_ENV CORECLR_GDBJIT
++NAME         NETCOREDBG-WAIT
++EXE          /usr/bin/dotnet-launcher
++APP_TYPE     dotnet
++EXTRA_ENV    DEBUG
+diff --git a/NativeLauncher/launcher/dotnet/dotnet_launcher.cc b/NativeLauncher/launcher/dotnet/dotnet_launcher.cc
+index b268357..83d4332 100644
+--- a/NativeLauncher/launcher/dotnet/dotnet_launcher.cc
++++ b/NativeLauncher/launcher/dotnet/dotnet_launcher.cc
+@@ -16,6 +16,7 @@
+ #include <dlfcn.h>
++#include <unistd.h>
+ #include <string>
+ #include <fstream>
+@@ -376,6 +377,28 @@ int CoreRuntime::launch(const char* appId, const char* root, const char* path, i
+       }
+ #else
+       int st = initializeCoreClr(appId, probePath.c_str(), probePath.c_str(), tpa.c_str());
++
++      if (getenv("DEBUG"))
++      {
++              void *debuggerIsAttachedDelegate;
++              st = createDelegate(__hostHandle, __domainId,
++                                                      "mscorlib",
++                                                      "System.Diagnostics.Debugger",
++                                                      "get_IsAttached", &debuggerIsAttachedDelegate);
++              if (st < 0) {
++                      _ERR("Create delegate for Debugger.IsAttached property is fail (0x%08x)", st);
++                      return 1;
++              }
++              DebuggerIsAttachedPtr debuggerIsAttached = reinterpret_cast<DebuggerIsAttachedPtr>(debuggerIsAttachedDelegate);
++
++              if (debuggerIsAttached == nullptr) {
++                      _ERR("Cast delegate for Debugger.IsAttached property is fail");
++                      return 1;
++              }
++              while (!debuggerIsAttached())
++                      usleep(100 * 1000);
++      }
++
+       unsigned int ret = 0;
+       st = executeAssembly(__hostHandle, __domainId, argc, (const char**)argv, path, &ret);
+       if (st < 0)
+diff --git a/NativeLauncher/launcher/dotnet/dotnet_launcher.h b/NativeLauncher/launcher/dotnet/dotnet_launcher.h
+index 931846c..8b5ad7a 100644
+--- a/NativeLauncher/launcher/dotnet/dotnet_launcher.h
++++ b/NativeLauncher/launcher/dotnet/dotnet_launcher.h
+@@ -71,6 +71,7 @@ namespace dotnetcore {
+ typedef void (*PreparedFunctionPtr)();
+ typedef bool (*LaunchFunctionPtr)(const char* root, const char* path, int argc, char* argv[]);
++typedef bool (*DebuggerIsAttachedPtr)();
+ class CoreRuntime : public tizen::runtime::LauncherInterface
+ {
+-- 
+2.7.4
+