Skip to content

Commit

Permalink
[release/7.0.2xx-xcode14.3] [runtime] Add support for passing on a co…
Browse files Browse the repository at this point in the history
…nnect timeout to sdb. (#18056)

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.


Backport of #18037
  • Loading branch information
1 parent 28fa1cd commit 334c0c8
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 3 deletions.
1 change: 1 addition & 0 deletions dotnet/targets/Xamarin.Shared.Sdk.targets
Original file line number Diff line number Diff line change
Expand Up @@ -1851,6 +1851,7 @@
<MlaunchEnvironmentVariables Include="__XAMARIN_DEBUG_MODE__=$(XamarinDebugMode)" Condition="'$(XamarinDebugMode)' != ''" />
<MlaunchEnvironmentVariables Include="__XAMARIN_DEBUG_PORT__=$(XamarinDebugPort)" Condition="'$(XamarinDebugPort)' != ''" />
<MlaunchEnvironmentVariables Include="__XAMARIN_DEBUG_HOSTS__=$(XamarinDebugHosts.Replace(';', '%3B'))" Condition="'$(XamarinDebugHosts)' != ''" />
<MlaunchEnvironmentVariables Include="__XAMARIN_DEBUG_CONNECT_TIMEOUT__=$(XamarinDebugConnectTimeout)" Condition="'$(XamarinDebugConnectTimeout)' != ''" />
<!-- It's not possible to set an item group from the command line, so add support for setting a property (with semi-colon separated items) that we'll include into the item group -->
<MlaunchAdditionalArguments Include="$(MlaunchAdditionalArgumentsProperty)" Condition="'$(MlaunchAdditionalArgumentsProperty)' != ''" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 ()
Expand All @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions msbuild/Xamarin.Shared/Xamarin.Shared.targets
Original file line number Diff line number Diff line change
Expand Up @@ -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)"
Expand Down
25 changes: 22 additions & 3 deletions runtime/monotouch-debug.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}
}
Expand All @@ -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) {
Expand Down Expand Up @@ -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
Expand Down

6 comments on commit 334c0c8

@vs-mobiletools-engineering-service2
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💻 [CI Build] Tests on macOS M1 - Mac Ventura (13.0) passed 💻

All tests on macOS M1 - Mac Ventura (13.0) passed.

Pipeline on Agent
Hash: 334c0c87f592fa9ee2ac17d2b8f103035867090c [CI build]

@vs-mobiletools-engineering-service2
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💻 [CI Build] Tests on macOS M1 - Mac Big Sur (11.5) passed 💻

All tests on macOS M1 - Mac Big Sur (11.5) passed.

Pipeline on Agent
Hash: 334c0c87f592fa9ee2ac17d2b8f103035867090c [CI build]

@vs-mobiletools-engineering-service2
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ API diff for current PR / commit

NET (empty diffs)
  • iOS: (empty diff detected)
  • tvOS: (empty diff detected)
  • MacCatalyst: (empty diff detected)
  • macOS: (empty diff detected)

✅ API diff vs stable

.NET (No breaking changes)

✅ Generator diff

Generator diff is empty

Pipeline on Agent
Hash: 334c0c87f592fa9ee2ac17d2b8f103035867090c [CI build]

@vs-mobiletools-engineering-service2
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💻 [CI Build] Windows Integration Tests passed 💻

All Windows Integration Tests passed.

Pipeline on Agent
Hash: 334c0c87f592fa9ee2ac17d2b8f103035867090c [CI build]

@vs-mobiletools-engineering-service2
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📚 [CI Build] Artifacts 📚

Packages generated

View packages

Pipeline on Agent XAMMINI-051.Ventura
Hash: 334c0c87f592fa9ee2ac17d2b8f103035867090c [CI build]

@vs-mobiletools-engineering-service2
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀 [CI Build] Test results 🚀

Test results

✅ All tests passed on VSTS: simulator tests.

🎉 All 79 tests passed 🎉

Tests counts

⚠️ bcl: No tests selected. Html Report (VSDrops) Download
✅ cecil: All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests: All 1 tests passed. Html Report (VSDrops) Download
✅ fsharp: All 4 tests passed. Html Report (VSDrops) Download
✅ framework: All 4 tests passed. Html Report (VSDrops) Download
✅ generator: All 1 tests passed. Html Report (VSDrops) Download
✅ interdependent_binding_projects: All 4 tests passed. Html Report (VSDrops) Download
⚠️ install_source: No tests selected. Html Report (VSDrops) Download
✅ introspection: All 4 tests passed. Html Report (VSDrops) Download
✅ linker: All 40 tests passed. Html Report (VSDrops) Download
⚠️ mac_binding_project: No tests selected. Html Report (VSDrops) Download
⚠️ mmp: No tests selected. Html Report (VSDrops) Download
⚠️ mononative: No tests selected. Html Report (VSDrops) Download
✅ monotouch: All 13 tests passed. Html Report (VSDrops) Download
✅ msbuild: All 2 tests passed. Html Report (VSDrops) Download
⚠️ mtouch: No tests selected. Html Report (VSDrops) Download
⚠️ xammac: No tests selected. Html Report (VSDrops) Download
✅ xcframework: All 4 tests passed. Html Report (VSDrops) Download
✅ xtro: All 1 tests passed. Html Report (VSDrops) Download

Pipeline on Agent
Hash: 334c0c87f592fa9ee2ac17d2b8f103035867090c [CI build]

Please sign in to comment.