Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Effective and Faster Debugging With Conditional Breakpoints

DZone's Guide to

Effective and Faster Debugging With Conditional Breakpoints

Check out these awesome ways to use breakpoints in Eclipse and Chrome to debug your Java and Javascript apps.

· DevOps Zone ·
Free Resource

Is the concept of adopting a continuous everything model a daunting task for your fast moving business? Read this whitepaper to break down and understand one of the key pillars of this model in Continuous Governance: The Guardrails for Continuous Everything.

In order to find and resolve defects that prevent correct operation of our code, we mostly use debugging process. Through this process, in a sense, we "tease out" the code and observe the values of variables in runtime. Sometimes, this life-saving process can be time consuming.

Today, most IDEs and even browsers make debugging possible. With the effective use of these tools we can make the debugging process faster and easier.

Below, I want to share some methods that help us make the debugging process fast and effective. You will see Eclipse IDE and Chrome browser samples, but you can implement these methods to other IDEs and browsers, too.

In order to debug our Java code in Eclipse, we put a breakpoint to the line which we want to observe:

Image title

When we run our code in debug mode, the execution of code suspends in every iteration of line which we put breakpoint on. We can also observe the instant values of variables, when the exceution suspends.

Image title

When we know the reason of a defect, instead of observing the instant values of variables in every iteration, we can just specify the condition in the properties of breakpoint. This makes the execution suspended only when the condition  is met. By this way, we can observe the condition we expected quickly:

Image title

Image title

Image title

With the help of this property, we can even run any code when the execution passes the breakpoint, without suspending the execution.

Image title

We can also, change the instant value of variables when the execution passes the breakpoint. So, we can prevent the case which makes a code throw exception.

Image title

With the help of this property, we can also throw any exception from the breakpoint. By this way, it is possible to observe the handling of a rare exception.

Image title

It is possible to debug this in Chrome, too. This time, we will debug our Javascript code. To do this, we can press F12 or open the "Sources" menu under Tools>Developer Tools menu and select the code which we want to debug and add breakpoint. After that, we can also specify a condition to suspend the execution only when the condition meets.

Image title


Are you looking for greater insight into your software development value stream? Check out this whitepaper: DevOps Performance: The Importance of Measuring Throughput and Stability to see how CloudBees DevOptics can give you the visibility to improve your continuous delivery process.

Topics:
effectiveness ,faster ,debugging ,debuggers ,eclipse ,chrome browser

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}