Skip to content
This repository was archived by the owner on Apr 5, 2024. It is now read-only.

Commit 35baf7d

Browse files
committed
Attaching debugger when multiple unity processes are running will now
provide a guide on how to use the command defined in attach.js to attach to a specific process.
1 parent f54b0b9 commit 35baf7d

File tree

5 files changed

+25
-8
lines changed

5 files changed

+25
-8
lines changed

Changelog.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ Git: https://github.com/Unity-Technologies/vscode-unity-debug
66
Changes
77
-------
88

9+
2.4.0
10+
=====
11+
- Added support for attaching individual unity processes by use of commands.
12+
913
2.3.0
1014
=====
1115
- Added support for conditional breakpoints.

UnityDebug/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ static string GetUnityProcesses()
8585
{
8686
var processes = UnityProcessDiscovery.GetAttachableProcesses();
8787

88-
return string.Join("\n", processes.Select(x => x.Name));
88+
return string.Join("\n", processes.Select(x => x.Name + $" ({x.Id})"));
8989
}
9090
}
9191
}

UnityDebug/UnityAttach.cs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
using MonoDevelop.Debugger.Soft.Unity;
1+
using System;
2+
using MonoDevelop.Debugger.Soft.Unity;
23
using System.Collections.Generic;
34
using System.Linq;
5+
using System.Text.RegularExpressions;
46

57
namespace UnityDebug
68
{
@@ -17,8 +19,15 @@ public static class UnityAttach
1719
};
1820

1921

20-
public static IEnumerable<UnityProcessInfo> GetAttachableProcesses (string targetName)
22+
public static IEnumerable<UnityProcessInfo> GetAttachableProcesses(string targetName)
2123
{
24+
var match = Regex.Match(targetName, "\\(([0-9]+)\\)");
25+
var processId = -1;
26+
if (match.Success)
27+
{
28+
processId = Convert.ToInt32(match.Groups[1].Value);
29+
targetName = targetName.Substring(0, targetName.IndexOf("(") - 1);
30+
}
2231
string processName;
2332

2433
UnityProcessDiscovery.GetProcessOptions options = UnityProcessDiscovery.GetProcessOptions.All;
@@ -36,7 +45,9 @@ public static IEnumerable<UnityProcessInfo> GetAttachableProcesses (string targe
3645

3746
processes.ForEach (p => Log.Write ("Found Unity process: " + p.Name + " (" + p.Id + ")"));
3847

39-
return processes.Where (p => p.Name.Contains (processName));
48+
return processId == -1
49+
? processes.Where (p => p.Name.Contains(processName))
50+
: processes.Where(p => p.Name.Contains(processName) && p.Id == processId);
4051
}
4152
}
4253
}

UnityDebug/UnityDebugSession.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ public override void Attach(Response response, dynamic args)
212212

213213
SendOutput("stdout", "UnityDebug: Searching for Unity process '" + name + "'");
214214

215-
var processes = UnityAttach.GetAttachableProcesses (name).ToArray ();
215+
var processes = UnityAttach.GetAttachableProcesses(name).ToArray ();
216216

217217
if (processes == null) {
218218
SendErrorResponse(response, 8001, "Unknown target name '{_name}'. Did you mean 'Unity Editor'?", new { _name = name});
@@ -225,9 +225,11 @@ public override void Attach(Response response, dynamic args)
225225
}
226226

227227
if (processes.Length > 1) {
228-
SendErrorResponse (response, 8002, "Multiple targets with name '{_name}' running. Unable to connect.", new { _name = name});
228+
SendErrorResponse (response, 8002, "Multiple targets with name '{_name}' running. Unable to connect.\n" +
229+
"Use \"Unity Attach Debugger\" from the command palette (View > Command Palette...) to specify which process to attach to.", new { _name = name});
229230

230-
SendOutput("stdout", "UnityDebug: Multiple targets with name '" + name + "' running. Unable to connect");
231+
SendOutput("stdout", "UnityDebug: Multiple targets with name '" + name + "' running. Unable to connect.\n" +
232+
"Use \"Unity Attach Debugger\" from the command palette (View > Command Palette...) to specify which process to attach to.");
231233

232234
foreach(var p in processes)
233235
SendOutput("stdout", "UnityDebug: Found Unity process '" + p.Name + "' (" + p.Id + ")\n");

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "unity-debug",
33
"displayName": "Debugger for Unity",
4-
"version": "2.3.0",
4+
"version": "2.4.0",
55
"publisher": "Unity",
66
"description": "Unity debugger extension",
77
"engines": {

0 commit comments

Comments
 (0)