Create coreclr delegate inside coreclr_initialize
authorEvgeny Pavlov <e.pavlov@samsung.com>
Mon, 18 Jul 2016 12:19:26 +0000 (15:19 +0300)
committerEvgeny Pavlov <e.pavlov@samsung.com>
Fri, 22 Jul 2016 07:57:30 +0000 (10:57 +0300)
Commit migrated from https://github.com/dotnet/coreclr/commit/24066e1427bbb6be7e95449302040daf2fcddfd7

src/coreclr/src/coreclr/hosts/inc/coreclrhost.h
src/coreclr/src/coreclr/hosts/unixcoreruncommon/coreruncommon.cpp
src/coreclr/src/dlls/mscoree/CMakeLists.txt
src/coreclr/src/dlls/mscoree/unixinterface.cpp
src/coreclr/src/inc/utilcode.h
src/coreclr/src/vm/gdbjit.cpp

index 733174b..8c9f3a3 100644 (file)
@@ -47,21 +47,6 @@ CORECLR_HOSTING_API(coreclr_execute_assembly,
 
 #undef CORECLR_HOSTING_API
 
-struct SequencePointInfo
-{
-    int lineNumber, ilOffset;
-    char16_t* fileName;
-};
-
-struct MethodDebugInfo
-{
-    SequencePointInfo* points;
-    int size;
-};
-
-typedef int (*GetInfoForMethodDelegate)(const char*, unsigned int, MethodDebugInfo& methodDebugInfo);
-extern GetInfoForMethodDelegate getInfoForMethodDelegate;
-
 #endif // __CORECLR_HOST_H__
 
 
index ae2d49c..29f2772 100644 (file)
@@ -34,7 +34,6 @@
 // If set to 1, server GC is enabled on startup. If 0, server GC is
 // disabled. Server GC is off by default.
 static const char* serverGcVar = "CORECLR_SERVER_GC";
-GetInfoForMethodDelegate getInfoForMethodDelegate = NULL;
 #if defined(__linux__)
 #define symlinkEntrypointExecutable "/proc/self/exe"
 #elif !defined(__APPLE__)
@@ -402,24 +401,6 @@ int ExecuteManagedAssembly(
             }
             else 
             {
-#ifdef FEATURE_GDBJIT                
-                coreclr_create_delegate_ptr CreateDelegate =
-                (coreclr_create_delegate_ptr)dlsym(coreclrLib,
-                                           "coreclr_create_delegate");
-
-                // st = CreateDelegate(hostHandle, domainId, "System.Diagnostics.Debug.SymbolReader",
-                //           "System.Diagnostics.Debug.SymbolReader.SymbolReader", "GetLineByILOffset",
-                //           (void **)&getLineByILOffsetDelegate);
-                st = CreateDelegate(hostHandle, domainId, "System.Diagnostics.Debug.SymbolReader",
-                          "System.Diagnostics.Debug.SymbolReader.SymbolReader", "GetInfoForMethod",
-                          (void **)&getInfoForMethodDelegate);
-
-                if (!SUCCEEDED(st))
-                {
-                    fprintf(stderr, "coreclr_create_delegate failed - status: 0x%08x\n", st);
-                    exitCode = -1;
-                }
-#endif // FEATURE_GDBJIT                
                 st = executeAssembly(
                         hostHandle,
                         domainId,
index 7af76fb..6a157e4 100644 (file)
@@ -1,5 +1,9 @@
 include_directories("../../inc")
 
+if(FEATURE_GDBJIT)
+   add_definitions(-DFEATURE_GDBJIT)
+endif(FEATURE_GDBJIT)
+
 set(CLR_SOURCES
     mscoree.cpp
     unixinterface.cpp
index be345b3..f48b021 100644 (file)
@@ -137,6 +137,11 @@ static void ConvertConfigPropertiesToUnicode(
 extern "C" LPCWSTR g_CLRJITPath;
 #endif // !defined(FEATURE_MERGE_JIT_AND_ENGINE)
 
+#ifdef FEATURE_GDBJIT
+GetInfoForMethodDelegate getInfoForMethodDelegate = NULL;
+extern "C" int coreclr_create_delegate(void*, unsigned int, const char*, const char*, const char*, void**);
+#endif //FEATURE_GDBJIT
+
 //
 // Initialize the CoreCLR. Creates and starts CoreCLR host and creates an app domain
 //
@@ -238,8 +243,21 @@ int coreclr_initialize(
     {
         host.SuppressRelease();
         *hostHandle = host;
-    }
+#ifdef FEATURE_GDBJIT
 
+        hr = coreclr_create_delegate(*hostHandle,
+                                     *domainId,
+                                     "System.Diagnostics.Debug.SymbolReader",
+                                     "System.Diagnostics.Debug.SymbolReader.SymbolReader",
+                                     "GetInfoForMethod",
+                                     (void**)&getInfoForMethodDelegate);
+
+        if (!SUCCEEDED(hr))
+        {
+            fprintf(stderr, "coreclr_create_delegate failed - status: 0x%08x\n", hr);
+        }
+#endif
+    }
     return hr;
 }
 
index 993d87d..79bdc69 100644 (file)
@@ -5750,4 +5750,21 @@ extern SpinConstants g_SpinConstants;
 
 // ======================================================================================
 
+#ifdef FEATURE_GDBJIT
+struct SequencePointInfo
+{
+    int lineNumber, ilOffset;
+    char16_t* fileName;
+};
+
+struct MethodDebugInfo
+{
+    SequencePointInfo* points;
+    int size;
+};
+
+typedef int (*GetInfoForMethodDelegate)(const char*, unsigned int, MethodDebugInfo& methodDebugInfo);
+extern GetInfoForMethodDelegate getInfoForMethodDelegate;
+#endif // FEATURE_GDBJIT
+
 #endif // __UtilCode_h__
index c60f349..d3a6574 100644 (file)
@@ -11,7 +11,7 @@
 //*****************************************************************************
 
 #include "common.h"
-#include "../coreclr/hosts/inc/coreclrhost.h"
+#include "../inc/utilcode.h"
 #include "gdbjit.h"
 
 struct DebuggerILToNativeMap
@@ -102,7 +102,7 @@ GetDebugInfoFromPDB(MethodDesc* MethodDescPtr, SymbolsInfo** symInfo, unsigned i
     StackScratchBuffer scratch;
     const char* szModName = modName.GetUTF8(scratch);
 
-    MethodDebugInfo *methodDebugInfo = new (nothrow )MethodDebugInfo();
+    MethodDebugInfo* methodDebugInfo = new (nothrow) MethodDebugInfo();
     if (methodDebugInfo == nullptr)
         return E_OUTOFMEMORY;
     methodDebugInfo->points = (SequencePointInfo*) CoTaskMemAlloc(sizeof(SequencePointInfo) * numMap);