Skip to content

Commit

Permalink
Add target framework information to the AttachDebugger callback (#3701)
Browse files Browse the repository at this point in the history
Add target framework information to AttachDebugger callback so we can use it to hint the attaching debugger.
  • Loading branch information
nohwnd committed Jun 6, 2022
1 parent 493a0e2 commit 27ea06b
Show file tree
Hide file tree
Showing 88 changed files with 842 additions and 417 deletions.
30 changes: 15 additions & 15 deletions TestPlatform.sln
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "playground", "playground",
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TestPlatform.Playground", "playground\TestPlatform.Playground\TestPlatform.Playground.csproj", "{545A88D3-1AE2-4D39-9B7C-C691768AD17F}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MSTest1", "playground\MSTest1\MSTest1.csproj", "{57A61A09-10AD-44BE-8DF4-A6FD108F7DF7}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AttachmentProcessorDataCollector", "test\TestAssets\AttachmentProcessorDataCollector\AttachmentProcessorDataCollector.csproj", "{B6AF6BCD-64C6-4F4E-ABCA-C8AA2AA66B7B}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "vstest.ProgrammerTests", "test\vstest.ProgrammerTests\vstest.ProgrammerTests.csproj", "{B1F84FD8-6150-4ECA-9AD7-C316E04E17D8}"
Expand All @@ -191,6 +189,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DumpMinitool.arm64", "src\D
EndProject
Project("{D954291E-2A0B-460D-934E-DC6B0785DB48}") = "Microsoft.TestPlatform.Nullability", "src\Microsoft.TestPlatform.Nullability\Microsoft.TestPlatform.Nullability.shproj", "{9DF3BC3C-2A53-46E7-9291-40728ACE5F82}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MSTest1", "playground\MSTest1\MSTest1.csproj", "{4DA57968-F547-4019-8381-03A218B6C385}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -861,18 +861,6 @@ Global
{545A88D3-1AE2-4D39-9B7C-C691768AD17F}.Release|x64.Build.0 = Release|Any CPU
{545A88D3-1AE2-4D39-9B7C-C691768AD17F}.Release|x86.ActiveCfg = Release|Any CPU
{545A88D3-1AE2-4D39-9B7C-C691768AD17F}.Release|x86.Build.0 = Release|Any CPU
{57A61A09-10AD-44BE-8DF4-A6FD108F7DF7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{57A61A09-10AD-44BE-8DF4-A6FD108F7DF7}.Debug|Any CPU.Build.0 = Debug|Any CPU
{57A61A09-10AD-44BE-8DF4-A6FD108F7DF7}.Debug|x64.ActiveCfg = Debug|Any CPU
{57A61A09-10AD-44BE-8DF4-A6FD108F7DF7}.Debug|x64.Build.0 = Debug|Any CPU
{57A61A09-10AD-44BE-8DF4-A6FD108F7DF7}.Debug|x86.ActiveCfg = Debug|Any CPU
{57A61A09-10AD-44BE-8DF4-A6FD108F7DF7}.Debug|x86.Build.0 = Debug|Any CPU
{57A61A09-10AD-44BE-8DF4-A6FD108F7DF7}.Release|Any CPU.ActiveCfg = Release|Any CPU
{57A61A09-10AD-44BE-8DF4-A6FD108F7DF7}.Release|Any CPU.Build.0 = Release|Any CPU
{57A61A09-10AD-44BE-8DF4-A6FD108F7DF7}.Release|x64.ActiveCfg = Release|Any CPU
{57A61A09-10AD-44BE-8DF4-A6FD108F7DF7}.Release|x64.Build.0 = Release|Any CPU
{57A61A09-10AD-44BE-8DF4-A6FD108F7DF7}.Release|x86.ActiveCfg = Release|Any CPU
{57A61A09-10AD-44BE-8DF4-A6FD108F7DF7}.Release|x86.Build.0 = Release|Any CPU
{B6AF6BCD-64C6-4F4E-ABCA-C8AA2AA66B7B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B6AF6BCD-64C6-4F4E-ABCA-C8AA2AA66B7B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B6AF6BCD-64C6-4F4E-ABCA-C8AA2AA66B7B}.Debug|x64.ActiveCfg = Debug|Any CPU
Expand Down Expand Up @@ -945,6 +933,18 @@ Global
{62E9D32B-B989-43CF-81A2-B38B3367FCA3}.Release|x64.Build.0 = Release|Any CPU
{62E9D32B-B989-43CF-81A2-B38B3367FCA3}.Release|x86.ActiveCfg = Release|Any CPU
{62E9D32B-B989-43CF-81A2-B38B3367FCA3}.Release|x86.Build.0 = Release|Any CPU
{4DA57968-F547-4019-8381-03A218B6C385}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4DA57968-F547-4019-8381-03A218B6C385}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4DA57968-F547-4019-8381-03A218B6C385}.Debug|x64.ActiveCfg = Debug|Any CPU
{4DA57968-F547-4019-8381-03A218B6C385}.Debug|x64.Build.0 = Debug|Any CPU
{4DA57968-F547-4019-8381-03A218B6C385}.Debug|x86.ActiveCfg = Debug|Any CPU
{4DA57968-F547-4019-8381-03A218B6C385}.Debug|x86.Build.0 = Debug|Any CPU
{4DA57968-F547-4019-8381-03A218B6C385}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4DA57968-F547-4019-8381-03A218B6C385}.Release|Any CPU.Build.0 = Release|Any CPU
{4DA57968-F547-4019-8381-03A218B6C385}.Release|x64.ActiveCfg = Release|Any CPU
{4DA57968-F547-4019-8381-03A218B6C385}.Release|x64.Build.0 = Release|Any CPU
{4DA57968-F547-4019-8381-03A218B6C385}.Release|x86.ActiveCfg = Release|Any CPU
{4DA57968-F547-4019-8381-03A218B6C385}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -1018,14 +1018,14 @@ Global
{2C88C923-3D7A-4492-9241-7A489750CAB7} = {B705537C-B82C-4A30-AFA5-6244D9A7DAEB}
{8238A052-D626-49EB-A011-51DC6D0DBA30} = {ED0C35EB-7F31-4841-A24F-8EB708FFA959}
{545A88D3-1AE2-4D39-9B7C-C691768AD17F} = {6CE2F530-582B-4695-A209-41065E103426}
{57A61A09-10AD-44BE-8DF4-A6FD108F7DF7} = {6CE2F530-582B-4695-A209-41065E103426}
{B6AF6BCD-64C6-4F4E-ABCA-C8AA2AA66B7B} = {D9A30E32-D466-4EC5-B4F2-62E17562279B}
{B1F84FD8-6150-4ECA-9AD7-C316E04E17D8} = {B27FAFDF-2DBA-4AB0-BA85-FD5F21D359D6}
{BFBB35C9-6437-480A-8DCC-AE3700110E7D} = {B27FAFDF-2DBA-4AB0-BA85-FD5F21D359D6}
{29270853-90DC-4C39-9621-F47AE40A79B6} = {B27FAFDF-2DBA-4AB0-BA85-FD5F21D359D6}
{186069FE-E1E8-4DE1-BEA4-0FF1484D22D1} = {ED0C35EB-7F31-4841-A24F-8EB708FFA959}
{62E9D32B-B989-43CF-81A2-B38B3367FCA3} = {B705537C-B82C-4A30-AFA5-6244D9A7DAEB}
{9DF3BC3C-2A53-46E7-9291-40728ACE5F82} = {ED0C35EB-7F31-4841-A24F-8EB708FFA959}
{4DA57968-F547-4019-8381-03A218B6C385} = {6CE2F530-582B-4695-A209-41065E103426}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {0541B30C-FF51-4E28-B172-83F5F3934BCD}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TestPlatformRoot Condition="$(TestPlatformRoot) == ''">..\..\</TestPlatformRoot>
<TargetLatestRuntimePatch>true</TargetLatestRuntimePatch>
<!-- MSB3270 Suppress warnings about testhost being x64 (AMD64)/x86 when imported into AnyCPU (MSIL) projects. -->
<!-- MSB3276 Suppress warnings about conflicts between different versions of the same dependent assembly -->
<MSBuildWarningsAsMessages>$(MSBuildWarningsAsMessages);MSB3270;MSB3276</MSBuildWarningsAsMessages>
</PropertyGroup>

<Import Project="$(TestPlatformRoot)scripts/build/TestPlatform.Settings.targets" />
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFrameworks>$(TargetFrameworks);net472</TargetFrameworks>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.CodeCoverage" Version="17.2.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\datacollector\datacollector.csproj" />
<ProjectReference Include="..\..\src\Microsoft.TestPlatform.TestHostProvider\Microsoft.TestPlatform.TestHostProvider.csproj" />
<ProjectReference Include="..\..\src\Microsoft.TestPlatform.VsTestConsole.TranslationLayer\Microsoft.TestPlatform.VsTestConsole.TranslationLayer.csproj" />
<ProjectReference Include="..\..\src\testhost.x86\testhost.x86.csproj" />
<ProjectReference Include="..\..\src\testhost\testhost.csproj" />
<ProjectReference Include="..\..\src\vstest.console\vstest.console.csproj" />
<ProjectReference Include="..\MSTest1\MSTest1.TestAdapter.csproj" />
</ItemGroup>
<ItemGroup Condition=" $(TargetFramework.StartsWith('net4')) AND '$(OS)' != 'Windows_NT' ">
<Reference Include="System" />
<Reference Include="System.Runtime" />
<Reference Include="System.Xml" />
<Reference Include="System.Xml.Linq" />
<Reference Include="Microsoft.CSharp" />
</ItemGroup>

<Target Name="PostBuild" AfterTargets="PostBuildEvent" Condition=" '$(OS)' == 'WINDOWS_NT' ">
<Exec Command="xcopy /i /y /f $(MSBuildProjectDirectory)\..\..\src\vstest.console\bin\$(Configuration)\net451\ $(TargetDir)\vstest.console\&#xD;&#xA;xcopy /i /y /f $(MSBuildProjectDirectory)\..\..\src\Microsoft.TestPlatform.TestHostProvider\bin\$(Configuration)\net451\ $(TargetDir)\vstest.console\Extensions\&#xD;&#xA;REM copy net451, net47, net471, net472 and net48 testhosts&#xD;&#xA;xcopy /i /y /f $(MSBuildProjectDirectory)\..\..\src\testhost.x86\bin\$(Configuration)\net451\win7-x86 $(TargetDir)\vstest.console\TestHost\&#xD;&#xA;xcopy /i /y /f $(MSBuildProjectDirectory)\..\..\src\testhost\bin\$(Configuration)\net451\win7-x64 $(TargetDir)\vstest.console\TestHost\&#xD;&#xA;xcopy /i /y /f $(MSBuildProjectDirectory)\..\..\src\testhost.x86\bin\$(Configuration)\net47\win7-x86 $(TargetDir)\vstest.console\TestHost\&#xD;&#xA;xcopy /i /y /f $(MSBuildProjectDirectory)\..\..\src\testhost\bin\$(Configuration)\net47\win7-x64 $(TargetDir)\vstest.console\TestHost\&#xD;&#xA;xcopy /i /y /f $(MSBuildProjectDirectory)\..\..\src\testhost.x86\bin\$(Configuration)\net471\win7-x86 $(TargetDir)\vstest.console\TestHost\&#xD;&#xA;xcopy /i /y /f $(MSBuildProjectDirectory)\..\..\src\testhost\bin\$(Configuration)\net471\win7-x64 $(TargetDir)\vstest.console\TestHost\&#xD;&#xA;xcopy /i /y /f $(MSBuildProjectDirectory)\..\..\src\testhost.x86\bin\$(Configuration)\net472\win7-x86 $(TargetDir)\vstest.console\TestHost\&#xD;&#xA;xcopy /i /y /f $(MSBuildProjectDirectory)\..\..\src\testhost\bin\$(Configuration)\net472\win7-x64 $(TargetDir)\vstest.console\TestHost\&#xD;&#xA;xcopy /i /y /f $(MSBuildProjectDirectory)\..\..\src\testhost.x86\bin\$(Configuration)\net48\win7-x86 $(TargetDir)\vstest.console\TestHost\&#xD;&#xA;xcopy /i /y /f $(MSBuildProjectDirectory)\..\..\src\testhost\bin\$(Configuration)\net48\win7-x64 $(TargetDir)\vstest.console\TestHost\" />
</Target>
<Import Project="$(TestPlatformRoot)scripts\build\TestPlatform.targets" />
</Project>
2 changes: 1 addition & 1 deletion scripts/build/TestPlatform.Dependencies.props
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
<RoslynPublicApiAnalyzersVersion>3.3.4-beta1.21554.2</RoslynPublicApiAnalyzersVersion>
<RoslynBannedApiAnalyzersVersion>3.3.3</RoslynBannedApiAnalyzersVersion>

<MicrosoftCodeCoverageVersion>17.1.0</MicrosoftCodeCoverageVersion>
<MicrosoftCodeCoverageVersion>17.2.0</MicrosoftCodeCoverageVersion>

<DependencyVersionsImported>true</DependencyVersionsImported>
</PropertyGroup>
Expand Down
26 changes: 23 additions & 3 deletions src/Microsoft.TestPlatform.Client/DesignMode/DesignModeClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
using Microsoft.VisualStudio.TestPlatform.CoreUtilities.Helpers;
using Microsoft.VisualStudio.TestPlatform.ObjectModel;
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client;
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client.Interfaces;
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client.Payloads;
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging;
using Microsoft.VisualStudio.TestPlatform.PlatformAbstractions;
Expand All @@ -30,7 +31,9 @@
namespace Microsoft.VisualStudio.TestPlatform.Client.DesignMode;

/// <summary>
/// The design mode client.
/// The design mode client, which listens inside of vstest.console when we are running in server mode (e.g. under an IDE like VS), and proceses
/// the incoming requests. See <see cref="ProcessRequests"/> for how the requests are received, and for example <see cref="StartTestRun"/>
/// for how a single request is handled, and a result is sent back to the IDE or other consumer.
/// </summary>
public class DesignModeClient : IDesignModeClient
{
Expand Down Expand Up @@ -327,7 +330,7 @@ public int LaunchCustomHost(TestProcessStartInfo testProcessStartInfo, Cancellat
}

/// <inheritdoc/>
public bool AttachDebuggerToProcess(int pid, CancellationToken cancellationToken)
public bool AttachDebuggerToProcess(AttachDebuggerInfo attachDebuggerInfo, CancellationToken cancellationToken)
{
// If an attach request is issued but there is no support for attaching on the other
// side of the communication channel, we simply return and let the caller know the
Expand All @@ -347,7 +350,24 @@ public bool AttachDebuggerToProcess(int pid, CancellationToken cancellationToken
waitHandle.Set();
};

_communicationManager.SendMessage(MessageType.EditorAttachDebugger, pid, _protocolConfig.Version);
// TODO: formalize this so we can the deprecation version from the message data, and automatically switch
// to the new message, including type safety, where we determine T from the payload. And maybe give SendMessage
// a type of T as well to prevent some more mistakes.
if (_protocolConfig.Version < 7)
{
#pragma warning disable CS0618 // Type or member is obsolete
_communicationManager.SendMessage(MessageType.EditorAttachDebugger, attachDebuggerInfo.ProcessId, _protocolConfig.Version);
#pragma warning restore CS0618 // Type or member is obsolete
}
else
{
var payload = new EditorAttachDebuggerPayload
{
TargetFramework = attachDebuggerInfo.TargetFramework.ToString(),
ProcessID = attachDebuggerInfo.ProcessId,
};
_communicationManager.SendMessage(MessageType.EditorAttachDebugger2, payload);
}

WaitHandle.WaitAny(new WaitHandle[] { waitHandle, cancellationToken.WaitHandle });

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System;
using System.Threading;

using Microsoft.VisualStudio.TestPlatform.ObjectModel;
Expand All @@ -13,7 +14,7 @@ namespace Microsoft.VisualStudio.TestPlatform.Client.DesignMode;
/// <summary>
/// DesignMode TestHost Launcher for hosting of test process
/// </summary>
internal class DesignModeTestHostLauncher : ITestHostLauncher2
internal class DesignModeTestHostLauncher : ITestHostLauncher3
{
private readonly IDesignModeClient _designModeClient;

Expand All @@ -30,15 +31,22 @@ public DesignModeTestHostLauncher(IDesignModeClient designModeClient)
public virtual bool IsDebug => false;

/// <inheritdoc/>
[Obsolete("Don't use, internal implementations should use only the latest interface.", true)]
public bool AttachDebuggerToProcess(int pid)
{
return _designModeClient.AttachDebuggerToProcess(pid, CancellationToken.None);
throw new NotSupportedException();
}

/// <inheritdoc/>
[Obsolete("Don't use, internal implementations should use only the latest interface.", true)]
public bool AttachDebuggerToProcess(int pid, CancellationToken cancellationToken)
{
return _designModeClient.AttachDebuggerToProcess(pid, cancellationToken);
throw new NotSupportedException();
}

public bool AttachDebuggerToProcess(AttachDebuggerInfo attachDebuggerInfo, CancellationToken cancellationToken)
{
return _designModeClient.AttachDebuggerToProcess(attachDebuggerInfo, cancellationToken);
}

/// <inheritdoc/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ namespace Microsoft.VisualStudio.TestPlatform.Client.DesignMode;
/// </summary>
public static class DesignModeTestHostLauncherFactory
{
private static ITestHostLauncher s_defaultLauncher;
private static ITestHostLauncher s_debugLauncher;
private static ITestHostLauncher3 s_defaultLauncher;
private static ITestHostLauncher3 s_debugLauncher;

public static ITestHostLauncher GetCustomHostLauncherForTestRun(IDesignModeClient designModeClient, bool debuggingEnabled)
public static ITestHostLauncher3 GetCustomHostLauncherForTestRun(IDesignModeClient designModeClient, bool debuggingEnabled)
{
ITestHostLauncher testHostLauncher = !debuggingEnabled
ITestHostLauncher3 testHostLauncher = !debuggingEnabled
? (s_defaultLauncher ??= new DesignModeTestHostLauncher(designModeClient))
: (s_debugLauncher ??= new DesignModeDebugTestHostLauncher(designModeClient));
return testHostLauncher;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

using Microsoft.VisualStudio.TestPlatform.Client.RequestHelper;
using Microsoft.VisualStudio.TestPlatform.ObjectModel;
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client.Interfaces;
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging;

#nullable disable
Expand Down Expand Up @@ -34,10 +35,10 @@ public interface IDesignModeClient : IDisposable
/// <summary>
/// Attach debugger to an already running process.
/// </summary>
/// <param name="pid">Process ID of the process to which the debugger should be attached.</param>
/// <param name="attachDebuggerInfo">Process Id and other information about the process that IDE should attach to.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns><see cref="true"/> if the debugger was successfully attached to the requested process, <see cref="false"/> otherwise.</returns>
bool AttachDebuggerToProcess(int pid, CancellationToken cancellationToken);
bool AttachDebuggerToProcess(AttachDebuggerInfo attachDebuggerInfo, CancellationToken cancellationToken);

/// <summary>
/// Handles parent process exit
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,9 @@ public void Abort()

if (DiscoveryInProgress)
{
// TODO: COMPAT: This should not check the default protocol config, that is vstest.console maximum protocol version, not the
// version we negotiated with testhost. Instead this should be handled by the proxy discovery manager, based on the protocol
// version it has.
// If testhost has old version, we should use old cancel logic
// to be consistent and not create regression issues
if (Constants.DefaultProtocolConfig.Version < Constants.MinimumProtocolVersionWithCancelDiscoveryEventHandlerSupport)
Expand Down
12 changes: 8 additions & 4 deletions src/Microsoft.TestPlatform.Client/Execution/TestRunRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

namespace Microsoft.VisualStudio.TestPlatform.Client.Execution;

public class TestRunRequest : ITestRunRequest, ITestRunEventsHandler2
public class TestRunRequest : ITestRunRequest, IInternalTestRunEventsHandler
{
/// <summary>
/// Specifies whether the run is disposed or not
Expand Down Expand Up @@ -662,10 +662,14 @@ public int LaunchProcessWithDebuggerAttached(TestProcessStartInfo testProcessSta
}

/// <inheritdoc />
public bool AttachDebuggerToProcess(int pid)
public bool AttachDebuggerToProcess(AttachDebuggerInfo attachDebuggerInfo)
{
return TestRunCriteria.TestHostLauncher is ITestHostLauncher2 launcher
&& launcher.AttachDebuggerToProcess(pid);
return TestRunCriteria.TestHostLauncher switch
{
ITestHostLauncher3 launcher3 => launcher3.AttachDebuggerToProcess(attachDebuggerInfo, CancellationToken.None),
ITestHostLauncher2 launcher2 => launcher2.AttachDebuggerToProcess(attachDebuggerInfo.ProcessId),
_ => false
};
}

/// <summary>
Expand Down
Loading

0 comments on commit 27ea06b

Please sign in to comment.