We are diving into the world of debugging in Visual Studio Code (VS Code). We begin by discussing the importance of debugging and how it is not just about troubleshooting existing programs, but also about investigating and ensuring code works as intended during the development process. We then introduce the debugging tools in VS Code and explain that debuggers can be CLI-based or integrated into the IDE.
To demonstrate the debugging process, we use an example of a zero-player adventure game with some misbehaving code. We take a quick look at the code, discussing its three parts and explaining how it handles the available characters, checks if players are allowed to play, and prints out the active players.
Next, we dive into the practical part and demonstrate how to use the F5 key or the debugging symbol in the sidebar to launch the current file and start debugging. We explain the different options in the tools palette, such as stepping over, stepping into, stepping out, continuing the program, restarting, and stopping. We also highlight the debugging view in VS Code, which includes the breakpoint section, variable section, and watch window. We explain how to use the watch window to evaluate expressions and gather more information.
As we step through the code, we encounter various issues and bugs. We discuss how to fix these bugs, refactoring the code and paying attention to variables' states. We also highlight the importance of resetting the PowerShell session when debugging multiple scripts and mention an experimental feature in VS Code that allows for the creation of a new PowerShell session when starting the debugger. We emphasize the need to restart the PowerShell session in the integrated terminal and the importance of considering variables and session states from previous debugging sessions.
In the final part of the episode, we focus on the different views available in VS Code for debugging purposes. We discuss the variable view, watch window, call stack view, and breakpoint view, explaining their functionalities and how they can aid in the debugging process. We also discuss different ways to launch the debugger depending on specific needs, such as running a current script, attaching to a running process on a remote machine, or using the interactive session. We mention keyboard shortcuts for navigation and introduce a game called Maze Loot to further illustrate the debugging process.
In total, we cover topics such as debugging tools in VS Code, practical demonstrations, bug fixing, resetting PowerShell sessions, views for debugging, launching the debugger, and debugging multi-run level code. We also address common questions from the audience about debugging scripts on machines without VS Code and setting conditional breakpoints.
Chapters:
00:00:00 may the debugger be with you - Manfred Wallner - PSConfEU 2023
00:00:07 Introduction to partial debugging in VS Code
00:03:41 Different types of debugging tools and approaches explained
00:08:15 Setting breakpoints and stepping through the code for inspection
00:10:25 Utilizing the debugging view and variable inspection in VS Code
00:13:12 Stepping into the For Each Object Block and Debugging
00:21:13 Debugging in VS Code: Partial Session State
00:23:26 Launching the Debugger: Default Configuration and Interactive Session
00:25:24 Introduction to Maze Loot game module
00:26:17 Importing the Maze Loot module
00:26:47 Introduction to Maze Loot Game and available items
00:35:17 Exploring the Game Engine and Player Run Spaces
00:38:09 Changing Execution Order when Debugging Multi-Run Level Code
00:40:23 Attaching to the first run space for debugging.
00:41:32 Exploring Runspaces and Player's Threads
00:43:35 Using Call Stack View for Execution Threads
00:46:05 Debugging PowerShell scripts in PowerShell ISE
00:47:20 Conditional Breakpoints: Stopping Inside a Program on a Condition
Ещё видео!