If you’ve been following along with the series thus far, then you’re likely seeing just how useful proper debugging can be especially when working on WordPress.
That is to say that not only are you able to gain valuable insights into your own projects, but you can see how WordPress core works, too.
At this point, though, we haven’t done much. As you may recall from the previous post (or if you haven’t watched the screencast, now is a good time to do so), you can see just how much debugging offers.
The truth is, we’ve barely scratched the surface. As I mentioned last time, this post and this screencast are going to focus specifically on the following:
In the next post, we’re going to look at more advanced things we can do such as stepping into functions, stepping out of functions, and stepping over functions.
We’re still not at a point where we’re going to worry about changing variable values on-the-fly, but we’re definitely going to see how we can strategically use the debugger to step into certain functions, step over certain functions, and step out of certain functions.
Stepping Around Code
Before sharing the screencast, I want to define what it means to step around the code in a project. It sounds like something that we do whenever we’re navigating the codebase.
But that’s not true in the context of debugging.
Remember that for the purposes of this particular series, I’m using the latest version of WordPress from Subversion. You can review how to set this up by reading this post.
A Word About Steps
Before defining the upcoming terms, please note that the idea of a “step” when debugging is analogous to going line-by-line through the code base.
As we saw in the previous post, the program’s execution will halt as soon as a breakpoint is hit. From there, the result of how the program proceeds is left up to us. And with that as our backdrop, we’ll define a few terms.
- Stepping into a function is an action that, when you hit a function call, will take you into the function. Sometimes this is useful, like if you want to see what the function is doing or see how values are being set; other times, it’s unnecessary if you just care about the function executing or you only care about what it returns.
- Stepping over a function call will allow you to bypass a function’s execution in the sense that it still runs, we just don’t see how it actually works. Instead, control will go to the next line after the function has finished its execution.
- Stepping out of a function is used when you’ve stepped into a function, hit a point where you’re done evaluating the code, and then ready to step back out to whatever the codebase is going to do next. This is useful if you’re wanting to find where a bug may lie and suspect its in one part of the code (where it may or may not be).
And that’s it. If this is brand new, it may sound weird or it may be difficult to wrap your head around it. If that’s the case, it’s okay. That’s how it goes with anything new, right?
On the other hand, if you happen to know these terms or grok the definitions of them easily, then consider the previous points a refresher.
And Now a Screencast
In this screencast, I’m going to perform all of the above actions using one of my own plugins – Easier Excerpts. This isn’t mean to be any type of self-promotion, though. Instead, I know the codebase and I don’t have to worry about actually showcasing the work that is being done for someone else.
Now that you’ve seen the screencast and know it’s strictly my codebase, you can download the code and perform all of the same actions yourself to get a handle on how to perform the actions outlined in this post.
This will provide even more practice for your debugging skills and should make it easy to continue improving our debugging skills as we move forward in the next post.
This is a bit of a lengthy post and I tried to make sure all of the explanations were made before viewing the screencast. After all, it’s much easier to read paragraphs of text about content and then seeing it play out in a short video rather than having a 15-minute video, isn’t it?
As useful as this can be, there’s still more to it. And that’s what we’ll review in the next post. Specifically, we’re going to look at how to inspect variable values, review what an array contains, and then how we can modify variables on the fly.
It’s powerful stuff, but make sure you’ve reviewed the first bit of content, carefully reviewed this post, and do a bit of practice before moving forward.