From 943ea0524c1da1b6a14133ff8bb0aba93fcf6fb6 Mon Sep 17 00:00:00 2001 From: Andrew Wang Date: Wed, 2 Aug 2023 15:41:32 -0700 Subject: [PATCH 1/2] Only use ps 'flags' for macOS This PR adds in an operating system check via uname to determine if we should run the PS command with the 'flags' flag. This feature was originally used to determine the architecture of a process for macOS M1 machines that can run as x64 or as arm64. AD7Process only uses the flags field in macOS so this PR updates the command sent to only use it on macOS machines. Other changes: - Updated the setup.csx script to update VS with VS.list instead of VS.Codespaces.list - Updated tests to use the new PSOutputParser - Added a macOS test --- src/SSHDebugPS/AD7/AD7Process.cs | 4 +- src/SSHDebugPS/IConnection.cs | 30 ++++++++++-- src/SSHDebugPS/PSOutputParser.cs | 48 +++++++++++-------- src/SSHDebugPS/PipeConnection.cs | 21 ++++++--- src/SSHDebugPS/SSH/SSHConnection.cs | 15 ++++-- src/SSHDebugTests/PSOutputParserTests.cs | 59 +++++++++++++++++------- tools/Setup.csx | 23 +++++---- tools/VS.CodeSpaces.list | 8 ---- tools/VS.list | 16 +++++++ 9 files changed, 157 insertions(+), 67 deletions(-) delete mode 100644 tools/VS.CodeSpaces.list create mode 100644 tools/VS.list diff --git a/src/SSHDebugPS/AD7/AD7Process.cs b/src/SSHDebugPS/AD7/AD7Process.cs index 09c275867..9675a393b 100644 --- a/src/SSHDebugPS/AD7/AD7Process.cs +++ b/src/SSHDebugPS/AD7/AD7Process.cs @@ -25,7 +25,7 @@ internal class AD7Process : IDebugProcess2, IDebugProcessSecurity2, IDebugProces /// /// Flags are only used in ps command scenarios. It will be set to 0 for others. /// - private readonly uint _flags; + private readonly uint? _flags; /// /// Returns true if _commandLine appears to hold a real file name + args rather than just a description @@ -297,7 +297,7 @@ string IDebugUnixProcess.GetProcessArchitecture() { // For Apple Silicon M1, it is possible that the process we are attaching to is being emulated as x86_64. // The process is emulated if it has process flags has P_TRANSLATED (0x20000). - if (_port.IsOSX() && _systemArch == "arm64") + if (_port.IsOSX() && _systemArch == "arm64" && _flags.HasValue) { if ((_flags & 0x20000) != 0) { diff --git a/src/SSHDebugPS/IConnection.cs b/src/SSHDebugPS/IConnection.cs index 27c4e48ca..99ff487bd 100644 --- a/src/SSHDebugPS/IConnection.cs +++ b/src/SSHDebugPS/IConnection.cs @@ -1,7 +1,9 @@ // Copyright (c) Microsoft. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. +using System; using System.Collections.Generic; +using System.Diagnostics; using System.Threading; using Microsoft.DebugEngineHost; using Microsoft.SSHDebugPS.Utilities; @@ -104,13 +106,13 @@ public class Process /// /// Only used by the PSOutputParser /// - public uint Flags { get; private set; } + public uint? Flags { get; private set; } public string SystemArch { get; private set; } public string CommandLine { get; private set; } public string UserName { get; private set; } public bool IsSameUser { get; private set; } - public Process(uint id, string arch, uint flags, string userName, string commandLine, bool isSameUser) + public Process(uint id, string arch, uint? flags, string userName, string commandLine, bool isSameUser) { this.Id = id; this.Flags = flags; @@ -121,15 +123,37 @@ public Process(uint id, string arch, uint flags, string userName, string command } } + internal static class OperatingSystemStringConverter + { + internal static PlatformID ConvertToPlatformID(this string value) + { + if (!string.IsNullOrEmpty(value)) + { + value = value.ToLowerInvariant(); + if (value.Contains("darwin")) + { + return PlatformID.MacOSX; + } else if (value.Contains("linux")) + { + return PlatformID.Unix; + } + } + Debug.Fail($"Expected a valid platform '{value}' of darwin or linux, but falling back to linux."); + return PlatformID.Unix; + } + } + internal class SystemInformation { public string UserName { get; private set; } public string Architecture { get; private set; } + public PlatformID Platform { get; private set; } - public SystemInformation(string username, string architecture) + public SystemInformation(string username, string architecture, PlatformID platform) { this.UserName = username; this.Architecture = architecture; + Platform = platform; } } } \ No newline at end of file diff --git a/src/SSHDebugPS/PSOutputParser.cs b/src/SSHDebugPS/PSOutputParser.cs index 15fac8a71..d3255f18b 100644 --- a/src/SSHDebugPS/PSOutputParser.cs +++ b/src/SSHDebugPS/PSOutputParser.cs @@ -59,28 +59,27 @@ public string Extract(string line) // Use padding to expand column width. 10 for pid and 32 for userid as that is the max size for each // Tested this format with different distributions of Linux and container distributions. This command (and the alternative without the flags) seems // to be the one that works the best between standard *nix and BusyBox implementations of ps. - private const string PSCommandLineFormat = "ps{0}-o pid=pppppppppp -o flags=ffffffff -o ruser=rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr -o args"; + private const string PSCommandLineFormat = "ps{0}-o pid=pppppppppp{1} -o ruser=rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr -o args"; private SystemInformation _currentSystemInformation; private ColumnDef _pidCol; private ColumnDef _flagsCol; private ColumnDef _ruserCol; private ColumnDef _argsCol; - public static string PSCommandLine = PSCommandLineFormat.FormatInvariantWithArgs(" axww "); - public static string AltPSCommandLine = PSCommandLineFormat.FormatInvariantWithArgs(" "); + // In order to determine the architecture of a process, we need to run the ps command with 'flags'. + // However, certain of distros of Linux do not support flags, so only add this for macOS. + private string PSFlagFormat => _currentSystemInformation.Platform == PlatformID.MacOSX ? " -o flags=ffffffff" : string.Empty; - public static List Parse(string output, SystemInformation systemInformation) - { - return new PSOutputParser().ParseInternal(output, systemInformation); - } + public string PSCommandLine => PSCommandLineFormat.FormatInvariantWithArgs(" axww ", PSFlagFormat); + public string AltPSCommandLine => PSCommandLineFormat.FormatInvariantWithArgs(" ", PSFlagFormat); - private PSOutputParser() + public PSOutputParser(SystemInformation systemInformation) { + _currentSystemInformation = systemInformation; } - private List ParseInternal(string output, SystemInformation systemInformation) + public List Parse(string output) { - _currentSystemInformation = systemInformation; List processList = new List(); using (var reader = new StringReader(output)) @@ -136,14 +135,18 @@ private bool ProcessHeaderLine(/*OPTIONAL*/ string headerLine) if (!SkipNonWhitespace(headerLine, ref index)) return false; - _flagsCol = new ColumnDef(colStart, index); + /// on why this is only executed for macOS. + if (_currentSystemInformation.Platform == PlatformID.MacOSX) + { + _flagsCol = new ColumnDef(colStart, index); - if (!SkipWhitespace(headerLine, ref index)) - return false; + if (!SkipWhitespace(headerLine, ref index)) + return false; - colStart = index; - if (!SkipNonWhitespace(headerLine, ref index)) - return false; + colStart = index; + if (!SkipNonWhitespace(headerLine, ref index)) + return false; + } _ruserCol = new ColumnDef(colStart, index); @@ -170,10 +173,15 @@ private Process SplitPSLine(string line) if (!uint.TryParse(pidText, NumberStyles.None, CultureInfo.InvariantCulture, out pid)) return null; - uint flags; - string flagsText = _flagsCol.Extract(line); - if (!uint.TryParse(flagsText, NumberStyles.HexNumber, CultureInfo.InvariantCulture, out flags)) - return null; + uint? flags = null; + /// on why this is only executed for macOS. + if (_currentSystemInformation.Platform == PlatformID.MacOSX) + { + string flagsText = _flagsCol.Extract(line); + if (!uint.TryParse(flagsText, NumberStyles.HexNumber, CultureInfo.InvariantCulture, out uint tempFlags)) + return null; + flags = tempFlags; + } string ruser = _ruserCol.Extract(line); string commandLine = _argsCol.Extract(line); diff --git a/src/SSHDebugPS/PipeConnection.cs b/src/SSHDebugPS/PipeConnection.cs index 94f5ca7ac..a8f37311e 100644 --- a/src/SSHDebugPS/PipeConnection.cs +++ b/src/SSHDebugPS/PipeConnection.cs @@ -98,8 +98,8 @@ public override bool IsLinux() /// SystemInformation containing username and architecture. If it was unable to obtain any of these, the value will be set to string.Empty. public SystemInformation GetSystemInformation() { - string commandOutput; - string errorMessage; + string commandOutput = string.Empty; + string errorMessage = string.Empty; int exitCode; string username = string.Empty; @@ -108,13 +108,19 @@ public SystemInformation GetSystemInformation() username = commandOutput; } + string platform = string.Empty; + if (ExecuteCommand("uname", Timeout.Infinite, commandOutput: out commandOutput, errorMessage: out errorMessage, exitCode: out exitCode)) + { + platform = commandOutput; + } + string architecture = string.Empty; if (ExecuteCommand("uname -m", Timeout.Infinite, commandOutput: out commandOutput, errorMessage: out errorMessage, exitCode: out exitCode)) { architecture = commandOutput; } - return new SystemInformation(username, architecture); + return new SystemInformation(username, architecture, platform.ConvertToPlatformID()); } public override List ListProcesses() @@ -152,12 +158,15 @@ private bool PSListProcess(SystemInformation systemInformation, out string error errorMessage = string.Empty; string commandOutput; int exitCode; - if (!ExecuteCommand(PSOutputParser.PSCommandLine, Timeout.Infinite, out commandOutput, out errorMessage, out exitCode)) + + PSOutputParser psOutputParser = new PSOutputParser(systemInformation); + + if (!ExecuteCommand(psOutputParser.PSCommandLine, Timeout.Infinite, out commandOutput, out errorMessage, out exitCode)) { // Clear output and errorMessage commandOutput = string.Empty; errorMessage = string.Empty; - if (!ExecuteCommand(PSOutputParser.AltPSCommandLine, Timeout.Infinite, out commandOutput, out errorMessage, out exitCode)) + if (!ExecuteCommand(psOutputParser.AltPSCommandLine, Timeout.Infinite, out commandOutput, out errorMessage, out exitCode)) { if (exitCode == 127) { @@ -174,7 +183,7 @@ private bool PSListProcess(SystemInformation systemInformation, out string error } } - processes = PSOutputParser.Parse(commandOutput, systemInformation); + processes = psOutputParser.Parse(commandOutput); return true; } diff --git a/src/SSHDebugPS/SSH/SSHConnection.cs b/src/SSHDebugPS/SSH/SSHConnection.cs index 56b5f4907..4abcfe541 100644 --- a/src/SSHDebugPS/SSH/SSHConnection.cs +++ b/src/SSHDebugPS/SSH/SSHConnection.cs @@ -52,6 +52,13 @@ public override List ListProcesses() username = usernameCommand.Output.TrimEnd('\n', '\r'); // trim line endings because 'id' command ends with a newline } + string operatingSystem = string.Empty; + var operatingSystemCommand = _remoteSystem.Shell.ExecuteCommand("uname", Timeout.InfiniteTimeSpan); + if (operatingSystemCommand.ExitCode == 0) + { + operatingSystem = operatingSystemCommand.Output.TrimEnd('\n', '\r'); // trim line endings because 'uname' command ends with a newline + } + string architecture = string.Empty; var architectureCommand = _remoteSystem.Shell.ExecuteCommand("uname -m", Timeout.InfiniteTimeSpan); if (architectureCommand.ExitCode == 0) @@ -59,15 +66,17 @@ public override List ListProcesses() architecture = architectureCommand.Output.TrimEnd('\n', '\r'); // trim line endings because 'uname -m' command ends with a newline } - SystemInformation systemInformation = new SystemInformation(username, architecture); + SystemInformation systemInformation = new SystemInformation(username, architecture, operatingSystem.ConvertToPlatformID()); + + PSOutputParser psOutputParser = new PSOutputParser(systemInformation); - var command = _remoteSystem.Shell.ExecuteCommand(PSOutputParser.PSCommandLine, Timeout.InfiniteTimeSpan); + var command = _remoteSystem.Shell.ExecuteCommand(psOutputParser.PSCommandLine, Timeout.InfiniteTimeSpan); if (command.ExitCode != 0) { throw new CommandFailedException(StringResources.Error_PSFailed); } - return PSOutputParser.Parse(command.Output, systemInformation); + return psOutputParser.Parse(command.Output); } /// diff --git a/src/SSHDebugTests/PSOutputParserTests.cs b/src/SSHDebugTests/PSOutputParserTests.cs index bfd74a129..819bcd3cd 100644 --- a/src/SSHDebugTests/PSOutputParserTests.cs +++ b/src/SSHDebugTests/PSOutputParserTests.cs @@ -1,6 +1,7 @@ // Copyright (c) Microsoft. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. +using System; using Microsoft.SSHDebugPS; using System.Collections.Generic; using Xunit; @@ -9,6 +10,29 @@ namespace SSHDebugTests { public class PSOutputParserTests { + [Fact] + public void PSOutputParser_macOS() + { + const string username = "username"; + const string architecture = "x86_64"; + const string input = + "pppppppppp ffffffff rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr ARGS\n" + + "1 4004 root /sbin/launchd\n" + + "50 1004004 root /System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/FSEvents.framework/Versions/A/Support/fseventsd\n" + + "70 1004004 root /System/Library/Frameworks/CoreServices.framework/Frameworks/Metadata.framework/Support/mds\n" + + "83 4004 _timed /usr/libexec/timed\n" + + "96 80004104 root /System/Library/CoreServices/loginwindow.app/Contents/MacOS/loginwindow console\n" + + "7835 4104 username ps axww -o pid=pppppppppp -o flags=ffffffff -o ruser=rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr -o args\n"; + + PSOutputParser psOutputParser = new PSOutputParser(new SystemInformation(username, architecture, PlatformID.MacOSX)); + List r = psOutputParser.Parse(input); + Assert.Equal(5, r.Count); + // Testing flags here as PID USER ARGS are tested in the other tests. + Assert.Equal(r[0].Flags.Value, (uint)0x4004); + Assert.Equal(r[1].Flags.Value, (uint)0x1004004); + Assert.Equal(r[4].Flags.Value, (uint)0x80004104); + } + [Fact] public void PSOutputParser_Ubuntu14() { @@ -16,15 +40,16 @@ public void PSOutputParser_Ubuntu14() const string architecture = "x86_64"; // example output from ps on a real Ubuntu 14 machine (with many processes removed): const string input = - "pppppppppp ffffffff rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr COMMAND\n" + - " 1 0 root /sbin/init\n" + - " 2 0 root [kthreadd]\n" + - " 720 0 message+ dbus-daemon --system --fork\n" + - " 2389 0 greggm -bash\n" + - " 2580 0 root /sbin/dhclient -d -sf /usr/lib/NetworkManager/nm-dhcp-client.action -pf /run/sendsigs.omit.d/network-manager.dhclient-eth0.pid -lf /var/lib/NetworkManager/dhclient-d08a482b-ff90-4007-9b13-6500eb94b673-eth0.lease -cf /var/lib/NetworkManager/dhclient-eth0.conf eth0\n" + - " 2913 0 greggm ps axww -o pid=pppppppppp -o flags=ffffffff -o ruser=rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr -o args\n"; + "pppppppppp rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr COMMAND\n" + + " 1 root /sbin/init\n" + + " 2 root [kthreadd]\n" + + " 720 message+ dbus-daemon --system --fork\n" + + " 2389 greggm -bash\n" + + " 2580 root /sbin/dhclient -d -sf /usr/lib/NetworkManager/nm-dhcp-client.action -pf /run/sendsigs.omit.d/network-manager.dhclient-eth0.pid -lf /var/lib/NetworkManager/dhclient-d08a482b-ff90-4007-9b13-6500eb94b673-eth0.lease -cf /var/lib/NetworkManager/dhclient-eth0.conf eth0\n" + + " 2913 greggm ps axww -o pid=pppppppppp -o ruser=rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr -o args\n"; - List r = PSOutputParser.Parse(input, new SystemInformation(username, architecture)); + PSOutputParser psOutputParser = new PSOutputParser(new SystemInformation(username, architecture, PlatformID.Unix)); + List r = psOutputParser.Parse(input); Assert.Equal(5, r.Count); uint[] pids = { 1, 2, 720, 2389, 2580 }; @@ -47,10 +72,11 @@ public void PSOutputParser_SmallCol() const string architecture = "x86_64"; // made up output for what could happen if the fields were all just 1 character in size const string input = - "A B C D\n" + - "9 0 r /sbin/init"; + "A B C\n" + + "9 r /sbin/init"; - List r = PSOutputParser.Parse(input, new SystemInformation(username, architecture)); + PSOutputParser psOutputParser = new PSOutputParser(new SystemInformation(username, architecture, PlatformID.Unix)); + List r = psOutputParser.Parse(input); Assert.Single(r); Assert.Equal(9, r[0].Id); Assert.Equal("r", r[0].UserName); @@ -64,12 +90,13 @@ public void PSOutputParser_NoUserName() const string username = ""; const string architecture = ""; const string input = - "pppppppppp ffffffff rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr COMMAND\n" + - " 1 0 root /sbin/init\n" + - " 720 0 dbus-daemon --system --fork\n" + - " 2389 0 greggm -bash\n"; + "pppppppppp rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr COMMAND\n" + + " 1 root /sbin/init\n" + + " 720 dbus-daemon --system --fork\n" + + " 2389 greggm -bash\n"; - List r = PSOutputParser.Parse(input, new SystemInformation(username, architecture)); + PSOutputParser psOutputParser = new PSOutputParser(new SystemInformation(username, architecture, PlatformID.Unix)); + List r = psOutputParser.Parse(input); Assert.Equal(3, r.Count); uint[] pids = { 1, 720, 2389 }; diff --git a/tools/Setup.csx b/tools/Setup.csx index 832030bac..66f62ed4b 100644 --- a/tools/Setup.csx +++ b/tools/Setup.csx @@ -196,15 +196,21 @@ class Setup { vscodeExtensionPath = Path.Join(Environment.GetEnvironmentVariable("HOME"), ".vscode/extensions"); } IEnumerable extensions = Directory.EnumerateDirectories(vscodeExtensionPath); - - foreach (string extension in extensions) + if (extensions.Any()) { - if (extension.Contains("ms-vscode.cpptools")) + foreach (string extension in extensions) { - TargetPath = extension; - break; + if (extension.Contains("ms-vscode.cpptools")) + { + TargetPath = extension; + break; + } } } + else + { + throw new InvalidOperationException("Unable to find an installation of VS Code C++ Extension."); + } } } @@ -217,7 +223,7 @@ class Setup { if (Client == Client.VS) { - listFilePath = Path.Join(scriptDirectoryPath, "VS.CodeSpaces.list"); + listFilePath = Path.Join(scriptDirectoryPath, "VS.list"); // Use folder. binDirectoryPath = Path.Join(binDirectoryPath, Configuration.ToString()); } @@ -225,13 +231,12 @@ class Setup { { listFilePath = Path.Join(scriptDirectoryPath, "VSCode.list"); // Use Desktop. folder. - binDirectoryPath = Path.Join(binDirectoryPath, "Desktop." + Configuration.ToString()); + binDirectoryPath = Path.Join(binDirectoryPath, Configuration.ToString()); } if (!Directory.Exists(binDirectoryPath)) { - string configurationToUse = Client == Client.VS ? Configuration.ToString() : "Desktop." + Configuration.ToString(); - throw new InvalidOperationException(string.Format("'{0}' does not exist. Did you build {1}?", binDirectoryPath, configurationToUse)); + throw new InvalidOperationException(string.Format("'{0}' does not exist. Did you build {1}?", binDirectoryPath, Configuration.ToString())); } IList lffList = this.ParseListFiles(listFilePath); diff --git a/tools/VS.CodeSpaces.list b/tools/VS.CodeSpaces.list deleted file mode 100644 index e90f8618f..000000000 --- a/tools/VS.CodeSpaces.list +++ /dev/null @@ -1,8 +0,0 @@ -# filename,source-root,source-dir,install-dir -# Where 'source-root' is either 'src', or 'bin' -Microsoft.MICore.dll,bin,,\Common7\IDE\CommonExtensions\Microsoft\MDD\Debugger -Microsoft.MIDebugEngine.dll,bin,,\Common7\IDE\CommonExtensions\Microsoft\MDD\Debugger -OpenDebugAD7.exe,bin,vscode,\Common7\IDE\CommonExtensions\Microsoft\MDD\Debugger\vscode -Microsoft.DebugEngineHost.dll,bin,vscode,\Common7\IDE\CommonExtensions\Microsoft\MDD\Debugger\vscode -Microsoft.VisualStudio.Shared.VSCodeDebugProtocol.dll,bin,vscode,\Common7\IDE\CommonExtensions\Microsoft\MDD\Debugger\vscode -cppdbg.ad7Engine.json,src,OpenDebugAD7,\Common7\IDE\CommonExtensions\Microsoft\MDD\Debugger\vscode \ No newline at end of file diff --git a/tools/VS.list b/tools/VS.list new file mode 100644 index 000000000..3106e302b --- /dev/null +++ b/tools/VS.list @@ -0,0 +1,16 @@ +# filename,source-root,source-dir,install-dir +# Where 'source-root' is either 'src', or 'bin' +Microsoft.Android.natvis,src,AndroidDebugLauncher,\Common7\IDE\CommonExtensions\Microsoft\MDD\Debugger +Microsoft.AndroidDebugLauncher.dll,bin,,\Common7\IDE\CommonExtensions\Microsoft\MDD\Debugger +Microsoft.AndroidDebugLauncher.pkgdef,bin,,\Common7\IDE\CommonExtensions\Microsoft\MDD\Debugger +Microsoft.DebugEngineHost.dll,bin,,\Common7\IDE\CommonExtensions\Microsoft\MDD\Debugger +Microsoft.IOSDebugLauncher.dll,bin,,\Common7\IDE\CommonExtensions\Microsoft\MDD\Debugger +Microsoft.IOSDebugLauncher.pkgdef,bin,,\Common7\IDE\CommonExtensions\Microsoft\MDD\Debugger +Microsoft.JDbg.dll,bin,,\Common7\IDE\CommonExtensions\Microsoft\MDD\Debugger +Microsoft.MICore.dll,bin,,\Common7\IDE\CommonExtensions\Microsoft\MDD\Debugger +Microsoft.MICore.XmlSerializers.dll,bin,,\Common7\IDE\CommonExtensions\Microsoft\MDD\Debugger +Microsoft.MIDebugEngine.dll,bin,,\Common7\IDE\CommonExtensions\Microsoft\MDD\Debugger +Microsoft.MIDebugEngine.pkgdef,bin,,\Common7\IDE\CommonExtensions\Microsoft\MDD\Debugger +Microsoft.SSHDebugPS.dll,bin,,\Common7\IDE\CommonExtensions\Microsoft\MDD\Debugger +Microsoft.SSHDebugPS.pkgdef,bin,,\Common7\IDE\CommonExtensions\Microsoft\MDD\Debugger +OpenFolderSchema.json,bin,,\Common7\IDE\CommonExtensions\Microsoft\MDD\Debugger \ No newline at end of file From 42fee05798cb1c2582a023333fb3efb6c4df072f Mon Sep 17 00:00:00 2001 From: Andrew Wang Date: Mon, 7 Aug 2023 13:02:53 -0700 Subject: [PATCH 2/2] Addressing PR issues --- src/SSHDebugPS/IConnection.cs | 2 +- src/SSHDebugPS/PipeConnection.cs | 2 +- src/SSHDebugPS/SSH/SSHConnection.cs | 2 +- tools/Setup.csx | 11 ++--------- 4 files changed, 5 insertions(+), 12 deletions(-) diff --git a/src/SSHDebugPS/IConnection.cs b/src/SSHDebugPS/IConnection.cs index 99ff487bd..36b694d76 100644 --- a/src/SSHDebugPS/IConnection.cs +++ b/src/SSHDebugPS/IConnection.cs @@ -125,7 +125,7 @@ public Process(uint id, string arch, uint? flags, string userName, string comman internal static class OperatingSystemStringConverter { - internal static PlatformID ConvertToPlatformID(this string value) + internal static PlatformID ConvertToPlatformID(string value) { if (!string.IsNullOrEmpty(value)) { diff --git a/src/SSHDebugPS/PipeConnection.cs b/src/SSHDebugPS/PipeConnection.cs index a8f37311e..ee08786cc 100644 --- a/src/SSHDebugPS/PipeConnection.cs +++ b/src/SSHDebugPS/PipeConnection.cs @@ -120,7 +120,7 @@ public SystemInformation GetSystemInformation() architecture = commandOutput; } - return new SystemInformation(username, architecture, platform.ConvertToPlatformID()); + return new SystemInformation(username, architecture, OperatingSystemStringConverter.ConvertToPlatformID(platform)); } public override List ListProcesses() diff --git a/src/SSHDebugPS/SSH/SSHConnection.cs b/src/SSHDebugPS/SSH/SSHConnection.cs index 4abcfe541..e084b510b 100644 --- a/src/SSHDebugPS/SSH/SSHConnection.cs +++ b/src/SSHDebugPS/SSH/SSHConnection.cs @@ -66,7 +66,7 @@ public override List ListProcesses() architecture = architectureCommand.Output.TrimEnd('\n', '\r'); // trim line endings because 'uname -m' command ends with a newline } - SystemInformation systemInformation = new SystemInformation(username, architecture, operatingSystem.ConvertToPlatformID()); + SystemInformation systemInformation = new SystemInformation(username, architecture, OperatingSystemStringConverter.ConvertToPlatformID(operatingSystem)); PSOutputParser psOutputParser = new PSOutputParser(systemInformation); diff --git a/tools/Setup.csx b/tools/Setup.csx index 66f62ed4b..807d4dda9 100644 --- a/tools/Setup.csx +++ b/tools/Setup.csx @@ -195,17 +195,10 @@ class Setup { { vscodeExtensionPath = Path.Join(Environment.GetEnvironmentVariable("HOME"), ".vscode/extensions"); } - IEnumerable extensions = Directory.EnumerateDirectories(vscodeExtensionPath); + IEnumerable extensions = Directory.EnumerateDirectories(vscodeExtensionPath).Where(extension => extension.Contains("ms-vscode.cpptools")); if (extensions.Any()) { - foreach (string extension in extensions) - { - if (extension.Contains("ms-vscode.cpptools")) - { - TargetPath = extension; - break; - } - } + TargetPath = extensions.First(); } else {