From 049e990b6262fdc24ad7228896c6c938442de010 Mon Sep 17 00:00:00 2001 From: Rolf Bjarne Kvinge Date: Wed, 12 Apr 2023 11:13:28 +0200 Subject: [PATCH] [runtime] Add support for passing on a connect timeout to sdb. The timeout can be given: * By setting the __XAMARIN_DEBUG_CONNECT_TIMEOUT__ environment variable for the app when launching it. * By passing the XamarinDebugConnectTimeout MSBuild property to 'dotnet run' or 'dotnet build /t:Run'. * By setting the IOSDebugConnectTimeout MSBuild property at build time. Fixes https://devdiv.visualstudio.com/DevDiv/_workitems/edit/1778177. --- dotnet/targets/Xamarin.Shared.Sdk.targets | 1 + .../Tasks/CreateDebugConfigurationTaskBase.cs | 6 +++++ msbuild/Xamarin.Shared/Xamarin.Shared.targets | 1 + runtime/monotouch-debug.m | 25 ++++++++++++++++--- 4 files changed, 30 insertions(+), 3 deletions(-) diff --git a/dotnet/targets/Xamarin.Shared.Sdk.targets b/dotnet/targets/Xamarin.Shared.Sdk.targets index 0e76cb2548ed..a7b933f1ac4f 100644 --- a/dotnet/targets/Xamarin.Shared.Sdk.targets +++ b/dotnet/targets/Xamarin.Shared.Sdk.targets @@ -1851,6 +1851,7 @@ + diff --git a/msbuild/Xamarin.MacDev.Tasks/Tasks/CreateDebugConfigurationTaskBase.cs b/msbuild/Xamarin.MacDev.Tasks/Tasks/CreateDebugConfigurationTaskBase.cs index 0d45a1d877d6..42ffba071925 100644 --- a/msbuild/Xamarin.MacDev.Tasks/Tasks/CreateDebugConfigurationTaskBase.cs +++ b/msbuild/Xamarin.MacDev.Tasks/Tasks/CreateDebugConfigurationTaskBase.cs @@ -26,6 +26,7 @@ public abstract class CreateDebugConfigurationTaskBase : XamarinTask { [Required] public bool SdkIsSimulator { get; set; } + public string ConnectTimeout { get; set; } #endregion public override bool Execute () @@ -52,6 +53,11 @@ public override bool Execute () builder.Append ("Port: "); builder.AppendLine (DebuggerPort); + if (!string.IsNullOrEmpty (ConnectTimeout)) { + builder.Append ("Connect Timeout: "); + builder.AppendLine (ConnectTimeout); + } + var text = builder.ToString (); try { diff --git a/msbuild/Xamarin.Shared/Xamarin.Shared.targets b/msbuild/Xamarin.Shared/Xamarin.Shared.targets index 1726a8f196a7..f548b04ae551 100644 --- a/msbuild/Xamarin.Shared/Xamarin.Shared.targets +++ b/msbuild/Xamarin.Shared/Xamarin.Shared.targets @@ -2369,6 +2369,7 @@ Copyright (C) 2018 Microsoft. All rights reserved. SessionId="$(BuildSessionId)" Condition="'$(IsMacEnabled)' == 'true'" AppBundleDir="$(_AppResourcesPath)" + ConnectTimeout="$(IOSDebugConnectTimeout)" DebugOverWiFi="$(IOSDebugOverWiFi)" DebugIPAddresses="$(_DebugIPAddresses)" DebuggerPort="$(IOSDebuggerPort)" diff --git a/runtime/monotouch-debug.m b/runtime/monotouch-debug.m index 1db71cc8593c..a2d734e7d636 100644 --- a/runtime/monotouch-debug.m +++ b/runtime/monotouch-debug.m @@ -49,6 +49,7 @@ // permanent connection variables static long monodevelop_port = -1; static int sdb_fd = -1; +static long sdb_timeout_time = -1; static int heapshot_fd = -1; // this is the socket to write 'heapshot' to to requests heapshots from the profiler static long heapshot_port = -1; static char *profiler_description = NULL; @@ -593,6 +594,15 @@ void monotouch_configure_debugging () unsetenv ("__XAMARIN_DEBUG_HOSTS__"); } + evar = getenv ("__XAMARIN_DEBUG_CONNECT_TIMEOUT__"); + if (evar && *evar) { + if (sdb_timeout_time == -1) { + sdb_timeout_time = strtol (evar, NULL, 10); + LOG (PRODUCT ": Found connect timeout %i in environment variables\n", sdb_timeout_time); + } + unsetenv ("__XAMARIN_DEBUG_CONNECT_TIMEOUT__"); + } + #if MONOTOUCH && (defined(__i386__) || defined (__x86_64__)) // Try to read shared memory as well key_t shmkey; @@ -681,6 +691,8 @@ void monotouch_configure_debugging () #endif } else if (!strncmp ("Port: ", line, 6) && monodevelop_port == -1) { monodevelop_port = strtol (line + 6, NULL, 10); + } else if (!strncmp ("Connect Timeout: ", line, 17) && sdb_timeout_time == -1) { + sdb_timeout_time = strtol (line + 17, NULL, 10); } } } @@ -703,7 +715,7 @@ void monotouch_configure_debugging () if (monodevelop_port <= 0) { LOG (PRODUCT ": Invalid IDE Port: %i\n", monodevelop_port); } else { - LOG (PRODUCT ": IDE Port: %i Transport: %s\n", monodevelop_port, debugging_mode == DebuggingModeHttp ? "HTTP" : (debugging_mode == DebuggingModeUsb ? "USB" : "WiFi")); + LOG (PRODUCT ": IDE Port: %i Transport: %s Connect Timeout: %i\n", monodevelop_port, debugging_mode == DebuggingModeHttp ? "HTTP" : (debugging_mode == DebuggingModeUsb ? "USB" : "WiFi"), sdb_timeout_time); if (debugging_mode == DebuggingModeUsb) { monotouch_connect_usb (); } else if (debugging_mode == DebuggingModeWifi) { @@ -1251,8 +1263,15 @@ static ssize_t sdb_recv (void *buf, size_t len) transport.recv = sdb_recv; mono_debugger_agent_register_transport (&transport); - - mono_debugger_agent_parse_options ("transport=custom_transport,address=dummy,embedding=1"); + + char *options; + if (sdb_timeout_time != -1) { + options = xamarin_strdup_printf ("transport=custom_transport,address=dummy,embedding=1,timeout=%d", sdb_timeout_time); + } else { + options = xamarin_strdup_printf ("transport=custom_transport,address=dummy,embedding=1"); + } + mono_debugger_agent_parse_options (options); + // Can't free the 'options' variable, because mono_debugger_agent_parse_option stores the pointer instead of creating a copy :/ LOG (PRODUCT ": Debugger loaded with custom transport (fd: %i)\n", sdb_fd); #else