You can Debug .NET Core via Visual Studio or WinDBG.
For Visual Studio debugging, follow the instructions at [Debugging tests in Visual Studio](https://github.com/dotnet/corefx/blob/master/Documentation/building/windows-instructions.md) to run and debug tests.
For bugs that cannot be reproduced within Visual Studio (certain low-probability race conditions, SafeHandle life-time problems, etc) you will need to use WinDBG.
## Required Software
WinDBG free download:
* [WDK and WinDBG downloads](https://msdn.microsoft.com/en-us/windows/hardware/hh852365.aspx)
Note: You can select the Standalone Debugging Tools for Windows or download only WinDBG via the WDK.
## Prerequisites to Debugging with WinDBG
1. Build the entire repository. This ensures that all packages are downloaded and that you have up-to-date symbols.
2. Install WinDBG as post-mortem debugger
As Administrator:
```
windbg -I
```
You may need to do this for both x64 and x86 versions.
Any application that crashes should now automatically start a WinDBG session.
## Debugging tests
To run a single test from command line:
* Locate the test binary folder based on the CSPROJ name.
For example: `src\System.Net.Sockets\tests\Functional\System.Net.Sockets.Tests.csproj` will build and output binaries at `bin\tests\Windows_NT.AnyCPU.Debug\System.Net.Sockets.Tests\netcoreapp1.0`.
* Execute the test
Assuming that your repo is at `C:\corefx`:
```
cd C:\corefx\bin\tests\Windows_NT.AnyCPU.Debug\System.Net.Sockets.Tests\netcoreapp1.0
5. Add Additional Providers (see below - Important: keep the "*" wildcard before the names.)
![PerfView example](perfview_example.gif)
### Built-in EventSource tracing
The following EventSources are built-in to CoreFX. The ones that are not marked as [__TestCode__] can be enabled in production scenarios for log collection.
#### Global
*`*System.Diagnostics.Eventing.FrameworkEventSource {8E9F5090-2D75-4d03-8A81-E5AFBF85DAF1}`: Global EventSource used by multiple namespaces.
#### System.Collections
*`*System.Collections.Concurrent.ConcurrentCollectionsEventSource {35167F8E-49B2-4b96-AB86-435B59336B5E}`: Provides an event source for tracing Coordination Data Structure collection information.
#### System.Linq
*`*System.Linq.Parallel.PlinqEventSource {159eeeec-4a14-4418-a8fe-faabcd987887}`: Provides an event source for tracing PLINQ information.
Helper scripts are available at https://github.com/dotnet/corefx/tree/master/src/Common/tests/Scripts/Tools. Run `net_startlog.cmd` as Administrator, run the application, then run `net_stoplog.cmd`. Open the `.etl` file with PerfView.
*`*System.Threading.SynchronizationEventSource {EC631D38-466B-4290-9306-834971BA0217}`: Provides an event source for tracing Coordination Data Structure synchronization information.
*`*System.Threading.Tasks.TplEventSource {2e5dba47-a3d2-4d16-8ee0-6671ffdcd7b5}`: Provides an event source for tracing TPL information.
*`*System.Threading.Tasks.Parallel.EventSource`: Provides an event source for tracing TPL information.
*`*System.Threading.Tasks.Dataflow.DataflowEventSource {16F53577-E41D-43D4-B47E-C17025BF4025}`: Provides an event source for tracing Dataflow information.
## Notes
* You can find the test invocation command-line by looking at the logs generated after the `msbuild /t:rebuild,test` within the test folder.