Skip to content

Commit

Permalink
Add instructions to debug CLI builds using VS (#108455)
Browse files Browse the repository at this point in the history
Adds instructions to use VS as a tool to debug CLI builds

Previously the coreclr debugging docs only mentioned workflows for Visual Studio
which involve using VS for both building and debugging. This adds an additional
method to build using CLI scripts and use VS to only debug.

Thank you @AaronRobinsonMSFT for showing me this method.
  • Loading branch information
max-charlamb authored Oct 2, 2024
1 parent 0d86380 commit c2ba746
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions docs/workflow/debugging/coreclr/debugging-runtime.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* [Debugging CoreCLR on Windows](#debugging-coreclr-on-windows)
* [Using Visual Studio](#using-visual-studio)
* [Using Visual Studio Open Folder with CMake](#using-visual-studio-open-folder-with-cmake)
* [Using Visual Studio to debug CLI builds](#using-visual-studio-to-debug-cli-builds)
* [Using Visual Studio Code](#using-visual-studio-code)
* [Using SOS with Windbg or Cdb on Windows](#using-sos-with-windbg-or-cdb-on-windows)
* [Debugging CoreCLR on Linux and macOS](#debugging-coreclr-on-linux-and-macos)
Expand Down Expand Up @@ -103,6 +104,18 @@ Steps 1-9 only need to be done once as long as there's been no changes to the CM

Whenever you make changes to the CoreCLR source code, don't forget to invoke the _Install_ command again to have them set in place.

#### Using Visual Studio to debug CLI builds
Visual Studio can also be used to debug builds built externally from CLI scripts.

1. Build at least the `clr` and `libs` subsets as described in the [build instructions](https://github.com/dotnet/runtime/blob/main/docs/workflow/README.md#building-the-repo). Example command: `.\build.cmd -subset clr+libs -configuration Release -runtimeConfiguration Debug`
2. Build the Core_Root as described in the [testing instructions](https://github.com/dotnet/runtime/blob/main/docs/workflow/testing/coreclr/testing.md#building-the-core_root). This generates `corerun.exe` which serves as the entry point to run managed code. It is placed inside the core root folder along with all required dlls. Example command: `.\src\tests\build.cmd generatelayoutonly`
3. Launch a Visual Studio instance and select the option to open an existing project/solution. Select `artifacts\tests\coreclr\<OS>.<arch>.<configuration>\Tests\Core_Root\corerun.exe` as the project. Alternatively, launch Visual Studio using `devenv /debugexe artifacts\tests\coreclr\<OS>.<arch>.<configuration>\Tests\Core_Root\corerun.exe`
4. In the Solution Explorer, right click `corerun` and select properties. Set `Debugger Type` to `Native Only`. Set the `Arguments` field to a path of a managed application to debug.
5. To set breakpoints, runtime source files can to be added by right clicking the solution in the Solution Explorer and selecting Add -> Existing Item.
6. Set breakpoints and run the application with `F5` to start debugging.

Note, the `.sln` file can be saved and stores paths to `corerun.exe`, included files, and debug settings. It can be reused as long as the paths do not change.

### Using Visual Studio Code

It will be very nice to be able to achieve all this using Visual Studio Code as well, since it's the editor of choice for lots of developers.
Expand Down

0 comments on commit c2ba746

Please sign in to comment.