Skip to content

Auto-attach to service hub process on debug#53601

Merged
jmarolf merged 2 commits intodotnet:mainfrom
jmarolf:debug-service-process
Jun 1, 2021
Merged

Auto-attach to service hub process on debug#53601
jmarolf merged 2 commits intodotnet:mainfrom
jmarolf:debug-service-process

Conversation

@jmarolf
Copy link
Contributor

@jmarolf jmarolf commented May 21, 2021

Set the environment variable SERVICEHUBDEBUGHOSTONSTARTUP to All. This will pop up a debug dialog whenever a ServiceHub Host process starts running. You will then be able to attach a debugger to that process. In more complex scenarios, this same environment variable can be set with the name of the specific ServiceHub Host process you would like debug dialogs to be shown for. ex. ServiceHub.Host.CLR.exe.

I think we just want to set this value in environment we launch VS in.

@ghost ghost added the Area-Infrastructure label May 21, 2021
@sharwell sharwell changed the title Auto-attache to service hub process on debug Auto-attach to service hub process on debug May 21, 2021
Copy link
Contributor

@sharwell sharwell left a comment

Choose a reason for hiding this comment

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

In the current form, this will impact Ctrl+F5 scenarios (start without debugging). There are two changes needed:

  1. This should only impact F5 scenarios (start debugging)
  2. This should automatically attach the managed debugger from the current process, as opposed to calling Debugger.Launch and forcing the user to complete the process

An example of (2) can be seen in our integration tests.

if (System.Diagnostics.Debugger.IsAttached)
{
// If a Visual Studio debugger is attached to the test process, attach it to the instance running
// integration tests as well.
var debuggerHostDte = GetDebuggerHostDte();
var targetProcessId = Process.GetCurrentProcess().Id;
var localProcess = debuggerHostDte?.Debugger.LocalProcesses.OfType<EnvDTE80.Process2>().FirstOrDefault(p => p.ProcessID == hostProcess.Id);
if (localProcess != null)
{
localProcess.Attach2("Managed");
}
}

@jmarolf
Copy link
Contributor Author

jmarolf commented May 21, 2021

@sharwell I was also thinking of moving this to a separate profile such as Visual Studio Extension (with ServiceHub)

@jmarolf
Copy link
Contributor Author

jmarolf commented May 21, 2021

This should automatically attach the managed debugger from the current process, as opposed to calling Debugger.Launch and forcing the user to complete the process

This is not possible with service hub today. If we fully owned the process we could do this

@sharwell
Copy link
Contributor

I was also thinking of moving this to a separate profile such as Visual Studio Extension (with ServiceHub)

Sure, this would be totally fine. VS with ServiceHub debugging might be more clear.

@jmarolf jmarolf merged commit 1bf0e0d into dotnet:main Jun 1, 2021
@jmarolf jmarolf deleted the debug-service-process branch June 1, 2021 19:16
@ghost ghost added this to the Next milestone Jun 1, 2021
@RikkiGibson RikkiGibson modified the milestones: Next, 17.0.P2 Jun 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants