S&box Wiki

Revision Difference

Debugging#536273

<cat>Code.Intro</cat> <title>Debugging</title> #Debugging using Visual Studio #Debugging using Visual Studio <note>This page explains the process of [debugging using Visual Studio](https://docs.microsoft.com/en-us/visualstudio/get-started/csharp/tutorial-debugger), for other IDEs use their corresponding debugging capabilities.</note> ##Starting in debug mode S&box supports debugging, it's as simple as opening up the [generated](https://wiki.facepunch.com/sbox/Making_Gamemode#generatingproject) `Addons.sln` and hitting **Debug** > **Start Debugging** ( <key>F5</key> ). This will launch a new instance of s&box and attach a debugger to it. ##Attaching a debugger You can also attach a debugger to an already running instance of the game by going to **Debug** > **Attach to Process** ( <key>Ctrl</key> + <key>Alt</key> + <key>P</key> ) and selecting `sbox.exe` in the list of processes. After this you can reattach the debugger to the same process using **Debug** > **Reattach to Process** ( <key>Shift</key> + <key>Alt</key> + <key>P</key> ). ##Using breakpoints ![Breakpoint](https://files.facepunch.com/wiki/files/a59bc/8d90cbdd54b5728.png) Breakpoints allow you to pause execution when it reaches specified points in your code (breakpoints). To add or remove a breakpoint click on the left from the line of code you want to pause or put the caret on this line and press <key>F9</key>. A red circle should appear and the line should turn red. When this line will be reached execution will pause allowing you to inspect variables values, continue execution step-by-step and more. After you are done press <key>F5</key> to continue execution. Breakpoints can be added and removed freely in runtime, unlike code changes they don't require recompiling. ##Disabling Edit and Continue You may notice that you get green underlines while debugging and editing code, this is due to **Edit and Continue** being enabled in the Visual Studio settings, normally this is a good thing but due to s&box hotloading it needs to be disabled. You can disable this by going to **Tools** > **Options** > (or **Debug** > **Options**) > **Debugging** > **General** then scrolling about half way down and unchecking **Edit and Continue**. You can disable this by going to **Tools** > **Options** > (or **Debug** > **Options**) > **Debugging** > **General** then scrolling about half way down and unchecking **Edit and Continue**.