Add SetSwitch API to Tizen.Runtime
authorWoongsuk Cho <ws77.cho@samsung.com>
Mon, 6 Sep 2021 00:47:49 +0000 (09:47 +0900)
committer조웅석/Common Platform Lab(SR)/Principal Engineer/삼성전자 <ws77.cho@samsung.com>
Tue, 7 Sep 2021 00:04:27 +0000 (09:04 +0900)
MS decided not to show ILOffset info as default in exception info.
To enable that feature, "Switch.System.Diagnostics.StackTrace.ShowILOffsets" switch should be set true.

An internal API for setting app context switch in dotnet-launcher has been added.
And, "Switch.System.Diagnostics.StackTrace.ShowILOffsets" is enabled defaultly.

Managed/Tizen.Runtime/AppSetting.cs [new file with mode: 0644]
NativeLauncher/inc/coreclr_host.h
NativeLauncher/launcher/lib/core_runtime.cc
NativeLauncher/launcher/lib/core_runtime.h

diff --git a/Managed/Tizen.Runtime/AppSetting.cs b/Managed/Tizen.Runtime/AppSetting.cs
new file mode 100644 (file)
index 0000000..165dc8e
--- /dev/null
@@ -0,0 +1,29 @@
+/*
+ * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+using System;
+
+namespace Tizen.Runtime
+{
+    public class AppSetting
+    {
+        private static void SetSwitch(string name, bool value)
+        {
+            Console.WriteLine($"Set {name} switch to {value}");
+            AppContext.SetSwitch(name, value);
+        }
+    }
+}
index 702b7ec..a4adc44 100644 (file)
@@ -48,19 +48,6 @@ extern "C"
                        const char* entryPointMethodName,
                        void** delegate);
 
-       typedef bool (*set_environment_variable_ptr)(const char* name,
-                       const char* value);
-
-       typedef bool (*stop_profile_after_delay_ptr)(int sec);
-
-       typedef int (*multi_byte_to_wide_char_ptr)(
-                       unsigned int CodePage,
-                       unsigned int dwFlags,
-                       const char * lpMultiByteStr,
-                       int cbMultiByte,
-                       char16_t * lpWideCharStr,
-                       int cchWideChar);
-
        typedef int (*coreclr_preload_assembly_ptr)(
                  const char* assemblyPath);
 }
index 64cc962..b9e75ac 100644 (file)
@@ -57,6 +57,7 @@ static coreclr_shutdown_ptr shutdown = nullptr;
 static coreclr_create_delegate_ptr createDelegate = nullptr;
 static set_environment_variable_ptr setEnvironmentVariable = nullptr;
 static stop_profile_after_delay_ptr stopProfileAfterDelay = nullptr;
+static set_switch_ptr setSwitch = nullptr;
 static void* __coreclrLib = nullptr;
 static void* __hostHandle = nullptr;
 static unsigned int __domainId = -1;
@@ -452,6 +453,12 @@ int CoreRuntime::initialize(const char* appType, LaunchMode launchMode)
                return -1;
        }
 
+       st = createDelegate(__hostHandle, __domainId, "Tizen.Runtime", "Tizen.Runtime.AppSetting", "SetSwitch", (void**)&setSwitch);
+       if (st < 0 || setSwitch == nullptr) {
+               _ERR("Create delegate for Tizen.Runtime.dll -> Tizen.Runtime.AppSetting -> SetSwitch failed (0x%08x)", st);
+               return -1;
+       }
+
        if (launchMode == LaunchMode::loader) {
                // terminate candidate process if language is changed.
                // CurrentCulture created for preloaded dlls should be updated.
@@ -577,6 +584,8 @@ int CoreRuntime::launch(const char* appId, const char* root, const char* path, i
                free(localDataPath);
        }
 
+       setSwitch("Switch.System.Diagnostics.StackTrace.ShowILOffsets", true);
+
        vconf_ignore_key_changed(VCONFKEY_LANGSET, langChangedCB);
 
        pluginBeforeExecute();
index f341261..a6dc452 100644 (file)
@@ -32,6 +32,10 @@ namespace tizen {
 namespace runtime {
 namespace dotnetcore {
 
+typedef bool (*set_environment_variable_ptr)(const char* name, const char* value);
+typedef bool (*stop_profile_after_delay_ptr)(int sec);
+typedef bool (*set_switch_ptr)(const char* name, bool value);
+
 class CoreRuntime
 {
        public: