Skip to content

Commit d2f0fd2

Browse files
Improve in-proc debugging (#731)
Improve in-proc debugging
1 parent 7f292f9 commit d2f0fd2

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

Documentation/Troubleshooting.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,8 +239,9 @@ Process Id: 29228 Name: dotnet
239239

240240
## Enable collector instrumentation debugging
241241

242-
You can live attach and debug collectors with `COVERLET_DATACOLLECTOR_OUTOFPROC_DEBUG` env variable
242+
You can live attach and debug collectors with `COVERLET_DATACOLLECTOR_OUTOFPROC_DEBUG` and `COVERLET_DATACOLLECTOR_INPROC_DEBUG` env variable
243243
```
244244
set COVERLET_DATACOLLECTOR_OUTOFPROC_DEBUG=1
245+
set COVERLET_DATACOLLECTOR_INPROC_DEBUG=1
245246
```
246247
You will be asket to attach a debugger through UI popup.

src/coverlet.collector/InProcDataCollection/CoverletInProcDataCollector.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Diagnostics;
23
using System.Reflection;
34

45
using coverlet.collector.Resources;
@@ -14,8 +15,20 @@ public class CoverletInProcDataCollector : InProcDataCollection
1415
{
1516
private TestPlatformEqtTrace _eqtTrace;
1617

18+
private void AttachDebugger()
19+
{
20+
if (int.TryParse(Environment.GetEnvironmentVariable("COVERLET_DATACOLLECTOR_INPROC_DEBUG"), out int result) && result == 1)
21+
{
22+
Debugger.Launch();
23+
Debugger.Break();
24+
}
25+
}
26+
1727
public void Initialize(IDataCollectionSink dataCollectionSink)
1828
{
29+
30+
AttachDebugger();
31+
1932
_eqtTrace = new TestPlatformEqtTrace();
2033
_eqtTrace.Verbose("Initialize CoverletInProcDataCollector");
2134
}

0 commit comments

Comments
 (0)