break the Breakpoint đź”´ & debug efficiently
As a developer we spent a good amount of time for debugging our code(check my other story on debugger mode here) and typically uses breakpoint and logs. In this series I will show you how can you use some of the features of breakpoints in InteliJ based IDEs which will make your life easy and debugging faster so you can save your time for other work.
So let’s start with start by adding a breakpoint and it is as easy as a click, just do a click in gutter area where you want to put a breakpoint and congratulation you have added your first breakpoint.
Now if you run your app/code in debug mode it will stop here. Debugging this way is not efficient and you may hit this breakpoint every time your code reaches here but you want to execute it only if certain condition is true. Let’s add that condition, right click on a breakpoint and you will see a popup like below
you can add any condition here on which you want this breakpoint to be hit. Here you can right any code which returns boolean also you can write this condition in all the languages supported in your project(see dropdown with “Kotlin” in it) After you add this condition breakpoint icon will have a “?” with it.
sometimes you may just want to see the flow of your code and check some values of a variable on reaching to this line but do not want to halt here for this you can add a log and if your code reaches there it will execute your code and print that log also you can add some conditional logs. You need to uncheck `Suspend` checkbox for not stopping here. See below image with this and also notice logs in the bottom of it.
Dependent Breakpoint
Yes! you read it correct. You can make a breakpoint dependent on some other breakpoint and it will not hit until the other one is hit.
Loop Breakpoint
you are iterating an array and want to check your breakpoint after N iteration you can set that too. Your code will stop after it hits your breakpoint for N time.
Group Breakpoint
While you are debugging an issue but got another high priority issue you either need to remove or disable all breakpoints of existing issue and later you may miss to enable some of them for this all intellij IDEs support grouping of breakpoints and enable/disable them in a single click.
There are many more options here which you may find useful and reduce your time to debug an issue.
Bonus tip:- try to drag breakpoint to some other line.
for more detailed description about each option you can refer below page https://www.jetbrains.com/help/idea/2019.1/using-breakpoints.html