DEV Community

Cover image for Conditional Debugging - Faster debugging for complicated cases
Talha Aamir
Talha Aamir

Posted on

Conditional Debugging - Faster debugging for complicated cases

Introduction

My main goal with this small post is to just point out that if you're someone who doesn't use conditional breakpoints, when:

  • you're investigating a bug
  • know a case (some id or some value) you want to verify
  • are continually hitting the continue or step next button

NOTE For the TLDR of this post in a short gif, skip to conditional debugging

Well, you should (be using conditional breakpoints). Its a pretty simple feature which most (if not all) debug tools support. I have no idea how I skipped past this, probably because I never realized I could do this in the first place.

Caveat

At the time of writing, I have been using this for python debugging using pycharm, c++ debugging using visual studio and javascript debugging in chrome devtools, and it seems to be atrociously slow in devtools at my work atleast, even for an array with a few 100 entries, not a complicated process at all, but a bug I imagine. Either way, it's worth testing out yourself

Process

Setup

I'll take chrome dev tools as an example here, I have created a very simple project, with an html file that has a button with a function printEvenTillN. This as you might image prints all even numbers till N.
I have another js file, what this has is the function itself.
I have used the Live Server extension to launch a server so I can debug this in chrome devtools.

Conditional Debugging

The Case I am presenting is that for our simple function printEvenTillN I want to see if 32 is amongst the numbers it prints. I am choosing a specific number because it translates well to complicated debugging cases where we want to see if say a particular element with some known unique id exists.

Conditional Debugging Demo

Conclusion

I hope you get some value out of it. If you did not know about this already I encourage you to try it. Whilst console logs and looping through each debug instance is well, easy, and we are sometimes lazy, this makes the process so much easier.

Oldest comments (0)