Chapter 11. Debugging techniques

 

Debugging can be one of the most frustrating parts of toolmaking, and we feel it’s often because folks don’t have a consistent, methodical approach to debugging. That’s what we’re going to offer you in this chapter. We’ll even make a promise: If you follow our recommendations, you’ll find debugging to be infinitely less frustrating. We’ll even walk you through some real-life debugging examples to help drive home the point.

11.1. Two types of bugs

We feel that the entire universe of software bugs, at least the PowerShell universe, essentially comes down to one of two types: typos and logic errors.

Typos are straightforward enough: They’re what happen when you type something wrong. Maybe it’s a command name. Maybe you mistype a variable name. Maybe you forgot a closing quotation mark or curly bracket. Whatever the cause, typos are relatively easy to prevent (we’ll offer some tips shortly) and to solve, at least compared to their more sinister cousin, logic errors.

11.2. Solving typos

11.3. The real trick to debugging: expectations

11.4. Dealing with logic errors: trace code

11.5. Dealing with logic errors: breakpoints

11.6. Seriously, have expectations

11.7. Coming up next

11.8. Lab