Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Instant breakpoint with debugger statement in PhpStorm/WebStorm

I'm investigating the possibilities to set up a breakpoint instantly when debugging JavaScript

for (...) {
  for (...) {
    ...
  }
  // need a breakpoint here
}

The problem here is that a breakpoint cannot be toggled on comment line, it needs a statement.

And when debugger statement is added to line, another problem appears - it doesn't switch to Debugger tab automatically. It just looks like the application is pending, with no indication.

And I'm trying to avoid adding dummy statements because they can be neglected (as for debugger, there is at least an inspection rule to highlight it).

Are there any tricks to achieve this? Can debugger statement be made to behave like usual breakpoint at least?

like image 810
Estus Flask Avatar asked Sep 12 '26 22:09

Estus Flask


1 Answers

Speaking to the general question, there is only one answer, and it is the one you do not want to hear:

You must have a statement for the breakpoint

There are no tricks that are widely applicable (although there may exist some IDE that allows for convenience breaking immediately after a loop... weird)

Unfortunately, what you want is typically done with a temporary/dummy statements (exactly the kind that you are trying to avoid):

for (...) {
  for (...) {
    ...
  }
  // TODO: editors like Eclipse flag TODO lines so they are not lost in the source forest
  setTimeout(Function.prototype, 10000);
}

This is due to the mechanics of how (most) debuggers work: basic file and line numbers are stored as debugger information (hints) in the compiled code, and then matched up with the available source during debug execution. For non-compiled languages like JS/PHP, similar techniques are employed with the string that is parsed from source, but lines with comments or brackets are not really executable.

This issue has occasionally reared its ugly head during my own developer journey. It is simply part of the nature of debugging. I hope you can find a coding solution that provides you comfort and some peace of mind.

like image 171
JonathanDavidArndt Avatar answered Sep 14 '26 13:09

JonathanDavidArndt



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!