API for controlling PhpStorm, such as adding breakpoints Follow
Is there an API by which an external process could instruct PhpStorm to add a breakpoint to a line of a file? Such as:
$ phpstorm --action SetBreakpoint --targetFile /var/www/foo/bar.php --targetLine 351
Any format will do, I can wrap my Bash into anything PhpStorm will accept. My current goal is to add breakpoints to the 500 places in my project that I've identified as being the potential source of an issue. But I don't know which of the 500 is the one that is actually invoked!
If there is no API for this, would I be able to add breakpoints to specific lines with a PhpStorm extension? As in, if I invest in learning how to write PhpStorm extensions, is adding breakpoints to specific lines in specific files something that a PhpStorm extension could do?
Please sign in to leave a comment.
Can you add a bit more details? Maybe existing functionality can help here.
For example: you can log a specific message when breakpoint get hit: Logging options -- https://www.jetbrains.com/help/phpstorm/using-breakpoints.html#breakpoint-properties
Command line interface does not have such functionality: https://www.jetbrains.com/help/phpstorm/working-with-the-ide-features-from-command-line.html
The IDE has (had) some API .. but AFAIK it's limited to files/projects only (e.g. https://www.develar.org/idea-rest-api/#api-Platform-file) -- I'm not sure at all how up-to-date/accurate that is.
Anyway: if you close the project and open ".idea/workspace.xml" file, it keeps breakpoints under <component name="XDebuggerManager"> node. You can generate and replace that node with new content while project is closed in the IDE. For example (test project)
Thank you. I should have thought to check in workspace.xml, I even have a Python script to quickly create Scopes and colour them via workspace.xml.
As you asked, my particular situation is a highly customized Magento application that is at some point going down an unexpected code path under a specific condition that I can replicate. At some point normal code execution is being aborted and a redirect to the homepage is sent instead. I believe that it is not caused by a caught exception, but I'm not 100% sure. I didn't write this application, I just recently joined the project.
I've traced the code with xDebug profiling under both conditions, but there are no tools to compare xDebug profiles. So I've written a bash script to eliminate all timing information and other small irrelevancies such that I can then diff the two profiles. So now I have this diff, and I can see what function is run in one code path but not the other, but it would take me ages to code something that would let me extract a stack out of that! So I went to put a breakpoint on the method... and there are nearly 500 method declarations for that method name. I don't even want to speculate how that came about...
Again, thank you for pointing me in the right direction.
Wow... No ideas what exactly is going on here... but wow.
Anyway: please be careful with putting too many breakpoints. IIRC the IDE can have weird slowdowns or even freezes if there are a lot of breakpoints (and/or watches). Xdebug as well may have issues with that many of them. Sadly I cannot find exact tickets right now where it would clearly state those issues (only this one, which is 10 months old now: WI-49739). But I suggest you start with something like 20-30 breakpoints first and see how it goes; then increase to 50 or so if it all good.
Good luck in resolving your issue.
Thank you, I will be careful. I have no problem doing a few dozen at a time.
No API for this, sadly. The only option here is the mentioned above workaround with workspace.xml.
Else vote for https://youtrack.jetbrains.com/issue/IDEA-15540.