From e5eff53d6cc74d11ccb9fe7418de811d0519c834 Mon Sep 17 00:00:00 2001 From: Woongsuk Cho Date: Mon, 6 Sep 2021 09:47:49 +0900 Subject: [PATCH] Add SetSwitch API to Tizen.Runtime 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 | 29 +++++++++++++++++++++++++++++ NativeLauncher/inc/coreclr_host.h | 13 ------------- NativeLauncher/launcher/lib/core_runtime.cc | 9 +++++++++ NativeLauncher/launcher/lib/core_runtime.h | 4 ++++ 4 files changed, 42 insertions(+), 13 deletions(-) create mode 100644 Managed/Tizen.Runtime/AppSetting.cs diff --git a/Managed/Tizen.Runtime/AppSetting.cs b/Managed/Tizen.Runtime/AppSetting.cs new file mode 100644 index 0000000..165dc8e --- /dev/null +++ b/Managed/Tizen.Runtime/AppSetting.cs @@ -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); + } + } +} diff --git a/NativeLauncher/inc/coreclr_host.h b/NativeLauncher/inc/coreclr_host.h index 702b7ec..a4adc44 100644 --- a/NativeLauncher/inc/coreclr_host.h +++ b/NativeLauncher/inc/coreclr_host.h @@ -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); } diff --git a/NativeLauncher/launcher/lib/core_runtime.cc b/NativeLauncher/launcher/lib/core_runtime.cc index 64cc962..b9e75ac 100644 --- a/NativeLauncher/launcher/lib/core_runtime.cc +++ b/NativeLauncher/launcher/lib/core_runtime.cc @@ -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(); diff --git a/NativeLauncher/launcher/lib/core_runtime.h b/NativeLauncher/launcher/lib/core_runtime.h index f341261..a6dc452 100644 --- a/NativeLauncher/launcher/lib/core_runtime.h +++ b/NativeLauncher/launcher/lib/core_runtime.h @@ -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: -- 2.7.4